vp

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

vp-youtube (1791B)


      1 #!/usr/bin/env rc
      2 #
      3 # Pattern: ^https?://(www\d*\.)?youtube\.com/(v/|(watch(\.php|_videos)?))(\?|#!|#%21)
      4 #
      5 # Formats:
      6 #         Resolution  Ext   Video  / Audio    Rate Title
      7 #      0:   320x240   flv   (flv1) / mp3     22KHz
      8 #      5:   320x240   flv   (flv1) / mp3     22KHz "Small"
      9 #     13:   176x144   3gp   (H263) / AMR      8KHz
     10 #     17:   176x144   3gp   (mpg4) / AAC     22KHz
     11 #     18:   480x360   mp4   (H264) / AAC     44KHz "Large"
     12 #     22:  1280x720   mp4   (H264) / AAC     44KHz "HD720"
     13 #     34:   640x480   flv   (H264) / AAC     44KHz "Medium" (default)
     14 #     35:   854x640   flv   (H264) / AAC     44KHz "Large"
     15 #     36:   320x240   3gp   (mpg4) / AAC     22KHz
     16 #     37:  1920x1080  mp4   (H264) / AAC     44KHz "HD1080"
     17 #     43:   480x360   webm  (VP8 ) / Vorbis        "Medium"
     18 #     45:  1280x720   webm  (VP8 ) / Vorbis        "HD720"
     19 
     20 vp_youtube_formats = (22 45 18 35 34 5)
     21 vp_need_cookies = 1
     22 
     23 . vp-base $0 $*
     24 
     25 vp_data `{echo $* | sed 's/#(!|%21)v=/?v=/'} | vp_awk '
     26 	/flashvars=\\"/ {
     27 		split($0, a, /.*flashvars=\\"|\\"/)
     28 		urlparse(a[2], swfargs)
     29 	}
     30 	/flashvars="/ {
     31 		split($0, a, /.*flashvars="|"/)
     32 		gsub(/"/, "\"", a[2])
     33 		gsub(/&/, "\\&", a[2])
     34 		urlparse(a[2], swfargs)
     35 	}
     36 	/setAvailableFormat\(/ {
     37 		split($0, a, /.*setAvailableFormat\("|", "|"\)/)
     38 		fmt_url_map[a[5]] = a[2]
     39 	}
     40 	END {
     41 		urlparse(ENVIRON["swfargs"], swfargs)
     42 		urlparse(swfargs["fmt_url_map"], fmt_url_map, ",", "|")
     43 
     44 		n = split(swfargs["url_encoded_fmt_stream_map"], a, /,/)
     45 		for (i=i; i < n; i++) {
     46 			urlparse(a[i], fmt)
     47 			fmt_url_map[fmt["itag"]] = fmt["url"]
     48 		}
     49 
     50 		split("' $vp_format $vp_youtube_formats '", fmt)
     51 		for(i=1; i <= length(fmt); i++)
     52 			if(fmt[i] in fmt_url_map) {
     53 				set("vp_result", fmt_url_map[fmt[i]])
     54 				exit 0
     55 			}
     56 	}'
     57 vp_result $vp_result
     58