vimeo_user_atom.sh - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       vimeo_user_atom.sh (1592B)
       ---
            1 #!/bin/sh
            2 # lists Vimeo videos from a user (by userid) and converts the list to an
            3 # Atom feed.
            4 #
            5 # to find an user id, go to a page, for example:
            6 # https://vimeo.com/rossmanngroup
            7 # then see the HTML tag
            8 # <meta property="al:android:url" content="vimeo://app.vimeo.com/users/66583856">
            9 #
           10 # Dependencies: hurl, json2tsv, awk.
           11 
           12 userid="$1"
           13 
           14 if test x"${userid}" = x""; then
           15         echo "usage: $0 <userid>" >&2
           16         exit 1
           17 fi
           18 
           19 hurl -t 15 "https://vimeo.com/api/v2/user/${userid}/videos.json" | \
           20 json2tsv -r -F '\x1f' -R '\x1e'  | \
           21 awk '
           22 BEGIN {
           23         FS = "\x1f"; RS = "\x1e";
           24 }
           25 function encode(s) {
           26         # HTML.
           27         gsub("&", "\\&amp;", s);
           28         gsub("<", "\\&lt;", s);
           29         gsub(">", "\\&gt;", s);
           30         gsub("\"", "\\&quot;", s);
           31         gsub("'"'"'", "\\&#39;", s);
           32         return s;
           33 }
           34 function show() {
           35         if (!length(o["id"]))
           36                 return;
           37 
           38         uploaded = o["upload_date"];
           39         gsub(" ", "T", uploaded);
           40         uploaded = uploaded "Z";
           41 
           42         s = int(o["duration"]);
           43         m = s / 60;
           44         h = s / 3600;
           45         title = sprintf("%s [%d:%02d:%02d]", o["title"], h, m % 60, s % 60);
           46 
           47         print "<entry>";
           48         print  "\t<title type=\"text\">" encode(title) "</title>";
           49         print  "\t<published>" encode(uploaded) "</published>";
           50         print  "\t<updated>" encode(uploaded) "</updated>";
           51         print  "\t<link rel=\"alternate\" type=\"text/html\" href=\"https://vimeo.com/" encode(o["id"]) "\"/>";
           52         print  "</entry>";
           53 }
           54 $1 == "[]" && $2 == "o" {
           55         show();
           56         delete o;
           57 }
           58 $1 ~ /^\[\]\.[a-zA-Z0-9_]*$/ {
           59         o[substr($1, 4)] = $3;
           60 }
           61 BEGIN {
           62         print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
           63         print "<feed xmlns=\"http://www.w3.org/2005/Atom\" xml:lang=\"en\">";
           64 }
           65 END {
           66         show();
           67         print "</feed>";
           68 }'