SHOW:
|
|
- or go back to the newest paste.
1 | #! /bin/awk -f | |
2 | ||
3 | # Running examples (simple.awk is name of this script): | |
4 | # | |
5 | # ./simple.awk sample.txt | |
6 | # ./simple.awk -v debug=1 sample.txt | |
7 | # ./simple.awk -v path='~/Media/' sample.txt | |
8 | # ./simple.awk -v debug=1 -v path='~/Media/' sample.txt | |
9 | ||
10 | BEGIN { | |
11 | LDEBUG=""; | |
12 | LPATH=""; | |
13 | if(length(path)>0){ | |
14 | LPATH=path; | |
15 | } | |
16 | if(length(debug)>0){ | |
17 | LDEBUG=debug; | |
18 | } | |
19 | extinf=""; | |
20 | } | |
21 | ||
22 | /^#EXTINF:[0-9]+,.+$/{ | |
23 | gsub(/[ \t\n\r]+$/,""); # remove trailing non-printable chars from $0 | |
24 | match($0,/^#EXTINF:([0-9]+),(.+)[[:space:]]*$/,ar); | |
25 | gsub(/"/,"\\\"",ar[2]); # adding backslash to double quotes if found in song name | |
26 | extinf = "\"" ar[1] "." ar[2] ".mp3\""; | |
27 | if(LPATH) extinf = LPATH extinf; | |
28 | if(LDEBUG) print extinf; | |
29 | } | |
30 | ||
31 | /^http:\/\/.+\.mp3[\ \n\r\t]*$/{ | |
32 | if(extinf){ | |
33 | gsub(/[ \t\n\r]+$/,""); # remove trailing non-printable chars from $0 | |
34 | cmd="wget -O "extinf" '"$0"'"; | |
35 | if(LDEBUG) print cmd; | |
36 | else system(cmd); | |
37 | extinf=""; | |
38 | } | |
39 | } |