]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/baidu.py
debian/copyright: Update my copyright years.
[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 ..utils import unescapeHTML
8
9
10 class BaiduVideoIE(InfoExtractor):
11 IE_DESC = '百度视频'
12 _VALID_URL = r'https?://v\.baidu\.com/(?P<type>[a-z]+)/(?P<id>\d+)\.htm'
13 _TESTS = [{
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',
15 'info_dict': {
16 'id': '1069',
17 'title': '中华小当家 TV版国语',
18 'description': 'md5:51be07afe461cf99fa61231421b5397c',
19 },
20 'playlist_count': 52,
21 }, {
22 'url': 'http://v.baidu.com/show/11595.htm?frp=bdbrand',
23 'info_dict': {
24 'id': '11595',
25 'title': 're:^奔跑吧兄弟',
26 'description': 'md5:1bf88bad6d850930f542d51547c089b8',
27 },
28 'playlist_mincount': 12,
29 }]
30
31 def _call_api(self, path, category, playlist_id, note):
32 return self._download_json('http://app.video.baidu.com/%s/?worktype=adnative%s&id=%s' % (
33 path, category, playlist_id), playlist_id, note)
34
35 def _real_extract(self, url):
36 category, playlist_id = re.match(self._VALID_URL, url).groups()
37 if category == 'show':
38 category = 'tvshow'
39 if category == 'tv':
40 category = 'tvplay'
41
42 playlist_detail = self._call_api(
43 'xqinfo', category, playlist_id, 'Download playlist JSON metadata')
44
45 playlist_title = playlist_detail['title']
46 playlist_description = unescapeHTML(playlist_detail.get('intro'))
47
48 episodes_detail = self._call_api(
49 'xqsingle', category, playlist_id, 'Download episodes JSON metadata')
50
51 entries = [self.url_result(
52 episode['url'], video_title=episode['title']
53 ) for episode in episodes_detail['videos']]
54
55 return self.playlist_result(
56 entries, playlist_id, playlist_title, playlist_description)