Browse code

Better arg handling yt-meta

Jade Levesque authored on 2017-02-19 19:06:56
Showing 2 changed files
... ...
@@ -15,35 +15,45 @@ optnum=0
15 15
 
16 16
 for argument in $@
17 17
 do
18
-    case $argument in
19
-    -c)
20
-        options="$options c"
21
-        optnum=$((optnum+1))
22
-        ;;
23
-    -d) # duration
24
-        options="$options d"
25
-        optnum=$((optnum+1))
26
-        ;;
27
-    -D) # date
28
-        options="$options D"
29
-        optnum=$((optnum+1))
30
-        ;;
31
-    -v)
32
-        options="$options v"
33
-        optnum=$((optnum+1))
34
-        ;;
35
-    -t)
36
-        options="$options t"
37
-        optnum=$((optnum+1))
38
-        ;;
39
-    *)
18
+    if echo $argument | grep "^-" > /dev/null
19
+    then
20
+        charcount=$(echo "$argument" | echo "$(wc -c) - 1" | bc)
21
+        while [ $charcount -gt 0 ]
22
+        do
23
+            character=$(echo "$argument" | head -c1)
24
+            argument=$(echo "$argument" | sed 's/^.//')
25
+            case $character in
26
+                c)
27
+                    options="$options c"
28
+                    optnum=$((optnum+1)) ;;
29
+                d) # duration
30
+                    options="$options d"
31
+                    optnum=$((optnum+1)) ;;
32
+                D) # date
33
+                    options="$options D"
34
+                    optnum=$((optnum+1)) ;;
35
+                v)
36
+                    options="$options v"
37
+                    optnum=$((optnum+1)) ;;
38
+                t)
39
+                    options="$options t"
40
+                    optnum=$((optnum+1)) ;;
41
+                i)
42
+                    options="$options i"
43
+                    optnum=$((optnum+1)) ;;
44
+                -)  ;;
45
+            esac
46
+            charcount=$((charcount-1))
47
+        done
48
+    else
40 49
         preid="$argument"
41
-    esac
42
-done
43
-        
44
-if echo "$preid" | grep "youtube.com"
50
+    fi
51
+done 
52
+
53
+
54
+if echo "$preid" | grep "youtube.com" > /dev/null
45 55
 then 
46
-    id="$(echo $1 | sed 's/.*video_id=//')"
56
+    id="$(echo $preid | sed 's/.*v=//')"
47 57
 elif [ -z $preid ]
48 58
 then
49 59
     echo "No video specified."
... ...
@@ -81,8 +91,11 @@ author="$(grep "\"author\":\"" $video_file | sed 's/.*"author":"//' | sed 's/".*
81 91
 views="$(grep "\"view_count\":\"" $video_file | sed 's/.*"view_count":"//' | sed 's/".*//')"
82 92
 duration="$(grep "<a href=\"/watch?v=$1" $video_file.1 | sed 's/.*Duration: //' | sed 's/\..*//')"
83 93
 date="$(grep "datePublished" $video_file | sed 's/.*"datePublished" content="//' | sed 's/".*//')"
84
-echo "$title"
85
-echo "$author | $views | $duration | $date | $1"
94
+
95
+if [ $optnum -eq 0 ]
96
+then
97
+    echo "$author | $views | $duration | $date | $id"
98
+fi
86 99
 
87 100
 for option in $options
88 101
 do
... ...
@@ -92,11 +105,13 @@ do
92 105
         d) printf "$duration" ;;
93 106
         D) printf "$date" ;;
94 107
         v) printf "$views" ;;
108
+        i) printf "$id" ;;
95 109
     esac
96 110
     if [ $optnum -ge 2 ]
97 111
     then
98 112
         printf " | "
99 113
         optnum=$((optnum-1))
114
+    else
115
+        printf "\n"
100 116
     fi
101 117
 done
102
-cp $video_file /tmp/mateo
... ...
@@ -5,20 +5,27 @@
5 5
 # Lisc: ISC
6 6
 # Main: jadedctrl
7 7
 # Desc: Full-shell YT client that avoids the YT API.
8
-  Vers=0.5.1
8
+  Vers=0.5.2
9 9
 #####################
10 10
 
11
-# Roadmap:
12
-# v1.0 - [X] Playlist support
11
+# Roadmap 1.0:
12
+#   yt-meta:
13
+#        [X] Args for specific info
14
+#        [X] Better argument handling
15
+#   yt-playlist:
16
+#        [X] Playlist support
17
+#        [ ] Better argument handling
18
+#   yt-channel:
13 19
 #        [X] Channel support
14
-#        [ ] Audio dl/stream
15
-#        [ ] Show related videos
20
+#        [ ] Better argument handling
21
+#   yt-search:
16 22
 #        [|] Channel & Playlist search
17 23
 #        [ ] Search filters
18
-#        [ ] Search & Channel sort-by
19
-#        [X] Config video player, etc
20
-#        [ ] Overall better interface
21
-#        [x] Cli args as commands
24
+#        [ ] Better argument handling
25
+#   general:
26
+#        [|] Config video player, etc
27
+#        [|] Cli args as commands
28
+
22 29
 
23 30
 if [ -e "$HOME/.config/shelltube" ]
24 31
 then
... ...
@@ -151,7 +158,14 @@ parse() {
151 158
     queue | lq )
152 159
         cat /tmp/yt-queue | while IFS='' read -r CUR_LINE
153 160
         do
154
-            yt-meta "$CUR_LINE"
161
+            if [ $row -eq 1 ]
162
+            then
163
+                printf '\033[1;34m%s\n' "$CUR_LINE"
164
+                row=0
165
+            else
166
+                printf '\033[1;31m%s\n' "$CUR_LINE"
167
+                row=1
168
+            fi
155 169
         done
156 170
         ;;
157 171
     cqueue | cq )
... ...
@@ -161,16 +175,22 @@ parse() {
161 175
     dqueue | dq )
162 176
         for LINE in $(cat /tmp/yt-queue)
163 177
         do
164
-            yt-down -D "$LINE"
165
-            grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp
178
+            itemid="$(echo "$LINE" | sed 's/.*\|  //')"
179
+            echo $itemid
180
+            sleep 3
181
+            yt-down -D "$itemid"
182
+            grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp
166 183
             mv /tmp/yt-queue.tmp /tmp/yt-queue
167 184
         done
168 185
         ;;
169 186
     squeue | sq )
170 187
         for LINE in $(cat /tmp/yt-queue)
171 188
         do
172
-            yt-down -S "$LINE"
173
-            grep -v "$LINE" /tmp/yt-queue > /tmp/yt-queue.tmp
189
+            itemid="$(echo "$LINE" | sed 's/.*|  //')"
190
+            echo $itemid
191
+            sleep 3
192
+            yt-down -S "$itemid"
193
+            grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp
174 194
             mv /tmp/yt-queue.tmp /tmp/yt-queue
175 195
         done
176 196
         ;;