]>
Commit | Line | Data |
---|---|---|
846d8b76 RA |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
ce7ccb1c S |
4 | from ..compat import compat_str |
5 | from ..utils import ( | |
6 | float_or_none, | |
7 | try_get, | |
8 | unified_timestamp, | |
9 | ) | |
846d8b76 RA |
10 | |
11 | ||
12 | class CCTVIE(InfoExtractor): | |
ce7ccb1c | 13 | IE_DESC = '央视网' |
1911d77d | 14 | _VALID_URL = r'https?://(?:(?:[^/]+)\.(?:cntv|cctv)\.(?:com|cn)|(?:www\.)?ncpa-classic\.com)/(?:[^/]+/)*?(?P<id>[^/?#&]+?)(?:/index)?(?:\.s?html|[?#&]|$)' |
846d8b76 | 15 | _TESTS = [{ |
1911d77d | 16 | # fo.addVariable("videoCenterId","id") |
ce7ccb1c S |
17 | 'url': 'http://sports.cntv.cn/2016/02/12/ARTIaBRxv4rTT1yWf1frW2wi160212.shtml', |
18 | 'md5': 'd61ec00a493e09da810bf406a078f691', | |
846d8b76 | 19 | 'info_dict': { |
ce7ccb1c | 20 | 'id': '5ecdbeab623f4973b40ff25f18b174e8', |
846d8b76 | 21 | 'ext': 'mp4', |
ce7ccb1c S |
22 | 'title': '[NBA]二少联手砍下46分 雷霆主场击败鹈鹕(快讯)', |
23 | 'description': 'md5:7e14a5328dc5eb3d1cd6afbbe0574e95', | |
24 | 'duration': 98, | |
25 | 'uploader': 'songjunjie', | |
26 | 'timestamp': 1455279956, | |
27 | 'upload_date': '20160212', | |
28 | }, | |
29 | }, { | |
1911d77d | 30 | # var guid = "id" |
ce7ccb1c S |
31 | 'url': 'http://tv.cctv.com/2016/02/05/VIDEUS7apq3lKrHG9Dncm03B160205.shtml', |
32 | 'info_dict': { | |
33 | 'id': 'efc5d49e5b3b4ab2b34f3a502b73d3ae', | |
34 | 'ext': 'mp4', | |
35 | 'title': '[赛车]“车王”舒马赫恢复情况成谜(快讯)', | |
36 | 'description': '2月4日,蒙特泽莫罗透露了关于“车王”舒马赫恢复情况,但情况是否属实遭到了质疑。', | |
37 | 'duration': 37, | |
38 | 'uploader': 'shujun', | |
39 | 'timestamp': 1454677291, | |
40 | 'upload_date': '20160205', | |
41 | }, | |
42 | 'params': { | |
43 | 'skip_download': True, | |
44 | }, | |
45 | }, { | |
1911d77d | 46 | # changePlayer('id') |
ce7ccb1c S |
47 | 'url': 'http://english.cntv.cn/special/four_comprehensives/index.shtml', |
48 | 'info_dict': { | |
49 | 'id': '4bb9bb4db7a6471ba85fdeda5af0381e', | |
50 | 'ext': 'mp4', | |
51 | 'title': 'NHnews008 ANNUAL POLITICAL SEASON', | |
52 | 'description': 'Four Comprehensives', | |
53 | 'duration': 60, | |
54 | 'uploader': 'zhangyunlei', | |
55 | 'timestamp': 1425385521, | |
56 | 'upload_date': '20150303', | |
57 | }, | |
58 | 'params': { | |
59 | 'skip_download': True, | |
60 | }, | |
61 | }, { | |
1911d77d | 62 | # loadvideo('id') |
ce7ccb1c S |
63 | 'url': 'http://cctv.cntv.cn/lm/tvseries_russian/yilugesanghua/index.shtml', |
64 | 'info_dict': { | |
65 | 'id': 'b15f009ff45c43968b9af583fc2e04b2', | |
66 | 'ext': 'mp4', | |
67 | 'title': 'Путь,усыпанный космеями Серия 1', | |
68 | 'description': 'Путь, усыпанный космеями', | |
69 | 'duration': 2645, | |
70 | 'uploader': 'renxue', | |
71 | 'timestamp': 1477479241, | |
72 | 'upload_date': '20161026', | |
73 | }, | |
74 | 'params': { | |
75 | 'skip_download': True, | |
76 | }, | |
1911d77d S |
77 | }, { |
78 | # var initMyAray = 'id' | |
79 | 'url': 'http://www.ncpa-classic.com/2013/05/22/VIDE1369219508996867.shtml', | |
80 | 'info_dict': { | |
81 | 'id': 'a194cfa7f18c426b823d876668325946', | |
82 | 'ext': 'mp4', | |
83 | 'title': '小泽征尔音乐塾 音乐梦想无国界', | |
84 | 'duration': 2173, | |
85 | 'timestamp': 1369248264, | |
86 | 'upload_date': '20130522', | |
87 | }, | |
88 | 'params': { | |
89 | 'skip_download': True, | |
90 | }, | |
6ad11fef | 91 | }, { |
92 | # videoCenterId: "id" | |
93 | 'url': 'http://news.cctv.com/2024/02/21/ARTIcU5tKIOIF2myEGCATkLo240221.shtml', | |
94 | 'info_dict': { | |
95 | 'id': '5c846c0518444308ba32c4159df3b3e0', | |
96 | 'ext': 'mp4', | |
97 | 'title': '《平“语”近人——习近平喜欢的典故》第三季 第5集:风物长宜放眼量', | |
98 | 'uploader': 'yangjuan', | |
99 | 'timestamp': 1708554940, | |
100 | 'upload_date': '20240221', | |
101 | }, | |
102 | 'params': { | |
103 | 'skip_download': True, | |
104 | }, | |
1911d77d S |
105 | }, { |
106 | # var ids = ["id"] | |
107 | 'url': 'http://www.ncpa-classic.com/clt/more/416/index.shtml', | |
108 | 'info_dict': { | |
109 | 'id': 'a8606119a4884588a79d81c02abecc16', | |
110 | 'ext': 'mp3', | |
111 | 'title': '来自维也纳的新年贺礼', | |
112 | 'description': 'md5:f13764ae8dd484e84dd4b39d5bcba2a7', | |
113 | 'duration': 1578, | |
114 | 'uploader': 'djy', | |
115 | 'timestamp': 1482942419, | |
116 | 'upload_date': '20161228', | |
117 | }, | |
118 | 'params': { | |
119 | 'skip_download': True, | |
120 | }, | |
121 | 'expected_warnings': ['Failed to download m3u8 information'], | |
ce7ccb1c S |
122 | }, { |
123 | 'url': 'http://ent.cntv.cn/2016/01/18/ARTIjprSSJH8DryTVr5Bx8Wb160118.shtml', | |
124 | 'only_matching': True, | |
125 | }, { | |
126 | 'url': 'http://tv.cntv.cn/video/C39296/e0210d949f113ddfb38d31f00a4e5c44', | |
127 | 'only_matching': True, | |
128 | }, { | |
129 | 'url': 'http://english.cntv.cn/2016/09/03/VIDEhnkB5y9AgHyIEVphCEz1160903.shtml', | |
130 | 'only_matching': True, | |
846d8b76 RA |
131 | }, { |
132 | 'url': 'http://tv.cctv.com/2016/09/07/VIDE5C1FnlX5bUywlrjhxXOV160907.shtml', | |
133 | 'only_matching': True, | |
134 | }, { | |
135 | 'url': 'http://tv.cntv.cn/video/C39296/95cfac44cabd3ddc4a9438780a4e5c44', | |
1911d77d | 136 | 'only_matching': True, |
846d8b76 RA |
137 | }] |
138 | ||
139 | def _real_extract(self, url): | |
ce7ccb1c S |
140 | video_id = self._match_id(url) |
141 | webpage = self._download_webpage(url, video_id) | |
142 | ||
143 | video_id = self._search_regex( | |
144 | [r'var\s+guid\s*=\s*["\']([\da-fA-F]+)', | |
6ad11fef | 145 | r'videoCenterId(?:["\']\s*,|:)\s*["\']([\da-fA-F]+)', |
7a9e0669 | 146 | r'changePlayer\s*\(\s*["\']([\da-fA-F]+)', |
1911d77d S |
147 | r'load[Vv]ideo\s*\(\s*["\']([\da-fA-F]+)', |
148 | r'var\s+initMyAray\s*=\s*["\']([\da-fA-F]+)', | |
149 | r'var\s+ids\s*=\s*\[["\']([\da-fA-F]+)'], | |
327caf66 | 150 | webpage, 'video id') |
ce7ccb1c S |
151 | |
152 | data = self._download_json( | |
153 | 'http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do', video_id, | |
154 | query={ | |
155 | 'pid': video_id, | |
156 | 'url': url, | |
157 | 'idl': 32, | |
158 | 'idlr': 32, | |
159 | 'modifyed': 'false', | |
160 | }) | |
161 | ||
162 | title = data['title'] | |
163 | ||
164 | formats = [] | |
165 | ||
166 | video = data.get('video') | |
167 | if isinstance(video, dict): | |
168 | for quality, chapters_key in enumerate(('lowChapters', 'chapters')): | |
169 | video_url = try_get( | |
170 | video, lambda x: x[chapters_key][0]['url'], compat_str) | |
171 | if video_url: | |
172 | formats.append({ | |
173 | 'url': video_url, | |
174 | 'format_id': 'http', | |
175 | 'quality': quality, | |
35cd4c4d | 176 | # Sample clip |
177 | 'preference': -10 | |
ce7ccb1c S |
178 | }) |
179 | ||
180 | hls_url = try_get(data, lambda x: x['hls_url'], compat_str) | |
181 | if hls_url: | |
182 | hls_url = re.sub(r'maxbr=\d+&?', '', hls_url) | |
183 | formats.extend(self._extract_m3u8_formats( | |
184 | hls_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
185 | m3u8_id='hls', fatal=False)) | |
186 | ||
ce7ccb1c | 187 | uploader = data.get('editer_name') |
1911d77d S |
188 | description = self._html_search_meta( |
189 | 'description', webpage, default=None) | |
ce7ccb1c S |
190 | timestamp = unified_timestamp(data.get('f_pgmtime')) |
191 | duration = float_or_none(try_get(video, lambda x: x['totalLength'])) | |
846d8b76 RA |
192 | |
193 | return { | |
194 | 'id': video_id, | |
ce7ccb1c S |
195 | 'title': title, |
196 | 'description': description, | |
197 | 'uploader': uploader, | |
198 | 'timestamp': timestamp, | |
199 | 'duration': duration, | |
200 | 'formats': formats, | |
846d8b76 | 201 | } |