diff options
| author | Horus3 | 2014-03-09 11:57:07 +0100 |
|---|---|---|
| committer | Horus3 | 2014-03-09 11:57:07 +0100 |
| commit | f34158ad920e17f4d506edcb6a6379e233e208f1 (patch) | |
| tree | 97ef958ab482f1dc2b78e6e03ce36d29572f5602 /bin | |
| parent | 9f4b3494700eeb2061dfd840e8d030f66088b173 (diff) | |
| download | dotfiles-f34158ad920e17f4d506edcb6a6379e233e208f1.tar.gz | |
improvements
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/play | 70 |
1 files changed, 49 insertions, 21 deletions
@@ -8,12 +8,27 @@ # echo "q quit 255" >> ~/.mpv/input.conf -if [ "$1" = "-y" ] || [ "$1" = "y" ] || [ "$1" = "Y" ] || [ "$1" = "-Y" ]; then - verify="yes" - shift -else - verify=0 -fi +while true; do + case "$1" in + -y|-Y|-yes|-j|-ja) verify="yes" + shift + ;; + -r|-rm|-remove) verify="rm" + shift + ;; + -o|-other|-ot) verify="other" + shift + ;; + -n|-no|-nope|-nein) verify= + shift + ;; + -d|-download|-down) download="yes" + shift + ;; + *) break + ;; + esac +done player[0]=$(command -v mpv) #media player of choice player[1]=$(command -v mplayer) @@ -33,9 +48,9 @@ fi if [ ! -d $ARCHIV ]; then echo "Note: Variable \$ARCHIV couldn't be found. It will play the file fine, but you should consider to organize your collection." - read -p "You can export it temporarily. If you do, just type the path to the folder , if you don't, leave it empty. " path - if [ $path ] && [ -d $path ] && [ -w $path ]; then - export ARCHIV=$path + read -p "You can export it temporarily. If you do, just type the path to the folder, if you don't, leave it empty. " path + if [ "$path" ] && [ -d "$path" ] && [ -w "$path" ]; then + export ARCHIV="$path" echo "Roger that!" fi fi @@ -46,27 +61,38 @@ if [ -d /tmp ] && [ -w /tmp ]; then tmp="/tmp" else read -p "Please name the directory to cache the file: " tmp - if [ ! -d $tmp ] || [ ! -w $tmp ]; then + if [ ! -d "$tmp" ] || [ ! -w "$tmp" ]; then echo "Directory doesn't exist or you don't have write permission." exit 1 fi fi -if [[ "$@" =~ ^https?://.* ]]; then +if [[ "$@" =~ ^https?://.+\.[a-z]{2}[a-z]* ]]; then read -p "Detected hyperlink. Should we try to download (caching)? Type something random to play direct with the mpv. [y/N] " download - if [ $download = "ja" ] || [ $download = "yes" ] || [ $download = "j" ] || [ $download = "y" ] || [ $download = "Y" ]; then + if [[ $download = "ja" ]] || [[ $download = "yes" ]] || [[ $download = "j" ]] || [[ $download = "y" ]] || [[ $download = "Y" ]]; then cd "$tmp" - wget "$@" & - elif [ $player =~ .*/mpv$ ] && [ $download ] && ( [ ! $download = "n" ] || [ ! $download = "N" ] || [ ! $download = "no" ] || [ ! $download = "nein" ] || [ ! $download = "NO" ]); then + wget -q -O "file" "$@" & + echo "Starting download. Ready to play in 2 sec." + sleep 2 + mpv file + echo "TODO: Moving to archiv. Not implemented yet." + exit 0 + elif [[ $player =~ mpv$ ]] && [ $download ] && ( [ ! $download = "n" ] && [ ! $download = "N" ] && [ ! $download = "no" ] && [ ! $download = "nein" ] && [ ! $download = "NO" ]); then echo "Playing directly using mpv." mpv "$@" - exit 0 + if [ $? -eq 0 ]; then + echo "Have a nice day!" + exit 0 + else + echo "Something is broken with the media player!" + exit 1 + fi else echo "This script is designed to cache media files from a FTP share or network drive. Exiting. " exit 1 fi else - cp "$@" $tmp & + cp "$@" "$tmp" & fi echo -n "Preparing the awesome! Starting playback in.." @@ -76,19 +102,20 @@ echo -n " 1" sleep 1 echo " Start!" -cd $tmp +cd "$tmp" + $player "$@" if [ $? -eq 0 ]; then if [ -d $ARCHIV ] && [ -w $ARCHIV ]; then echo "Finished $@ succesfull." - if [ $verify -eq 0 ]; then - read -p "Should we move everything to the Archiv? ($ARCHIV) [Y/n/rm/other] " verify + if [ ! $verify ]; then + read -p "Should we move everything to the archiv? ($ARCHIV) [Y/n/rm/other] " verify fi if [ ! $verify ] || [ $verify = "ja" ] || [ $verify = "yes" ] || [ $verify = "j" ] || [ $verify = "y" ] || [ $verify = "Y" ]; then echo "Moving the stuff to $ARCHIV." mv -v "$@" "$ARCHIV" if [ $? -eq 0 ]; then - cd $pwd + cd "$pwd" rm -v "$@" fi elif [ $verify = "other" ] || [ $verify = "o" ] || [ $verify = "O" ] || [ $verify = "OTHER" ]; then @@ -97,7 +124,7 @@ if [ $? -eq 0 ]; then echo "Moving to $path." mv -v "$@" "$path" if [ $? -eq 0 ]; then - cd $pwd + cd "$pwd" rm -v "$@" fi else @@ -120,3 +147,4 @@ else fi echo "Have a nice day!" +exit 0 |
