Advertisement
Guest User

simple.awk

a guest
Mar 16th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.90 KB | None | 0 0
  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.   extinf = "\"" ar[1] "." ar[2] ".mp3\"";
  26.   if(LPATH)  extinf = LPATH extinf;
  27.   if(LDEBUG) print extinf;
  28. }
  29.  
  30. /^http:\/\/.+\.mp3[\ \n\r\t]*$/{
  31.   if(extinf){
  32.     gsub(/[ \t\n\r]+$/,""); # remove trailing non-printable chars from $0
  33.     cmd="wget -O "extinf" '"$0"'";
  34.     if(LDEBUG) print cmd;
  35.     else system(cmd);
  36.     extinf="";
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement