Browse code

Wildcard support

Jade Levesque authored on 2017-01-08 06:10:36
Showing 3 changed files
... ...
@@ -75,10 +75,15 @@ get_input() {
75 75
     then
76 76
         exit
77 77
     fi
78
-
79
-    test $n -ge 0
80
-
81
-    if [ $? -gt 1 ] 
78
+    if [ "$n" == "*" ]
79
+    then
80
+        cat $temp_file | while IFS='' read -r CUR_LINE
81
+        do
82
+            echo "$CUR_LINE" | sed 's/.*href="\/watch?v=//' | sed 's/".*//' >> $output
83
+        done
84
+        cp $output /tmp/yt-queue
85
+#    test $n -ge 0
86
+    elif [ $? -gt 1 ] 
82 87
     then
83 88
         echo "Bad input, mate. Type in a valid number or 'exit'."
84 89
         get_input
... ...
@@ -4,8 +4,7 @@
4 4
 # Lisc: ISC
5 5
 # Main: jadedctrl
6 6
 # Desc: Search YT videos and display
7
-#       in easy-to-read and easy-to
8
-#       -parse results
7
+#       in easy-to-read and easy-to #       -parse results
9 8
 #####################
10 9
 
11 10
 # Usage: yt-search.sh "$search_string"
... ...
@@ -47,11 +46,15 @@ function get_input() {
47 46
     if [ "$n" == "exit" ]
48 47
     then
49 48
         exit
50
-    fi
51
-
52
-    test $n -ge 0 &> /dev/null
53
-
54
-    if [ $? -gt 1 ] 
49
+    elif [ "$n" == "*" ]
50
+    then
51
+        cat $temp_file | while IFS='' read -r CUR_LINE
52
+        do
53
+            echo "$CUR_LINE" | sed 's/.*<a href="\/watch?v=//' | sed 's/".*//' >> $output
54
+        done
55
+        cp $output /tmp/yt-queue
56
+    #test $n -ge 0 &> /dev/null
57
+    elif [ $? -gt 1 ] 
55 58
     then
56 59
         echo "Bad input, mate. Type in a valid number or 'exit'."
57 60
         get_input
... ...
@@ -5,7 +5,7 @@
5 5
 # Lisc: ISC
6 6
 # Main: jadedctrl
7 7
 # Desc: Full-shell YT client that avoids the YT API.
8
-  Vers=0.5
8
+  Vers=0.5.1
9 9
 #####################
10 10
 
11 11
 # Roadmap:
... ...
@@ -39,11 +39,11 @@ fi
39 39
 search() {
40 40
     output="$(mktemp -u /tmp/yt_XXXXXX)"
41 41
     yt-search -i "$1" "$output"
42
-    if grep "^PL" "$output" > /dev/null
42
+    if sed -n ${1}p "$output" | grep "^PL" > /dev/null
43 43
     then
44
-        playlist "$(cat "$output")"
44
+        playlist "$(sed -n ${1}p "$output")"
45 45
     else
46
-        selected_video="$(cat "$output")"
46
+        selected_video="$(sed -n ${1}p "$output")"
47 47
         yt-meta "$selected_video"
48 48
     fi
49 49
 }
... ...
@@ -65,7 +65,7 @@ channel() {
65 65
         yt-channel -iu "$1" "$output"
66 66
         ;;
67 67
     esac
68
-    selected_video="$(cat "$output")"
68
+    selected_video="$(sed -n 1p "$output")"
69 69
     yt-meta "$selected_video"
70 70
 }
71 71
 
... ...
@@ -89,6 +89,10 @@ search   | /        Perform a search.
89 89
 channel  | chan     Show newest videos of a channel.
90 90
 stream   | str      Stream the selected video.
91 91
 video | sel | url   Select video based on URL or ID.
92
+queue    | lq       List videos in the queue.
93
+squeue   | sq       Stream all videos in the queue.
94
+dqueue   | dq       Download all videos in the queue.
95
+
92 96
 Note about usage:
93 97
 Both 'video ID; download' and 'download ID' are valid.  You don't need to
94 98
 select a video to run commands on it, but if you use metadata, download, or
... ...
@@ -157,13 +161,17 @@ parse() {
157 161
     dqueue | dq )
158 162
         for LINE in $(cat /tmp/yt-queue)
159 163
         do
160
-            yt-down "$LINE"
164
+            yt-down -D "$LINE"
165
+            grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp
166
+            mv /tmp/yt-queue.tmp /tmp/yt-queue
161 167
         done
162 168
         ;;
163 169
     squeue | sq )
164 170
         for LINE in $(cat /tmp/yt-queue)
165 171
         do
166
-            yt-down -s "$LINE"
172
+            yt-down -S "$LINE"
173
+            grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp
174
+            mv /tmp/yt-queue.tmp /tmp/yt-queue
167 175
         done
168 176
         ;;
169 177
     about | ! )