YahooIE: remove old code and accept screen.yahoo.com videos (#300)

Videos require rtmpdump
This commit is contained in:
Jaime Marquínez Ferrándiz 2013-05-12 14:05:14 +02:00
parent 86fd453ea8
commit 59f4fd4dc6
2 changed files with 47 additions and 109 deletions

View File

@ -430,5 +430,15 @@
"info_dict":{ "info_dict":{
"title":"François Hollande \"Je crois que c'est clair\"" "title":"François Hollande \"Je crois que c'est clair\""
} }
},
{
"name": "Yahoo",
"url": "http://screen.yahoo.com/obama-celebrates-iraq-victory-27592561.html",
"file": "27592561.flv",
"md5": "c6179bed843512823fd284fa2e7f012d",
"info_dict": {
"title": "Obama Celebrates Iraq Victory"
},
"skip": "Requires rtmpdump"
} }
] ]

View File

@ -912,123 +912,51 @@ class PhotobucketIE(InfoExtractor):
class YahooIE(InfoExtractor): class YahooIE(InfoExtractor):
"""Information extractor for video.yahoo.com.""" """Information extractor for screen.yahoo.com."""
_VALID_URL = r'http://screen\.yahoo\.com/.*?-(?P<id>\d*?)\.html'
_WORKING = False def _real_extract(self, url):
# _VALID_URL matches all Yahoo! Video URLs
# _VPAGE_URL matches only the extractable '/watch/' URLs
_VALID_URL = r'(?:http://)?(?:[a-z]+\.)?video\.yahoo\.com/(?:watch|network)/([0-9]+)(?:/|\?v=)([0-9]+)(?:[#\?].*)?'
_VPAGE_URL = r'(?:http://)?video\.yahoo\.com/watch/([0-9]+)/([0-9]+)(?:[#\?].*)?'
IE_NAME = u'video.yahoo'
def _real_extract(self, url, new_video=True):
# Extract ID from URL
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
if mobj is None: if mobj is None:
raise ExtractorError(u'Invalid URL: %s' % url) raise ExtractorError(u'Invalid URL: %s' % url)
video_id = mobj.group('id')
video_id = mobj.group(2) # TODO: Check which url parameters are required
video_extension = 'flv' info_url = 'http://cosmos.bcst.yahoo.com/rest/v2/pops;lmsoverride=1;outputformat=mrss;cb=974419660;id=%s;rd=news.yahoo.com;datacontext=mdb;lg=KCa2IihxG3qE60vQ7HtyUy' % video_id
webpage = self._download_webpage(info_url, video_id, "Downloading info webpage")
# Rewrite valid but non-extractable URLs as info_re = r'''<title><!\[CDATA\[(?P<title>.*?)\]\]></title>.*
# extractable English language /watch/ URLs <description><!\[CDATA\[(?P<description>.*?)\]\]></description>.*
if re.match(self._VPAGE_URL, url) is None: <media:pubStart><!\[CDATA\[(?P<date>.*?)\ .*\]\]></media:pubStart>.*
request = compat_urllib_request.Request(url) <media:content\ medium="image"\ url="(?P<thumb>.*?)"\ name="LARGETHUMB"
try: '''
webpage = compat_urllib_request.urlopen(request).read()
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
raise ExtractorError(u'Unable to retrieve video webpage: %s' % compat_str(err))
mobj = re.search(r'\("id", "([0-9]+)"\);', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract id field')
yahoo_id = mobj.group(1)
mobj = re.search(r'\("vid", "([0-9]+)"\);', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract vid field')
yahoo_vid = mobj.group(1)
url = 'http://video.yahoo.com/watch/%s/%s' % (yahoo_vid, yahoo_id)
return self._real_extract(url, new_video=False)
# Retrieve video webpage to extract further information
request = compat_urllib_request.Request(url)
try:
self.report_download_webpage(video_id)
webpage = compat_urllib_request.urlopen(request).read()
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
raise ExtractorError(u'Unable to retrieve video webpage: %s' % compat_str(err))
# Extract uploader and title from webpage
self.report_extraction(video_id) self.report_extraction(video_id)
mobj = re.search(r'<meta name="title" content="(.*)" />', webpage) m_info = re.search(info_re, webpage, re.VERBOSE|re.DOTALL)
if mobj is None: if m_info is None:
raise ExtractorError(u'Unable to extract video title') raise ExtractorError(u'Unable to extract video info')
video_title = mobj.group(1).decode('utf-8') video_title = m_info.group('title')
video_description = m_info.group('description')
video_thumb = m_info.group('thumb')
video_date = m_info.group('date')
video_date = datetime.datetime.strptime(video_date, '%m/%d/%Y').strftime('%Y%m%d')
mobj = re.search(r'<h2 class="ti-5"><a href="http://video\.yahoo\.com/(people|profile)/[0-9]+" beacon=".*">(.*)</a></h2>', webpage) # TODO: Find a way to get mp4 videos
if mobj is None: rest_url = 'http://cosmos.bcst.yahoo.com/rest/v2/pops;element=stream;outputformat=mrss;id=%s;lmsoverride=1;bw=375;dynamicstream=1;cb=83521105;tech=flv,mp4;rd=news.yahoo.com;datacontext=mdb;lg=KCa2IihxG3qE60vQ7HtyUy' % video_id
raise ExtractorError(u'Unable to extract video uploader') webpage = self._download_webpage(rest_url, video_id, 'Downloading video url webpage')
video_uploader = mobj.group(1).decode('utf-8') m_rest = re.search(r'<media:content url="(?P<url>.*?)" path="(?P<path>.*?)"', webpage)
if m_rest is None:
raise ExtractorError(u'Unable to extract video url')
# Extract video thumbnail info_dict = {
mobj = re.search(r'<link rel="image_src" href="(.*)" />', webpage) 'id': video_id,
if mobj is None: 'url':m_rest.group('url'),
raise ExtractorError(u'Unable to extract video thumbnail') 'play_path': m_rest.group('path'),
video_thumbnail = mobj.group(1).decode('utf-8') 'title':video_title,
# Extract video description
mobj = re.search(r'<meta name="description" content="(.*)" />', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract video description')
video_description = mobj.group(1).decode('utf-8')
if not video_description:
video_description = 'No description available.'
# Extract video height and width
mobj = re.search(r'<meta name="video_height" content="([0-9]+)" />', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract video height')
yv_video_height = mobj.group(1)
mobj = re.search(r'<meta name="video_width" content="([0-9]+)" />', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract video width')
yv_video_width = mobj.group(1)
# Retrieve video playlist to extract media URL
# I'm not completely sure what all these options are, but we
# seem to need most of them, otherwise the server sends a 401.
yv_lg = 'R0xx6idZnW2zlrKP8xxAIR' # not sure what this represents
yv_bitrate = '700' # according to Wikipedia this is hard-coded
request = compat_urllib_request.Request('http://cosmos.bcst.yahoo.com/up/yep/process/getPlaylistFOP.php?node_id=' + video_id +
'&tech=flash&mode=playlist&lg=' + yv_lg + '&bitrate=' + yv_bitrate + '&vidH=' + yv_video_height +
'&vidW=' + yv_video_width + '&swf=as3&rd=video.yahoo.com&tk=null&adsupported=v1,v2,&eventid=1301797')
try:
self.report_download_webpage(video_id)
webpage = compat_urllib_request.urlopen(request).read()
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
raise ExtractorError(u'Unable to retrieve video webpage: %s' % compat_str(err))
# Extract media URL from playlist XML
mobj = re.search(r'<STREAM APP="(http://.*)" FULLPATH="/?(/.*\.flv\?[^"]*)"', webpage)
if mobj is None:
raise ExtractorError(u'Unable to extract media URL')
video_url = compat_urllib_parse.unquote(mobj.group(1) + mobj.group(2)).decode('utf-8')
video_url = unescapeHTML(video_url)
return [{
'id': video_id.decode('utf-8'),
'url': video_url,
'uploader': video_uploader,
'upload_date': None,
'title': video_title,
'ext': video_extension.decode('utf-8'),
'thumbnail': video_thumbnail.decode('utf-8'),
'description': video_description, 'description': video_description,
}] 'thumbnail': video_thumb,
'upload_date': video_date,
'ext': 'flv',
}
return info_dict
class VimeoIE(InfoExtractor): class VimeoIE(InfoExtractor):
"""Information extractor for vimeo.com.""" """Information extractor for vimeo.com."""