2 from __future__ import unicode_literals
6 from .common import InfoExtractor
14 class BiliBiliIE(InfoExtractor):
15 _VALID_URL = r'http://www\.bilibili\.(?:tv|com)/video/av(?P<id>[0-9]+)/'
18 'url': 'http://www.bilibili.tv/video/av1074402/',
19 'md5': '2c301e4dab317596e837c3e7633e7d86',
25 'upload_date': '20140420',
26 'thumbnail': 're:^https?://.+\.jpg',
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32 webpage = self._download_webpage(url, video_id)
34 if self._search_regex(r'(此视频不存在或被删除)', webpage, 'error message', default=None):
35 raise ExtractorError('The video does not exist or was deleted', expected=True)
36 video_code = self._search_regex(
37 r'(?s)<div itemprop="video".*?>(.*?)</div>', webpage, 'video code')
39 title = self._html_search_meta(
40 'media:title', video_code, 'title', fatal=True)
41 duration_str = self._html_search_meta(
42 'duration', video_code, 'duration')
43 if duration_str is None:
46 duration_mobj = re.match(
47 r'^T(?:(?P<hours>[0-9]+)H)?(?P<minutes>[0-9]+)M(?P<seconds>[0-9]+)S$',
50 int_or_none(duration_mobj.group('hours'), default=0) * 3600 +
51 int(duration_mobj.group('minutes')) * 60 +
52 int(duration_mobj.group('seconds')))
53 upload_date = unified_strdate(self._html_search_meta(
54 'uploadDate', video_code, fatal=False))
55 thumbnail = self._html_search_meta(
56 'thumbnailUrl', video_code, 'thumbnail', fatal=False)
58 cid = self._search_regex(r'cid=(\d+)', webpage, 'cid')
60 lq_doc = self._download_xml(
61 'http://interface.bilibili.com/v_cdn_play?appkey=1&cid=%s' % cid,
63 note='Downloading LQ video info'
65 lq_durl = lq_doc.find('./durl')
69 'url': lq_durl.find('./url').text,
70 'filesize': int_or_none(
71 lq_durl.find('./size'), get_attr='text'),
74 hq_doc = self._download_xml(
75 'http://interface.bilibili.com/playurl?appkey=1&cid=%s' % cid,
77 note='Downloading HQ video info',
80 if hq_doc is not False:
81 hq_durl = hq_doc.find('./durl')
86 'url': hq_durl.find('./url').text,
87 'filesize': int_or_none(
88 hq_durl.find('./size'), get_attr='text'),
91 self._sort_formats(formats)
97 'upload_date': upload_date,
98 'thumbnail': thumbnail,