fix video urls
This commit is contained in:
parent
c97dce9431
commit
ff0352a0b7
1 changed files with 20 additions and 11 deletions
|
@ -4,35 +4,43 @@ from urllib import quote, unquote
|
||||||
import httplib
|
import httplib
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import re
|
import re
|
||||||
|
from urlparse import parse_qs
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
from ox.cache import readUrl, readUrlUnicode
|
from ox.cache import readUrl, readUrlUnicode
|
||||||
from ox import findString, findRe
|
from ox import findString, findRe
|
||||||
|
|
||||||
|
|
||||||
def getVideoKey(youtubeId):
|
def getVideoKey(youtubeId):
|
||||||
data = readUrl("http://www.youtube.com/get_video_info?&video_id=%s" % youtubeId)
|
for el_type in ['&el=embedded', '&el=detailpage', '&el=vevo', '']:
|
||||||
match = re.compile("token=(.+)&thumbnail").findall(data)
|
video_info_url = 'http://www.youtube.com/get_video_info?&video_id=%s%s&ps=default&eurl=&gl=US&hl=en' % (youtubeId, el_type)
|
||||||
if match:
|
try:
|
||||||
return unquote(match[0])
|
data = readUrl(video_info_url)
|
||||||
|
video_info = parse_qs(data)
|
||||||
|
if 'token' in video_info:
|
||||||
|
return video_info['token'][0]
|
||||||
|
except (urllib2.URLError, httplib.HTTPException, socket.error), err:
|
||||||
|
return
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getVideoUrl(youtubeId, format='mp4'):
|
def getVideoUrl(youtubeId, format='mp4'):
|
||||||
youtubeKey = getVideoKey(youtubeId)
|
youtubeKey = getVideoKey(youtubeId)
|
||||||
|
|
||||||
|
fmt = None
|
||||||
|
if format == 'webm':
|
||||||
|
fmt=45
|
||||||
if format == '1080p':
|
if format == '1080p':
|
||||||
fmt=37
|
fmt=37
|
||||||
url = "http://youtube.com/get_video.php?video_id=%s&t=%s&fmt=%s" % (youtubeId, youtubeKey, fmt)
|
|
||||||
if format == '720p':
|
if format == '720p':
|
||||||
fmt=22
|
fmt=22
|
||||||
url = "http://youtube.com/get_video.php?video_id=%s&t=%s&fmt=%s" % (youtubeId, youtubeKey, fmt)
|
|
||||||
elif format == 'mp4':
|
elif format == 'mp4':
|
||||||
fmt=18
|
fmt=18
|
||||||
url = "http://youtube.com/get_video.php?video_id=%s&t=%s&fmt=%s" % (youtubeId, youtubeKey, fmt)
|
|
||||||
elif format == 'high':
|
elif format == 'high':
|
||||||
fmt=35
|
fmt=35
|
||||||
url = "http://youtube.com/get_video.php?video_id=%s&t=%s&fmt=%s" % (youtubeId, youtubeKey, fmt)
|
url_template = "http://www.youtube.com/get_video?video_id=%s&t=%s=&eurl=&el=&ps=&asv="
|
||||||
else:
|
url = url_template % (youtubeId, youtubeKey)
|
||||||
url = "http://youtube.com/get_video.php?video_id=%s&t=%s" % (youtubeId, youtubeKey)
|
if fmt:
|
||||||
|
url += "&fmt=%d"%fmt
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def getMovieInfo(youtubeId, video_url_base=None):
|
def getMovieInfo(youtubeId, video_url_base=None):
|
||||||
|
@ -58,6 +66,7 @@ def getInfoFromAtom(entry, video_url_base=None):
|
||||||
else:
|
else:
|
||||||
info['flv'] = getVideoUrl(info['id'], 'flv')
|
info['flv'] = getVideoUrl(info['id'], 'flv')
|
||||||
info['flv_high'] = getVideoUrl(info['id'], 'high')
|
info['flv_high'] = getVideoUrl(info['id'], 'high')
|
||||||
|
info['webm'] = getVideoUrl(info['id'], 'webm')
|
||||||
info['mp4'] = getVideoUrl(info['id'], 'mp4')
|
info['mp4'] = getVideoUrl(info['id'], 'mp4')
|
||||||
info['720p'] = getVideoUrl(info['id'], '720p')
|
info['720p'] = getVideoUrl(info['id'], '720p')
|
||||||
info['1080p'] = getVideoUrl(info['id'], '1080p')
|
info['1080p'] = getVideoUrl(info['id'], '1080p')
|
||||||
|
|
Loading…
Reference in a new issue