summaryrefslogtreecommitdiff
path: root/play
blob: 7f950203bc7a5f88af83223abab6884095e2ac8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

# bash script to play files from a slow network ressource using mpv
# caches the file in /tmp and moves to $ARCHIV
# -y to skip verification
# export global variable $ARCHIV
# set the exit code right for quitting
# echo "q quit 255" >> ~/.mpv/input.conf

if [ $1 = "-y" ] || [ $1 = "y" ] || [ $1 = "Y" ] || [ $1 = "-Y" ]; then
	verify="yes"
	shift
else
	verify=0
fi

file="$@"

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."
fi

if [ -d /tmp ] && [ -w /tmp ]; then
	tmp="/tmp"
	cp "$file" /tmp &
else
	read -p "Please name the directory (without the trailing slash!) to cache the file: " tmp
	if [ -d $tmp ] && [ -w $tmp ]; then
		cp "$file" "$tmp" &
	else
		echo "Directory doesn't exist or you don't have write permission."
		exit 1
	fi
fi

echo -n "Preparing the awesome! Starting playback in.."
echo -n " 3"
sleep 1
echo -n " 2"
sleep 1
echo -n " 1"
sleep 1
echo " Start!"

mpv $tmp/"$file"
if [ $? -eq 0 ]; then
	if [ -d $ARCHIV ] && [ -w $ARCHIV ]; then
		echo "Finished $file succesfull."
		if [ $verify -eq 0 ]; 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 $tmp/"$file" "$ARCHIV"
			if [ $? -eq 0 ]; then
				rm -v "$file"
			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 $tmp/"$file" "$path"
				if [ $? -eq 0 ]; then
                                       	rm -v "$file"
                               	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 $tmp/"$file"
		else
			echo "Okay, don't touching the files."		
		fi
	else
		echo "Can't move to \"$ARCHIV\". Directory doesn't exist or you don't have write permission."
		exit 1
	fi
else
	echo "Something is broken with the media player!"
	exit 1
fi

echo "Have a nice day!"