public
Last active

  • Download Gist
YoutubeDL.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import urllib2, urlparse, sys, webbrowser
 
itags = {'45': 'webm_720p',
'44': 'webm_480p',
'43': 'webm_360p',
'38': 'mp4_3072p',
'37': 'mp4_1080p',
'36': 'phone_mp4_240p',
'35': 'flv_480p',
'34': 'flv_360p',
'22': 'mp4_720p',
'18': 'mp4_360p',
'17': 'phone_mp4_144p',
'5': 'flv_240p'}
 
order_preference = ['18', '22', '34', '35']
 
def main():
v_id = None
if (len(sys.argv) > 0):
try:
v_id = urlparse.parse_qs(sys.argv[1].split('?')[1])['v'][0]
except Exception:
v_id = None
if not v_id:
print repr(sys.argv)
return
config = urllib2.urlopen('http://www.youtube.com/get_video_info?&video_id=%s&el=detailpage&ps=default&eurl=&gl=US&hl=en' % v_id).read()
config = urlparse.parse_qs(config)
formats = [urlparse.parse_qs(x) for x in config['url_encoded_fmt_stream_map'][0].split(',')]
filtered_formats = dict([(x.get('itag', [0])[0], x) for x in formats if x.get('itag', [0])[0] in order_preference])
sorted_formats = [filtered_formats[x] for x in order_preference if filtered_formats.has_key(x)]
first_pick = sorted_formats[0]
download_url = first_pick['url'][0]
if first_pick.has_key('sig'):
download_url += ('&signature=' + first_pick['sig'][0])
download_url = download_url.replace('http://', 'iDownloads://')
webbrowser.open(download_url)
 
if __name__ == '__main__':
main()
 
# Bookmarklet:
# javascript:window.location='pythonista://YoutubeDL?action=run&argv='+encodeURIComponent(document.location.href);

javascript:window.location='pythonista://YoutubeDL?action=run&argv='+encodeURIComponent(document.location.href);

最后找到一个可用的project . https://github.com/rg3/youtube-dl 挺好用
python main.py www.youtube.com/watch?v=wYowgVn5_8w

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.