Browse code

Greatly improved yt-meta command parsing

Jade Levesque authored on 2017-02-19 07:02:37
Showing 1 changed files
... ...
@@ -1,3 +1,5 @@
1
+#!/bin/sh
2
+
1 3
 #####################
2 4
 # Name: yt-meta.sh
3 5
 # Date: 2016-12-10
... ...
@@ -9,15 +11,45 @@
9 11
 
10 12
 # Usage: yt-meta.sh $video_id
11 13
 
12
-if echo "$1" | grep "youtube.com"
14
+optnum=0
15
+
16
+for argument in $@
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
+    *)
40
+        preid="$argument"
41
+    esac
42
+done
43
+        
44
+if echo "$preid" | grep "youtube.com"
13 45
 then 
14 46
     id="$(echo $1 | sed 's/.*video_id=//')"
15
-elif [ -z $1 ]
47
+elif [ -z $preid ]
16 48
 then
17 49
     echo "No video specified."
18 50
     exit 1
19 51
 else
20
-    id="$1"
52
+    id="$preid"
21 53
 fi
22 54
 
23 55
 if [ -e "./lib/yt-meta" ]
... ...
@@ -51,3 +83,20 @@ duration="$(grep "<a href=\"/watch?v=$1" $video_file.1 | sed 's/.*Duration: //'
51 83
 date="$(grep "datePublished" $video_file | sed 's/.*"datePublished" content="//' | sed 's/".*//')"
52 84
 echo "$title"
53 85
 echo "$author | $views | $duration | $date | $1"
86
+
87
+for option in $options
88
+do
89
+    case $option in
90
+        c) printf "$author" ;;
91
+        t) printf "$title" ;;
92
+        d) printf "$duration" ;;
93
+        D) printf "$date" ;;
94
+        v) printf "$views" ;;
95
+    esac
96
+    if [ $optnum -ge 2 ]
97
+    then
98
+        printf " | "
99
+        optnum=$((optnum-1))
100
+    fi
101
+done
102
+cp $video_file /tmp/mateo