]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/baidu.py
debian/copyright: Fix lintian's dep5-copyright-license-name-not-unique.
[youtubedl] / youtube_dl / extractor / baidu.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_urlparse
8
9
10 class BaiduVideoIE(InfoExtractor):
11 _VALID_URL = r'http://v\.baidu\.com/(?P<type>[a-z]+)/(?P<id>\d+)\.htm'
12 _TESTS = [{
13 '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',
14 'info_dict': {
15 'id': '1069',
16 'title': '中华小当家 TV版 (全52集)',
17 'description': 'md5:395a419e41215e531c857bb037bbaf80',
18 },
19 'playlist_count': 52,
20 }, {
21 'url': 'http://v.baidu.com/show/11595.htm?frp=bdbrand',
22 'info_dict': {
23 'id': '11595',
24 'title': 're:^奔跑吧兄弟',
25 'description': 'md5:1bf88bad6d850930f542d51547c089b8',
26 },
27 'playlist_mincount': 3,
28 }]
29
30 def _real_extract(self, url):
31 mobj = re.match(self._VALID_URL, url)
32 playlist_id = mobj.group('id')
33 category = category2 = mobj.group('type')
34 if category == 'show':
35 category2 = 'tvshow'
36
37 webpage = self._download_webpage(url, playlist_id)
38
39 playlist_title = self._html_search_regex(
40 r'title\s*:\s*(["\'])(?P<title>[^\']+)\1', webpage,
41 'playlist title', group='title')
42 playlist_description = self._html_search_regex(
43 r'<input[^>]+class="j-data-intro"[^>]+value="([^"]+)"/>', webpage,
44 playlist_id, 'playlist description')
45
46 site = self._html_search_regex(
47 r'filterSite\s*:\s*["\']([^"]*)["\']', webpage,
48 'primary provider site')
49 api_result = self._download_json(
50 'http://v.baidu.com/%s_intro/?dtype=%sPlayUrl&id=%s&site=%s' % (
51 category, category2, playlist_id, site),
52 playlist_id, 'Get playlist links')
53
54 entries = []
55 for episode in api_result[0]['episodes']:
56 episode_id = '%s_%s' % (playlist_id, episode['episode'])
57
58 redirect_page = self._download_webpage(
59 compat_urlparse.urljoin(url, episode['url']), episode_id,
60 note='Download Baidu redirect page')
61 real_url = self._html_search_regex(
62 r'location\.replace\("([^"]+)"\)', redirect_page, 'real URL')
63
64 entries.append(self.url_result(
65 real_url, video_title=episode['single_title']))
66
67 return self.playlist_result(
68 entries, playlist_id, playlist_title, playlist_description)