vp

git clone git://oldgit.suckless.org/vp/
Log | Files | Refs | README

commit 4da671831028313784417d5c69a464b890758de7
parent 701115683cc92cf8d6acd937442d9da79323d7fe
Author: Kris Maglione <kris@suckless.org>
Date:   Sat,  4 Sep 2010 04:00:46 -0400

Add Google Video and Fora.tv

Diffstat:
vp | 2+-
vp-base | 63++++++++++++++++++++++++++++++++++++++++-----------------------
vp-fora | 30++++++++++++++++++++++++++++++
vp-google | 16++++++++++++++++
vp-youtube | 29++++++++++++++---------------
vp-ytlogin | 17+++++++++++++++--
6 files changed, 116 insertions(+), 41 deletions(-)

diff --git a/vp b/vp @@ -4,7 +4,7 @@ vp_subscript = 1 getflags 'e,f,F format,o output-file' -vp_format = $flagF +ifs=, { vp_format = `{echo -n $flagF} } vp_result = $argv(1) vp_default vp_result `{vp_paste} diff --git a/vp-base b/vp-base @@ -35,7 +35,7 @@ if(~ $vp_base_loaded '') { fn js { builtin js || kjs /dev/stdin } # Plan 9's sed doesn't work with long lines - fn sed { /bin/sed -r $* || /usr/bin/sed -E $* } + # fn sed { /bin/sed -r $* || /usr/bin/sed -E $* } fn vp_data { if (~ $1 '') cat @@ -56,6 +56,7 @@ if(~ $vp_base_loaded '') { if(test -n $"vp_need_cookies -a -z $"vp_have_player_cookies) vp_savevideo = $vp_vidtemp if(test -n $"vp_savevideo) { + echo >[1=2] vp: Saving to $vp_savevideo $vp_hget_silent $1 >$vp_savevideo & hget = $apid * = $vp_savevideo @@ -77,41 +78,57 @@ if(~ $vp_base_loaded '') { vp_urldec = 'hextab["' ^ (0 1 2 3 4 5 6 7 8 9 a b c d e f) ^ '"] = ' ^ `{seq 0 15} ^ ';' vp_urldec = ' BEGIN { '$"vp_urldec' } - function urldec(str, c, i, res) { - i = 1 - res = "" - for (i=1; i <= length(str); i++) { - c = substr(str, i, 1); - if(c == "%") { - c1 = hextab[tolower(substr(str, i+1, 1))] - c2 = hextab[tolower(substr(str, i+2, 1))] - if(c1 != "" && c2 != "") { - code = c1 * 16 + c2 - c = sprintf("%c", code) - i += 2 - } - } else if(c == "+") - c = " " - if(c != "\r") - res = res c + function urldec(str, token, ary, c1, c2, i, n, res) { + if(!token) + token = "%" + gsub(/\+/, " ", str) + n = split(str, ary, token) + res = ary[1] + for(i=2; i <= n; i++) { + c1 = hextab[tolower(substr(ary[i], 1, 1))] + c2 = hextab[tolower(substr(ary[i], 2, 1))] + if(c1 != "" && c2 != "") + res = res sprintf("%c", c1 * 16 + c2) + res = res substr(ary[i], 3) } return res } - function urlparse(a, str, sep1, sep2, i, n, items, kv) { + function urlparse(str, ary, sep1, sep2, i, n, items, kv) { if(sep1 == "") sep1 = "&" if(sep2 == "") sep2 = "=" n = split(str, items, sep1) for(i=1; i <= n; i++) { split(items[i], kv, sep2) - a[urldec(kv[1])] = urldec(kv[2]) + ary[urldec(kv[1])] = urldec(kv[2]) } }' + fn vp_awk { + ifs=() { + eval `{ + awk $"vp_urldec ^ ' + BEGIN { print ";" >"/dev/fd/3" } + function quote(val) { + gsub(/''/, "''''", val) + return "''" val "''" + } + function set(var, val) { + print var "=" quote(val) >"/dev/fd/3" + } + ' ^ $"* >[3=1] >[1=4] + # Best not think too much about these + # redirections. In short: + # 1 -> stdout + # 3 -> eval + } >[4=1] + } + } + config=$XDG_CONFIG_HOME ^ /vp.conf - test -f $config && . $config } -if (rc -c 'which config-' ^ $vp_script >/dev/null >[2=1]) - config- ^ $vp_script +test -f $config && . $config +if(! ~ $vp_script '') + config- ^ $vp_script >[2]/dev/null diff --git a/vp-fora b/vp-fora @@ -0,0 +1,30 @@ +#!/usr/bin/env rc +# +# Pattern: ^http://fora.tv/ +# +# TODO: Fallback to rtmp stream when mp4 is unavailable. + +. vp-base $0 $* + +vp_data $* | vp_awk ' + /full_program_clipid =/ { + gsub(/;/, ""); + set("clipid", $4) + exit 0 + }' +vp_data 'http://fora.tv/fora/fora_player_full?cid='^$"clipid | vp_awk ' + { + match($0, /<[a-zA-Z-_]+/) + tag = substr($0, RSTART+1, RLENGTH-1) + str = substr($0, RSTART + RLENGTH + 1) + match(str, "</" tag) + tags[tag] = substr(str, 1, RSTART - 1) + } + END { + name = tags["encode_url"] + sub(/-[^-]+-[0-9]+.flv$/, "", name) + set("vp_result", "http://foratv.vo.llnwd.net/o33/mp4/" name "-" ENVIRON["clipid"] "-new_download.mp4") + }' + +vp_result $vp_result + diff --git a/vp-google b/vp-google @@ -0,0 +1,16 @@ +#!/usr/bin/env rc +# +# Pattern: ^http://video.google.com/videoplay\? + +. vp-base $0 $* + +vp_data $* | vp_awk ' + /videoUrl(=|\\x3d)/ { + $0 = urldec($0, "\\\\x") + sub(/.*videoUrl=/, "") + sub(/&.*/, "") + set("vp_result", urldec($0)) + exit 0 + }' +vp_result $vp_result + diff --git a/vp-youtube b/vp-youtube @@ -22,25 +22,24 @@ vp_need_cookies = 1 . vp-base $0 $* -vp_getdata data `{echo $* | sed 's/#(!|%21)v=/?v=/'} - -swfargs=`{ { echo ""; sed <$data -n 's/.*flashvars=\\"(([^\\]|\\[^"])+).*/\1/p' } | tail -1 } - -fmt_array = ($vp_format $vp_youtube_formats) -fmt_array = 'fmt[' ^ `{seq 1 $#fmt_array} ^ '] = ' ^ $fmt_array ^ ';' - -vp_result `{sed <$data -n 's/.*setAvailableFormat\("(.*)"\);.*/\1/p' | awk -F '", "' $vp_urldec ^ ' - { fmt_url_map[$4] = $1 } +vp_data `{echo $* | sed 's/#(!|%21)v=/?v=/'} | vp_awk ' + /flashvars=\\"/ { + split($0, a, /.*flashvars=\\"|\\"/) + urlparse(a[2], swfargs) + } + /setAvailableFormat\(/ { + split($0, a, /.*setAvailableFormat\("|", "|"\)/) + fmt_url_map[a[5]] = a[2] + } END { - urlparse(swfargs, ENVIRON["swfargs"]) - urlparse(fmt_url_map, swfargs["fmt_url_map"], ",", "|") - '$"fmt_array' + urlparse(ENVIRON["swfargs"], swfargs) + urlparse(swfargs["fmt_url_map"], fmt_url_map, ",", "|") + split("' $vp_format $vp_youtube_formats '", fmt) for(i=1; i <= length(fmt); i++) if(fmt[i] in fmt_url_map) { - print fmt_url_map[fmt[i]] + set("vp_result", fmt_url_map[fmt[i]]) exit 0 } }' -} -rm $data +vp_result $vp_result diff --git a/vp-ytlogin b/vp-ytlogin @@ -1,16 +1,29 @@ #!/usr/bin/env rc +. vp-base vp-ytlogin echo -n 'User: '; user=`{read} stty -echo echo -n 'Pass: '; pass=`{read}; echo stty echo -curl >/dev/null 'http://www.youtube.com/signup?next=/&gl=US&hl=en' \ +vp_hget = (curl -vsL -b $vp_cookie_jar -c $vp_cookie_jar -A $vp_user_agent) + +$vp_hget >/dev/null 'http://www.youtube.com/signup?next=/&gl=US&hl=en' \ -F'current_form=loginForm' \ -F'next=/' \ -F'action_login=Log In' \ -F'username='$"user \ -F'password='$"pass -curl >/dev/null 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en' \ +true $vp_hget >/dev/null 'https://www.google.com/accounts/ServiceLoginAuth?service=youtube' \ + -F'continue=http://www.youtube.com/signin?action_handle_signin=true&amp;nomobiletemp=1&amp;hl=en_US&amp;next=%2F' \ + -F'ltmpl=sso' \ + -F'service=youtube' \ + -F'uilel=3' \ + -F'hl=en_US' \ + -F'PersistentCookie=yes' \ + -F'signIn=Sign In' \ + -F'Email='$"user \ + -F'Passwd='$"pass +$vp_hget >/dev/null 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en' \ -F'next_url=/' \ -F'action_confirm=Confirm'