]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mgtv.py
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
19 class MGTVIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:www\.)?mgtv\.com/(v|b)/(?:[^/]+/)*(?P<id>\d+)\.html'
22 _GEO_COUNTRIES
= ['CN']
25 'url': 'http://www.mgtv.com/v/1/290525/f/3116640.html',
30 'description': '我是歌手第四季双年巅峰会',
32 'thumbnail': r
're:^https?://.*\.jpg$',
35 'url': 'http://www.mgtv.com/b/301817/3826653.html',
36 'only_matching': True,
39 def _real_extract(self
, url
):
40 video_id
= self
._match
_id
(url
)
42 api_data
= self
._download
_json
(
43 'https://pcweb.api.mgtv.com/player/video', video_id
, query
={
44 'tk2': base64
.urlsafe_b64encode(b
'did=%s|pno=1030|ver=0.3.0301|clit=%d' % (compat_str(uuid
.uuid4()).encode(), time
.time()))[::-1],
46 }, headers
=self
.geo_verification_headers())['data']
47 except ExtractorError
as e
:
48 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
49 error
= self
._parse
_json
(e
.cause
.read().decode(), None)
50 if error
.get('code') == 40005:
51 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
52 raise ExtractorError(error
['msg'], expected
=True)
54 info
= api_data
['info']
55 title
= info
['title'].strip()
56 stream_data
= self
._download
_json
(
57 'https://pcweb.api.mgtv.com/player/getSource', video_id
, query
={
58 'pm2': api_data
['atc']['pm2'],
60 }, headers
=self
.geo_verification_headers())['data']
61 stream_domain
= stream_data
['stream_domain'][0]
64 for idx
, stream
in enumerate(stream_data
['stream']):
65 stream_path
= stream
.get('url')
68 format_data
= self
._download
_json
(
69 stream_domain
+ stream_path
, video_id
,
70 note
='Download video info for format #%d' % idx
)
71 format_url
= format_data
.get('info')
74 tbr
= int_or_none(stream
.get('filebitrate') or self
._search
_regex
(
75 r
'_(\d+)_mp4/', format_url
, 'tbr', default
=None))
77 'format_id': compat_str(tbr
or idx
),
81 'protocol': 'm3u8_native',
85 'format_note': stream
.get('name'),
87 self
._sort
_formats
(formats
)
93 'description': info
.get('desc'),
94 'duration': int_or_none(info
.get('duration')),
95 'thumbnail': info
.get('thumb'),