-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutube.awk
More file actions
41 lines (37 loc) · 1.24 KB
/
youtube.awk
File metadata and controls
41 lines (37 loc) · 1.24 KB
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
#
# youtube.awk: Small program to separate the audio and videos for download
# using youtube-dl.
# It parses the output of "youtebe-dl -F"
#
@include "getopt"
BEGIN {
otype = "default"
ofmt["default"] = "id: %s\naudio: %d\nvideo: %d\n"
ofmt["csv" ] = "%s,%d,%d\n"
ofmt["json" ] = "{ \"id\": \"%s\", \"audio\": %d, \"video\": %d }\n"
ofmt["xml" ] = "<id>%s</id><audio>%d</audio><video>%d</video>\n"
while (c = getopt(ARGC, ARGV, "cjx") != -1) {
switch (Optopt) {
case "c" : otype = "csv" ; break
case "j" : otype = "json" ; break
case "x" : otype = "xml" ; break
case "?" :
default :
print "Warning: Invalid Option: " Optopt
print " : " Opterr
}
}
# clear the arguments list
for (i = 1; i < Optind; i++) {
ARGV[i] = ""
}
}
"[youtube]" == $1 { id = substr($2, 1, length($2)-1) }
/audio only/ { audio[$2] = $1 }
/mp4|webm/ &&
"medium" == $4 { video[$2] = $1 }
END {
acode = audio["webm"] ? audio["webm"] : audio["m4a"] ? audio["m4a"] : 0
vcode = video["webm"] ? video["webm"] : video["mp4"] ? video["mp4"] : 0
printf(ofmt[otype], id, acode, vcode)
}