]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mgtv.py
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
19 class MGTVIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:w(?:ww)?\.)?mgtv\.com/(v|b)/(?:[^/]+/)*(?P<id>\d+)\.html'
24 'url': 'http://www.mgtv.com/v/1/290525/f/3116640.html',
29 'description': '我是歌手第四季双年巅峰会',
31 'thumbnail': r
're:^https?://.*\.jpg$',
34 'url': 'http://www.mgtv.com/b/301817/3826653.html',
35 'only_matching': True,
37 'url': 'https://w.mgtv.com/b/301817/3826653.html',
38 'only_matching': True,
41 def _real_extract(self
, url
):
42 video_id
= self
._match
_id
(url
)
43 tk2
= base64
.urlsafe_b64encode(b
'did=%s|pno=1030|ver=0.3.0301|clit=%d' % (compat_str(uuid
.uuid4()).encode(), time
.time()))[::-1]
45 api_data
= self
._download
_json
(
46 'https://pcweb.api.mgtv.com/player/video', video_id
, query
={
49 }, headers
=self
.geo_verification_headers())['data']
50 except ExtractorError
as e
:
51 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
52 error
= self
._parse
_json
(e
.cause
.read().decode(), None)
53 if error
.get('code') == 40005:
54 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
55 raise ExtractorError(error
['msg'], expected
=True)
57 info
= api_data
['info']
58 title
= info
['title'].strip()
59 stream_data
= self
._download
_json
(
60 'https://pcweb.api.mgtv.com/player/getSource', video_id
, query
={
61 'pm2': api_data
['atc']['pm2'],
64 }, headers
=self
.geo_verification_headers())['data']
65 stream_domain
= stream_data
['stream_domain'][0]
68 for idx
, stream
in enumerate(stream_data
['stream']):
69 stream_path
= stream
.get('url')
72 format_data
= self
._download
_json
(
73 stream_domain
+ stream_path
, video_id
,
74 note
='Download video info for format #%d' % idx
)
75 format_url
= format_data
.get('info')
78 tbr
= int_or_none(stream
.get('filebitrate') or self
._search
_regex
(
79 r
'_(\d+)_mp4/', format_url
, 'tbr', default
=None))
81 'format_id': compat_str(tbr
or idx
),
85 'protocol': 'm3u8_native',
89 'format_note': stream
.get('name'),
91 self
._sort
_formats
(formats
)
97 'description': info
.get('desc'),
98 'duration': int_or_none(info
.get('duration')),
99 'thumbnail': info
.get('thumb'),