]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bilibili.py
75d744852edc382721cee8556067f89ccb0092df
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
13 class BiliBiliIE(InfoExtractor
):
14 _VALID_URL
= r
'http://www\.bilibili\.(?:tv|com)/video/av(?P<id>[0-9]+)/'
17 'url': 'http://www.bilibili.tv/video/av1074402/',
18 'md5': '2c301e4dab317596e837c3e7633e7d86',
24 'upload_date': '20140420',
25 'thumbnail': 're:^https?://.+\.jpg',
29 def _real_extract(self
, url
):
30 video_id
= self
._match
_id
(url
)
31 webpage
= self
._download
_webpage
(url
, video_id
)
33 video_code
= self
._search
_regex
(
34 r
'(?s)<div itemprop="video".*?>(.*?)</div>', webpage
, 'video code')
36 title
= self
._html
_search
_meta
(
37 'media:title', video_code
, 'title', fatal
=True)
38 duration_str
= self
._html
_search
_meta
(
39 'duration', video_code
, 'duration')
40 if duration_str
is None:
43 duration_mobj
= re
.match(
44 r
'^T(?:(?P<hours>[0-9]+)H)?(?P<minutes>[0-9]+)M(?P<seconds>[0-9]+)S$',
47 int_or_none(duration_mobj
.group('hours'), default
=0) * 3600 +
48 int(duration_mobj
.group('minutes')) * 60 +
49 int(duration_mobj
.group('seconds')))
50 upload_date
= unified_strdate(self
._html
_search
_meta
(
51 'uploadDate', video_code
, fatal
=False))
52 thumbnail
= self
._html
_search
_meta
(
53 'thumbnailUrl', video_code
, 'thumbnail', fatal
=False)
55 cid
= self
._search
_regex
(r
'cid=(\d+)', webpage
, 'cid')
57 lq_doc
= self
._download
_xml
(
58 'http://interface.bilibili.com/v_cdn_play?appkey=1&cid=%s' % cid
,
60 note
='Downloading LQ video info'
62 lq_durl
= lq_doc
.find('./durl')
66 'url': lq_durl
.find('./url').text
,
67 'filesize': int_or_none(
68 lq_durl
.find('./size'), get_attr
='text'),
71 hq_doc
= self
._download
_xml
(
72 'http://interface.bilibili.com/playurl?appkey=1&cid=%s' % cid
,
74 note
='Downloading HQ video info',
77 if hq_doc
is not False:
78 hq_durl
= hq_doc
.find('./durl')
83 'url': hq_durl
.find('./url').text
,
84 'filesize': int_or_none(
85 hq_durl
.find('./size'), get_attr
='text'),
88 self
._sort
_formats
(formats
)
94 'upload_date': upload_date
,
95 'thumbnail': thumbnail
,