1 from __future__ import unicode_literals
7 from .common import InfoExtractor, SearchInfoExtractor
16 class YahooIE(InfoExtractor):
17 IE_DESC = 'Yahoo screen and movies'
18 _VALID_URL = r'(?P<url>https?://(?:screen|movies)\.yahoo\.com/.*?-(?P<id>[0-9]+)(?:-[a-z]+)?\.html)'
21 'url': 'http://screen.yahoo.com/julian-smith-travis-legg-watch-214727115.html',
22 'md5': '4962b075c08be8690a922ee026d05e69',
24 'id': '2d25e626-2378-391f-ada0-ddaf1417e588',
26 'title': 'Julian Smith & Travis Legg Watch Julian Smith',
27 'description': 'Julian and Travis watch Julian Smith',
31 'url': 'http://screen.yahoo.com/wired/codefellas-s1-ep12-cougar-lies-103000935.html',
32 'md5': 'd6e6fc6e1313c608f316ddad7b82b306',
34 'id': 'd1dedf8c-d58c-38c3-8963-e899929ae0a9',
36 'title': 'Codefellas - The Cougar Lies with Spanish Moss',
37 'description': 'Agent Topple\'s mustache does its dirty work, and Nicole brokers a deal for peace. But why is the NSA collecting millions of Instagram brunch photos? And if your waffles have nothing to hide, what are they so worried about?',
41 'url': 'https://screen.yahoo.com/community/community-sizzle-reel-203225340.html?format=embed',
42 'md5': '60e8ac193d8fb71997caa8fce54c6460',
44 'id': '4fe78544-8d48-39d8-97cd-13f205d9fcdb',
46 'title': "Yahoo Saves 'Community'",
47 'description': 'md5:4d4145af2fd3de00cbb6c1d664105053',
52 def _real_extract(self, url):
53 mobj = re.match(self._VALID_URL, url)
54 video_id = mobj.group('id')
55 url = mobj.group('url')
56 webpage = self._download_webpage(url, video_id)
58 items_json = self._search_regex(
59 r'mediaItems: ({.*?})$', webpage, 'items', flags=re.MULTILINE,
61 if items_json is None:
62 CONTENT_ID_REGEXES = [
63 r'YUI\.namespace\("Media"\)\.CONTENT_ID\s*=\s*"([^"]+)"',
64 r'root\.App\.Cache\.context\.videoCache\.curVideo = \{"([^"]+)"',
65 r'"first_videoid"\s*:\s*"([^"]+)"',
67 long_id = self._search_regex(CONTENT_ID_REGEXES, webpage, 'content ID')
70 items = json.loads(items_json)
71 info = items['mediaItems']['query']['results']['mediaObj'][0]
72 # The 'meta' field is not always in the video webpage, we request it
75 return self._get_info(long_id, video_id, webpage)
77 def _get_info(self, long_id, video_id, webpage):
78 query = ('SELECT * FROM yahoo.media.video.streams WHERE id="%s"'
79 ' AND plrs="86Gj0vCaSzV_Iuf6hNylf2" AND region="US"'
80 ' AND protocol="http"' % long_id)
81 data = compat_urllib_parse.urlencode({
86 query_result = self._download_json(
87 'http://video.query.yahoo.com/v1/public/yql?' + data,
88 video_id, 'Downloading video info')
89 info = query_result['query']['results']['mediaObj'][0]
93 for s in info['streams']:
95 'width': int_or_none(s.get('width')),
96 'height': int_or_none(s.get('height')),
97 'tbr': int_or_none(s.get('bitrate')),
102 if host.startswith('rtmp'):
109 format_url = compat_urlparse.urljoin(host, path)
110 format_info['url'] = format_url
111 formats.append(format_info)
113 self._sort_formats(formats)
117 'title': meta['title'],
119 'description': clean_html(meta['description']),
120 'thumbnail': meta['thumbnail'] if meta.get('thumbnail') else self._og_search_thumbnail(webpage),
124 class YahooNewsIE(YahooIE):
125 IE_NAME = 'yahoo:news'
126 _VALID_URL = r'http://news\.yahoo\.com/video/.*?-(?P<id>\d*?)\.html'
129 'url': 'http://news.yahoo.com/video/china-moses-crazy-blues-104538833.html',
130 'md5': '67010fdf3a08d290e060a4dd96baa07b',
134 'title': 'China Moses Is Crazy About the Blues',
135 'description': 'md5:9900ab8cd5808175c7b3fe55b979bed0',
139 def _real_extract(self, url):
140 mobj = re.match(self._VALID_URL, url)
141 video_id = mobj.group('id')
142 webpage = self._download_webpage(url, video_id)
143 long_id = self._search_regex(r'contentId: \'(.+?)\',', webpage, 'long id')
144 return self._get_info(long_id, video_id, webpage)
147 class YahooSearchIE(SearchInfoExtractor):
148 IE_DESC = 'Yahoo screen search'
150 IE_NAME = 'screen.yahoo:search'
151 _SEARCH_KEY = 'yvsearch'
153 def _get_n_results(self, query, n):
154 """Get a specified number of results for a query"""
156 for pagenum in itertools.count(0):
157 result_url = 'http://video.search.yahoo.com/search/?p=%s&fr=screen&o=js&gs=0&b=%d' % (compat_urllib_parse.quote_plus(query), pagenum * 30)
158 info = self._download_json(result_url, query,
159 note='Downloading results page '+str(pagenum+1))
161 results = info['results']
163 for (i, r) in enumerate(results):
164 if (pagenum * 30) + i >= n:
166 mobj = re.search(r'(?P<url>screen\.yahoo\.com/.*?-\d*?\.html)"', r)
167 e = self.url_result('http://' + mobj.group('url'), 'Yahoo')
169 if (pagenum * 30 + i >= n) or (m['last'] >= (m['total'] - 1)):