-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_random
executable file
·90 lines (77 loc) · 2.39 KB
/
play_random
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
86
87
88
89
#!/bin/bash
while(true);
do
clear;
echo -e "\e[92mMENU\e[39m";
echo -e "\e[92m=====================================\e[39m\n";
echo -e "\e[96m r)\e[97m Play a random song";
echo -e "\e[96m a)\e[97m Play songs from a randomly generated playlist";
echo -e "\e[96m g)\e[97m Generate a random playlist";
echo -e "\e[96m l)\e[97m List available songs";
echo -e "\e[96m q)\e[97m Quit\n";
echo -e "\e[93mSelect an option\e[39m\n"
echo -e "\e[33mUseful player commands (for mplayer):\e[39m";
echo -e "\e[33m=====================================\e[39m";
echo -e "\e[36mQ : \e[39mSTOP (cancel playing)";
echo -e "\e[36mSPACEBAR : \e[39mPAUSE";
echo -e "\e[36mRIGHT ARROW : \e[39mFORWARD";
echo -e "\e[36mLEFT ARROW : \e[39mREWIND";
echo -e "\e[36mENTER : \e[39mNEXT SONG IN PLAYLIST";
read -N 1 -s -r input;
echo $input;
if [ "$input" = "r" ]; then
files=();
while IFS= read -r -d $'\0'; do
files+=("$REPLY")
done < <( find . -name "*.mp3" -print0 )
echo -e "${files[RANDOM % ${#files[@]}]}";
mplayer -msgcolor "${files[RANDOM % ${#files[@]}]}";
fi
if [ "$input" = "a" ]; then
rm -f playlist;
files=();
while IFS= read -r -d $'\0'; do
files+=("$REPLY")
echo -e "${files[RANDOM % ${#files[@]}]}" >> playlist;
done < <( find . -name "*.mp3" -print0 )
mplayer -msgcolor -shuffle -playlist playlist;
rm -f playlist
fi
if [ "$input" = "g" ]; then
rm -f playlist;
files=();
while IFS= read -r -d $'\0'; do
files+=("$REPLY")
echo -e "${files[RANDOM % ${#files[@]}]}" >> playlist;
done < <( find . -name "*.mp3" -print0 )
read -N 1 -s -r -p "Playlist created. Press any key to continue";
fi
if [ "$input" = "l" ]; then
dircol=$(tput bold ;tput setaf 4)
coloff=$(tput sgr0)
root="." # define path here, not in 'find` arg
root="${root:-.}" # default to '.'
root="${root%/}/" # add trailing '/'
#
find "$root" -name '*.mp3' -printf "%y %P\n" |
while read -r line ;do
case $line in
d ) printf "%s\n" "$dircol$root$coloff";;
d\ *) printf "%s\n" "$dircol$root${line:2}$coloff";;
f\ *) l="$root${line:2}"
d="${l%/*}/"
f="${l##*/}"
cd -P "$d"
printf "%s" "$dircol$d$coloff"
ls --color=always -R1 "$f"
cd - >/dev/null
;;
*) printf "ERROR - type not yet catered for\n";;
esac
done | more
read -N 1 -s -r -p "Press any key to continue";
fi
if [ "$input" = "q" ]; then
exit 1;
fi
done