#!/bin/bash
# cat /usr/local/bin/openpl
# sudo chmod +x /usr/local/bin/openpl
# related commands: ls -l /usr/local/bin/{playmovs,mixmovs,openpl,newpldir}
#
# License: The MIT License, http://www.opensource.org/licenses/mit-license.php, Copyright (c) 2009 jv
#
declare DEFAULT_PLAYLIST_DIR PLAYLISTDIR
# default DEFAULT_PLAYLIST_DIR
DEFAULT_PLAYLIST_DIR="$(/usr/local/bin/playmovs -default_playlist_dir 2>/dev/null)" || DEFAULT_PLAYLIST_DIR="${HOME}/Movies/mplayer"
# make sure there is no trailing slash
DEFAULT_PLAYLIST_DIR="${DEFAULT_PLAYLIST_DIR%/}"
if [[ "${1}" == '-h' ]] || [[ "${1}" == '-help' ]] || [[ "${1}" == '--help' ]]; then
echo
echo 'usage:'
echo 'openpl -d # open default playlist directory'
echo 'openpl -h'
echo 'openpl -s # show'
echo 'openpl -s regex # show & filter with egrep regex'
echo 'openpl [dirname] # open playlist files of [dirname]'
echo 'openpl -d [dirname] # open specified playlist directory'
echo
exit 0
fi
if [[ "${1}" == '-s' ]] || [[ "${1}" == '--show' ]]; then
#/usr/bin/find -x "${DEFAULT_PLAYLIST_DIR}" -mindepth 1 -maxdepth 1 -type d -print0 | /usr/bin/xargs -0 /usr/bin/basename
/usr/bin/find -x "${DEFAULT_PLAYLIST_DIR}" -mindepth 1 -maxdepth 1 -type d -print0 | /usr/bin/xargs -0 /usr/bin/basename | /usr/bin/egrep -i "${2:-.*}"
#/usr/bin/find -x "${DEFAULT_PLAYLIST_DIR}" -mindepth 1 -maxdepth 1 -type d -name "${2:-*}" -print0 | /usr/bin/xargs -0 -n1 /usr/bin/basename
#/usr/bin/find -x "${DEFAULT_PLAYLIST_DIR}" -mindepth 1 -maxdepth 1 -type d -name "*${2:-*}*" -print0 | /usr/bin/xargs -0 -n1 /usr/bin/basename
exit 0
fi
if [[ "${1}" == '-d' ]]; then
if [[ ! -d "${DEFAULT_PLAYLIST_DIR}/${2}" ]]; then
echo "No such directory: ${DEFAULT_PLAYLIST_DIR}/${2}"
exit 1
fi
/usr/bin/open -a Finder "${DEFAULT_PLAYLIST_DIR}/${2}"
exit 0
fi
PLAYLISTDIR="${DEFAULT_PLAYLIST_DIR}/${1}"
if [[ ! -d "${PLAYLISTDIR}" ]]; then
echo "No such directory: ${PLAYLISTDIR}"
exit 1
fi
if [[ -f "${PLAYLISTDIR}/playlisturls-file.txt" ]]; then
/usr/bin/open -e "${PLAYLISTDIR}/playlisturls-file.txt"
else
echo "No such file: ${PLAYLISTDIR}/playlisturls-file.txt"
fi
if [[ -f "${PLAYLISTDIR}/playlisturls-website.txt" ]]; then
/usr/bin/open -e "${PLAYLISTDIR}/playlisturls-website.txt"
else
echo "No such file: ${PLAYLISTDIR}/playlisturls-website.txt"
fi
exit 0
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/RfW_hsnhCrU/10469