]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bilibili.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class BiliBiliIE(InfoExtractor
):
16 _VALID_URL
= r
'http://www\.bilibili\.tv/video/av(?P<id>[0-9]+)/'
19 'url': 'http://www.bilibili.tv/video/av1074402/',
20 'md5': '2c301e4dab317596e837c3e7633e7d86',
26 'upload_date': '20140420',
27 'thumbnail': 're:^https?://.+\.jpg',
31 def _real_extract(self
, url
):
32 mobj
= re
.match(self
._VALID
_URL
, url
)
33 video_id
= mobj
.group('id')
35 webpage
= self
._download
_webpage
(url
, video_id
)
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 player_params
= compat_parse_qs(self
._html
_search
_regex
(
59 r
'<iframe .*?class="player" src="https://secure.bilibili.tv/secure,([^"]+)"',
60 webpage
, 'player params'))
62 if 'cid' in player_params
:
63 cid
= player_params
['cid'][0]
65 lq_doc
= self
._download
_xml
(
66 'http://interface.bilibili.cn/v_cdn_play?cid=%s' % cid
,
68 note
='Downloading LQ video info'
70 lq_durl
= lq_doc
.find('.//durl')
74 'url': lq_durl
.find('./url').text
,
75 'filesize': int_or_none(
76 lq_durl
.find('./size'), get_attr
='text'),
79 hq_doc
= self
._download
_xml
(
80 'http://interface.bilibili.cn/playurl?cid=%s' % cid
,
82 note
='Downloading HQ video info',
85 if hq_doc
is not False:
86 hq_durl
= hq_doc
.find('.//durl')
91 'url': hq_durl
.find('./url').text
,
92 'filesize': int_or_none(
93 hq_durl
.find('./size'), get_attr
='text'),
96 raise ExtractorError('Unsupported player parameters: %r' % (player_params
,))
98 self
._sort
_formats
(formats
)
103 'duration': duration
,
104 'upload_date': upload_date
,
105 'thumbnail': thumbnail
,