]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mgtv.py
5 from .common
import InfoExtractor
18 class MGTVIE(InfoExtractor
):
19 _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': 'https://w.mgtv.com/b/427837/15588271.html',
38 'title': '春日迟迟再出发 沉浸版',
39 'description': 'md5:a7a05a05b1aa87bd50cae619b19bbca6',
40 'thumbnail': r
're:^https?://.+\.jpg',
44 'url': 'https://w.mgtv.com/b/333652/7329822.html',
49 'description': 'md5:cd81be6499bafe32e4d143abd822bf9c',
50 'thumbnail': r
're:^https?://.+\.jpg',
54 'url': 'https://w.mgtv.com/b/427837/15591647.html',
55 'only_matching': True,
57 'url': 'https://w.mgtv.com/b/388252/15634192.html?fpa=33318&fpos=4&lastp=ch_home',
58 'only_matching': True,
60 'url': 'http://www.mgtv.com/b/301817/3826653.html',
61 'only_matching': True,
63 'url': 'https://w.mgtv.com/b/301817/3826653.html',
64 'only_matching': True,
67 def _real_extract(self
, url
):
68 video_id
= self
._match
_id
(url
)
69 tk2
= base64
.urlsafe_b64encode(
70 f
'did={compat_str(uuid.uuid4()).encode()}|pno=1030|ver=0.3.0301|clit={int(time.time())}'.encode())[::-1]
72 api_data
= self
._download
_json
(
73 'https://pcweb.api.mgtv.com/player/video', video_id
, query
={
77 }, headers
=self
.geo_verification_headers())['data']
78 except ExtractorError
as e
:
79 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
80 error
= self
._parse
_json
(e
.cause
.read().decode(), None)
81 if error
.get('code') == 40005:
82 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
83 raise ExtractorError(error
['msg'], expected
=True)
85 info
= api_data
['info']
86 title
= info
['title'].strip()
87 stream_data
= self
._download
_json
(
88 'https://pcweb.api.mgtv.com/player/getSource', video_id
, query
={
89 'pm2': api_data
['atc']['pm2'],
93 }, headers
=self
.geo_verification_headers())['data']
94 stream_domain
= stream_data
['stream_domain'][0]
97 for idx
, stream
in enumerate(stream_data
['stream']):
98 stream_path
= stream
.get('url')
101 format_data
= self
._download
_json
(
102 stream_domain
+ stream_path
, video_id
,
103 note
=f
'Download video info for format #{idx}')
104 format_url
= format_data
.get('info')
107 tbr
= int_or_none(stream
.get('filebitrate') or self
._search
_regex
(
108 r
'_(\d+)_mp4/', format_url
, 'tbr', default
=None))
110 'format_id': compat_str(tbr
or idx
),
111 'url': url_or_none(format_url
),
114 'protocol': 'm3u8_native',
118 'format_note': stream
.get('name'),
120 self
._sort
_formats
(formats
)
126 'description': info
.get('desc'),
127 'duration': int_or_none(info
.get('duration')),
128 'thumbnail': info
.get('thumb'),
129 'subtitles': self
.extract_subtitles(video_id
, stream_domain
),
132 def _get_subtitles(self
, video_id
, domain
):
133 info
= self
._download
_json
(f
'https://pcweb.api.mgtv.com/video/title?videoId={video_id}',
134 video_id
, fatal
=False) or {}
136 for sub
in try_get(info
, lambda x
: x
['data']['title']) or []:
137 url_sub
= sub
.get('url')
140 locale
= sub
.get('captionCountrySimpleName')
141 sub
= self
._download
_json
(f
'{domain}{url_sub}', video_id
, fatal
=False,
142 note
=f
'Download subtitle for locale {sub.get("name")} ({locale})') or {}
143 sub_url
= url_or_none(sub
.get('info'))
146 subtitles
.setdefault(locale
or 'en', []).append({