-
Notifications
You must be signed in to change notification settings - Fork 0
/
ytube_playlist.sh
81 lines (80 loc) · 1.7 KB
/
ytube_playlist.sh
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
# /bin/bash
FILENAME=""
lineCount=0
current=0
analyze=1;
reset=0;
#check if the playlist file exists
if [ "$1" != "" ] && [ -f "$1" ] && [ -s "$1" ]; then
FILENAME=$1
#first we must analyze the playlist
while read -r -a line
do
lineCount=$[lineCount + 1]
case "$line" in \#\#*) continue ;; esac
case "$line" in \#*) continue ;; esac
if [ $analyze == 1 ]; then
case "$line" in *) current=$lineCount; analyze=0 ;; esac
fi
done < "$FILENAME"
if [ $analyze == 1 ]; then
current=$lineCount
analyze=0
fi
#now handle the options
if [ "$2" == "next" ]; then
count=0
while read line
do
if [ $count == $[current - 1] ] && [ $count != $[lineCount - 1] ] ; then
echo \#$line
else
echo $line
fi
count=$[count + 1]
done < "$FILENAME" > /tmp/playlist.ypl.t
mv /tmp/playlist.ypl.t "$FILENAME"
if [ $[current - 1] -ge $[lineCount - 1 ] ]; then
echo END
fi
elif [ "$2" == "back" ]; then
count=0
while read line
do
if [ $count == $[current - 2] ] && [ $count != 0 ] ; then
echo ${line//#/}
else
echo $line
fi
count=$[count + 1]
done < "$FILENAME" > /tmp/playlist.ypl.t
mv /tmp/playlist.ypl.t "$FILENAME"
if [ $[current - 2] -le 1 ]; then
echo TOP
fi
elif [ "$2" == "reset" ]; then
reset=1
else
#echo current
count=0
while read -r -a line
do
if [ $count == $[current - 1] ]; then
echo $line
break;
fi
count=$[count + 1]
done < "$FILENAME"
fi
if [ $reset == 1 ]; then
while read line
do
case "$line" in \#\#*) echo $line; continue ;; esac
echo ${line//#/}
done < "$FILENAME" > /tmp/playlist.ypl.t
mv /tmp/playlist.ypl.t "$FILENAME"
#sed -i -e 's/#//g' $FILENAME
fi
else
echo $1: Playlist does not exist.
fi