[ie/youtube] Add age-gate workaround for some embeddable videos (#11821)
[yt-dlp.git] / yt_dlp / extractor / xinpianchang.py
blob23ed9270da511715b6c2cc417846ef8ddb880c54
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 str_or_none,
5 try_get,
6 url_or_none,
10 class XinpianchangIE(InfoExtractor):
11 _VALID_URL = r'https?://(www\.)?xinpianchang\.com/(?P<id>a\d+)'
12 IE_DESC = '新片场'
13 _TESTS = [{
14 'url': 'https://www.xinpianchang.com/a11766551',
15 'info_dict': {
16 'id': 'a11766551',
17 'ext': 'mp4',
18 'title': '北京2022冬奥会闭幕式再见短片-冰墩墩下班了',
19 'description': 'md5:4a730c10639a82190fabe921c0fa4b87',
20 'duration': 151,
21 'thumbnail': r're:^https?://oss-xpc0\.xpccdn\.com.+/assets/',
22 'uploader': '正时文创',
23 'uploader_id': '10357277',
24 'categories': ['宣传片', '国家城市', '广告', '其他'],
25 'tags': ['北京冬奥会', '冰墩墩', '再见', '告别', '冰墩墩哭了', '感动', '闭幕式', '熄火'],
27 }, {
28 'url': 'https://www.xinpianchang.com/a11762904',
29 'info_dict': {
30 'id': 'a11762904',
31 'ext': 'mp4',
32 'title': '冬奥会决胜时刻《法国派出三只鸡?》',
33 'description': 'md5:55cb139ef8f48f0c877932d1f196df8b',
34 'duration': 136,
35 'thumbnail': r're:^https?://oss-xpc0\.xpccdn\.com.+/assets/',
36 'uploader': '精品动画',
37 'uploader_id': '10858927',
38 'categories': ['动画', '三维CG'],
39 'tags': ['France Télévisions', '法国3台', '蠢萌', '冬奥会'],
41 }, {
42 'url': 'https://www.xinpianchang.com/a11779743?from=IndexPick&part=%E7%BC%96%E8%BE%91%E7%B2%BE%E9%80%89&index=2',
43 'only_matching': True,
46 def _real_extract(self, url):
47 video_id = self._match_id(url)
48 webpage = self._download_webpage(url, video_id=video_id)
49 video_data = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['detail']['video']
51 data = self._download_json(
52 f'https://mod-api.xinpianchang.com/mod/api/v2/media/{video_data["vid"]}', video_id,
53 query={'appKey': video_data['appKey']})['data']
54 formats, subtitles = [], {}
55 for k, v in data.get('resource').items():
56 if k in ('dash', 'hls'):
57 v_url = v.get('url')
58 if not v_url:
59 continue
60 if k == 'dash':
61 fmts, subs = self._extract_mpd_formats_and_subtitles(v_url, video_id=video_id)
62 elif k == 'hls':
63 fmts, subs = self._extract_m3u8_formats_and_subtitles(v_url, video_id=video_id)
64 formats.extend(fmts)
65 subtitles = self._merge_subtitles(subtitles, subs)
66 elif k == 'progressive':
67 formats.extend([{
68 'url': url_or_none(prog.get('url')),
69 'width': int_or_none(prog.get('width')),
70 'height': int_or_none(prog.get('height')),
71 'ext': 'mp4',
72 'http_headers': {
73 # NB: Server returns 403 without the Range header
74 'Range': 'bytes=0-',
76 } for prog in v if prog.get('url') or []])
78 return {
79 'id': video_id,
80 'title': data.get('title'),
81 'description': data.get('description'),
82 'duration': int_or_none(data.get('duration')),
83 'categories': data.get('categories'),
84 'tags': data.get('keywords'),
85 'thumbnail': data.get('cover'),
86 'uploader': try_get(data, lambda x: x['owner']['username']),
87 'uploader_id': str_or_none(try_get(data, lambda x: x['owner']['id'])),
88 'formats': formats,
89 'subtitles': subtitles,