]>
Commit | Line | Data |
---|---|---|
c89bec26 HTL |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | int_or_none, | |
4 | try_get, | |
5 | update_url_query, | |
6 | url_or_none, | |
7 | ) | |
8 | ||
9 | ||
10 | class XinpianchangIE(InfoExtractor): | |
11 | _VALID_URL = r'https?://www\.xinpianchang\.com/(?P<id>[^/]+?)(?:\D|$)' | |
12 | IE_NAME = 'xinpianchang' | |
13 | IE_DESC = 'xinpianchang.com' | |
14 | _TESTS = [{ | |
15 | 'url': 'https://www.xinpianchang.com/a11766551', | |
16 | 'info_dict': { | |
17 | 'id': 'a11766551', | |
18 | 'ext': 'mp4', | |
19 | 'title': '北京2022冬奥会闭幕式再见短片-冰墩墩下班了', | |
20 | 'description': 'md5:4a730c10639a82190fabe921c0fa4b87', | |
21 | 'duration': 151, | |
22 | 'thumbnail': r're:^https?://oss-xpc0\.xpccdn\.com.+/assets/', | |
23 | 'uploader': '正时文创', | |
24 | 'uploader_id': 10357277, | |
25 | 'categories': ['宣传片', '国家城市', '广告', '其他'], | |
26 | 'keywords': ['北京冬奥会', '冰墩墩', '再见', '告别', '冰墩墩哭了', '感动', '闭幕式', '熄火'] | |
27 | }, | |
28 | }, { | |
29 | 'url': 'https://www.xinpianchang.com/a11762904', | |
30 | 'info_dict': { | |
31 | 'id': 'a11762904', | |
32 | 'ext': 'mp4', | |
33 | 'title': '冬奥会决胜时刻《法国派出三只鸡?》', | |
34 | 'description': 'md5:55cb139ef8f48f0c877932d1f196df8b', | |
35 | 'duration': 136, | |
36 | 'thumbnail': r're:^https?://oss-xpc0\.xpccdn\.com.+/assets/', | |
37 | 'uploader': '精品动画', | |
38 | 'uploader_id': 10858927, | |
39 | 'categories': ['动画', '三维CG'], | |
40 | 'keywords': ['France Télévisions', '法国3台', '蠢萌', '冬奥会'] | |
41 | }, | |
42 | }, { | |
43 | 'url': 'https://www.xinpianchang.com/a11779743?from=IndexPick&part=%E7%BC%96%E8%BE%91%E7%B2%BE%E9%80%89&index=2', | |
44 | 'only_matching': True, | |
45 | }] | |
46 | ||
47 | def _real_extract(self, url): | |
48 | video_id = self._match_id(url) | |
49 | webpage = self._download_webpage(url, video_id=video_id) | |
50 | domain = self.find_value_with_regex(var='requireNewDomain', webpage=webpage) | |
51 | vid = self.find_value_with_regex(var='vid', webpage=webpage) | |
52 | app_key = self.find_value_with_regex(var='modeServerAppKey', webpage=webpage) | |
53 | api = update_url_query(f'{domain}/mod/api/v2/media/{vid}', {'appKey': app_key}) | |
54 | data = self._download_json(api, video_id=video_id)['data'] | |
55 | formats, subtitles = [], {} | |
56 | for k, v in data.get('resource').items(): | |
57 | if k in ('dash', 'hls'): | |
58 | v_url = v.get('url') | |
59 | if not v_url: | |
60 | continue | |
61 | if k == 'dash': | |
62 | fmts, subs = self._extract_mpd_formats_and_subtitles(v_url, video_id=video_id) | |
63 | elif k == 'hls': | |
64 | fmts, subs = self._extract_m3u8_formats_and_subtitles(v_url, video_id=video_id) | |
65 | formats.extend(fmts) | |
66 | subtitles = self._merge_subtitles(subtitles, subs) | |
67 | elif k == 'progressive': | |
68 | formats.extend([{ | |
69 | 'url': url_or_none(prog.get('url')), | |
70 | 'width': int_or_none(prog.get('width')), | |
71 | 'height': int_or_none(prog.get('height')), | |
72 | 'ext': 'mp4', | |
73 | } for prog in v if prog.get('url') or []]) | |
74 | ||
c89bec26 HTL |
75 | return { |
76 | 'id': video_id, | |
77 | 'title': data.get('title'), | |
78 | 'description': data.get('description'), | |
79 | 'duration': int_or_none(data.get('duration')), | |
80 | 'categories': data.get('categories'), | |
81 | 'keywords': data.get('keywords'), | |
82 | 'thumbnail': data.get('cover'), | |
83 | 'uploader': try_get(data, lambda x: x['owner']['username']), | |
84 | 'uploader_id': try_get(data, lambda x: x['owner']['id']), | |
85 | 'formats': formats, | |
86 | 'subtitles': subtitles, | |
87 | } | |
88 | ||
89 | def find_value_with_regex(self, var, webpage): | |
90 | return self._search_regex(rf'var\s{var}\s=\s\"(?P<vid>[^\"]+)\"', webpage, name=var) |