2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urlparse
10 class BaiduVideoIE(InfoExtractor):
12 _VALID_URL = r'http://v\.baidu\.com/(?P<type>[a-z]+)/(?P<id>\d+)\.htm'
14 'url': 'http://v.baidu.com/comic/1069.htm?frp=bdbrand&q=%E4%B8%AD%E5%8D%8E%E5%B0%8F%E5%BD%93%E5%AE%B6',
17 'title': '中华小当家 TV版 (全52集)',
18 'description': 'md5:395a419e41215e531c857bb037bbaf80',
22 'url': 'http://v.baidu.com/show/11595.htm?frp=bdbrand',
26 'description': 'md5:1bf88bad6d850930f542d51547c089b8',
28 'playlist_mincount': 3,
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
33 playlist_id = mobj.group('id')
34 category = category2 = mobj.group('type')
35 if category == 'show':
38 webpage = self._download_webpage(url, playlist_id)
40 playlist_title = self._html_search_regex(
41 r'title\s*:\s*(["\'])(?P<title>[^\']+)\1', webpage,
42 'playlist title', group='title')
43 playlist_description = self._html_search_regex(
44 r'<input[^>]+class="j-data-intro"[^>]+value="([^"]+)"/>', webpage,
45 playlist_id, 'playlist description')
47 site = self._html_search_regex(
48 r'filterSite\s*:\s*["\']([^"]*)["\']', webpage,
49 'primary provider site')
50 api_result = self._download_json(
51 'http://v.baidu.com/%s_intro/?dtype=%sPlayUrl&id=%s&site=%s' % (
52 category, category2, playlist_id, site),
53 playlist_id, 'Get playlist links')
56 for episode in api_result[0]['episodes']:
57 episode_id = '%s_%s' % (playlist_id, episode['episode'])
59 redirect_page = self._download_webpage(
60 compat_urlparse.urljoin(url, episode['url']), episode_id,
61 note='Download Baidu redirect page')
62 real_url = self._html_search_regex(
63 r'location\.replace\("([^"]+)"\)', redirect_page, 'real URL')
65 entries.append(self.url_result(
66 real_url, video_title=episode['single_title']))
68 return self.playlist_result(
69 entries, playlist_id, playlist_title, playlist_description)