summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoehm2014-03-24 21:17:52 +0100
committermoehm2014-03-24 21:17:52 +0100
commit1073777cdca41b69505a0098fb96ba266e274016 (patch)
tree13094b582696d0ea944bd79293a559732af74336
parent811dbad6573456b7249dd07e2833e6f3a0baa773 (diff)
downloaddotfiles-1073777cdca41b69505a0098fb96ba266e274016.tar.gz
No with 'no-cache' flag.
-rwxr-xr-xbin/play161
1 files changed, 88 insertions, 73 deletions
diff --git a/bin/play b/bin/play
index 29c2af5..83e6460 100755
--- a/bin/play
+++ b/bin/play
@@ -21,8 +21,13 @@ printhelp(){
exit 0
}
+cache=1
+
while true; do
case "$1" in
+ -no-cache|-nc) cache=0
+ shift
+ ;;
-y|-Y|-yes|-j|-ja) verify="yes"
shift
;;
@@ -65,102 +70,112 @@ if [ ! $player ]; then
exit 1
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"
- echo "Roger that!"
+if [ $cache -gt 0 ]; then
+
+ if [ ! $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"
+ echo "Roger that!"
+ fi
fi
-fi
-pwd=$(pwd)
+ pwd=$(pwd)
-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
- echo "Directory doesn't exist or you don't have write permission."
- exit 1
+ 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
+ echo "Directory doesn't exist or you don't have write permission."
+ exit 1
+ fi
fi
-fi
-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
- cd "$tmp"
- 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 "$@"
- if [ $? -eq 0 ]; then
- echo "Have a nice day!"
+
+ 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
+ cd "$tmp"
+ 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 "$@"
+ 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 "Something is broken with the media player!"
+ echo "This script is designed to cache media files from a FTP share or network drive. Exiting. "
exit 1
fi
else
- echo "This script is designed to cache media files from a FTP share or network drive. Exiting. "
- exit 1
+ cp "$@" "$tmp" &
+ cd "$tmp"
+ file=${@##*/}
+
+ echo -n "Preparing the awesome! Starting playback in.."
+ echo -n " 2,"
+ sleep 1
+ echo -n " 1"
+ sleep 1
+ echo " Start!"
fi
else
- cp "$@" "$tmp" &
+ echo -n "Preparing the awesome! Starting playback in.."
+ file="$@"
+ echo -n "Now!"
fi
-echo -n "Preparing the awesome! Starting playback in.."
-echo -n " 2,"
-sleep 1
-echo -n " 1"
-sleep 1
-echo " Start!"
-
-cd "$tmp"
-
-file=${@##*/}
-
$player "$file"
-if [ $? -eq 0 ]; then
- if [ -d $ARCHIV ] && [ -w $ARCHIV ]; then
- echo "Finished $file succesfull."
- 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 "$file" "$ARCHIV"
- if [ $? -eq 0 ]; then
- cd "$pwd"
- rm -v "$@"
+if [ $? -eq 0 ]; then
+ if [ $cache -gt 0 ]; then
+ if [ -d $ARCHIV ] && [ -w $ARCHIV ] && [ $ARCHIV ]; then
+ echo "Finished $file succesfull."
+ if [ ! $verify ]; then
+ read -p "Should we move everything to the archiv? ($ARCHIV) [Y/n/rm/other] " verify
fi
- elif [ $verify = "other" ] || [ $verify = "o" ] || [ $verify = "O" ] || [ $verify = "OTHER" ]; then
- read -p "Please tell us the absolute path: " path
- if [ -d $path ] && [ -w $path ]; then
- echo "Moving to $path."
- mv -v "$file" "$path"
+ if [ ! $verify ] || [ $verify = "ja" ] || [ $verify = "yes" ] || [ $verify = "j" ] || [ $verify = "y" ] || [ $verify = "Y" ]; then
+ echo "Moving the stuff to $ARCHIV."
+ mv -v "$file" "$ARCHIV"
if [ $? -eq 0 ]; then
cd "$pwd"
- rm -v "$@"
- fi
+ rm -v "$@"
+ fi
+ elif [ $verify = "other" ] || [ $verify = "o" ] || [ $verify = "O" ] || [ $verify = "OTHER" ]; then
+ read -p "Please tell us the absolute path: " path
+ if [ -d $path ] && [ -w $path ]; then
+ echo "Moving to $path."
+ mv -v "$file" "$path"
+ if [ $? -eq 0 ]; then
+ cd "$pwd"
+ rm -v "$@"
+ fi
+ else
+ echo "Sorry, \"$path\" doesn't exist."
+ exit 1
+ fi
+ elif [ $verify = "r" ] || [ $verify = "rm" ] || [ $verify = "remove" ] || [ $verify = "RM" ] || [ $verify = "R" ]; then
+ echo "Cleaning the mess up. Only removing files from $tmp."
+ rm -v "$file"
else
- echo "Sorry, \"$path\" doesn't exist."
- exit 1
+ echo "Okay, don't touching the files."
fi
- elif [ $verify = "r" ] || [ $verify = "rm" ] || [ $verify = "remove" ] || [ $verify = "RM" ] || [ $verify = "R" ]; then
- echo "Cleaning the mess up. Only removing files from $tmp."
- rm -v "$file"
else
- echo "Okay, don't touching the files."
+ echo "Can't move to \"$ARCHIV\". Directory doesn't exist or you don't have write permission."
+ exit 1
fi
else
- echo "Can't move to \"$ARCHIV\". Directory doesn't exist or you don't have write permission."
- exit 1
+ echo "Nothing was cached, nothing is touched."
fi
else
echo "Something is broken with the media player!"