]>
Commit | Line | Data |
---|---|---|
206dba27 | 1 | from .common import InfoExtractor |
7c20b748 | 2 | from ..compat import compat_urlparse |
bc35ed3f YCH |
3 | from ..utils import ( |
4 | clean_html, | |
5 | get_element_by_class, | |
6 | int_or_none, | |
7 | parse_iso8601, | |
8 | remove_start, | |
9 | unified_timestamp, | |
10 | ) | |
206dba27 YCH |
11 | |
12 | ||
13 | class NextMediaIE(InfoExtractor): | |
9d16788a | 14 | IE_DESC = '蘋果日報' |
92519402 | 15 | _VALID_URL = r'https?://hk\.apple\.nextmedia\.com/[^/]+/[^/]+/(?P<date>\d+)/(?P<id>\d+)' |
206dba27 YCH |
16 | _TESTS = [{ |
17 | 'url': 'http://hk.apple.nextmedia.com/realtime/news/20141108/53109199', | |
18 | 'md5': 'dff9fad7009311c421176d1ac90bfe4f', | |
19 | 'info_dict': { | |
20 | 'id': '53109199', | |
21 | 'ext': 'mp4', | |
22 | 'title': '【佔領金鐘】50外國領事議員撐場 讚學生勇敢香港有希望', | |
ec85ded8 | 23 | 'thumbnail': r're:^https?://.*\.jpg$', |
206dba27 YCH |
24 | 'description': 'md5:28222b9912b6665a21011b034c70fcc7', |
25 | 'timestamp': 1415456273, | |
26 | 'upload_date': '20141108', | |
27 | } | |
28 | }] | |
29 | ||
30 | _URL_PATTERN = r'\{ url: \'(.+)\' \}' | |
31 | ||
32 | def _real_extract(self, url): | |
33 | news_id = self._match_id(url) | |
34 | page = self._download_webpage(url, news_id) | |
35 | return self._extract_from_nextmedia_page(news_id, url, page) | |
36 | ||
37 | def _extract_from_nextmedia_page(self, news_id, url, page): | |
7c20b748 YCH |
38 | redirection_url = self._search_regex( |
39 | r'window\.location\.href\s*=\s*([\'"])(?P<url>(?!\1).+)\1', | |
40 | page, 'redirection URL', default=None, group='url') | |
41 | if redirection_url: | |
42 | return self.url_result(compat_urlparse.urljoin(url, redirection_url)) | |
43 | ||
206dba27 YCH |
44 | title = self._fetch_title(page) |
45 | video_url = self._search_regex(self._URL_PATTERN, page, 'video url') | |
46 | ||
47 | attrs = { | |
48 | 'id': news_id, | |
49 | 'title': title, | |
50 | 'url': video_url, # ext can be inferred from url | |
51 | 'thumbnail': self._fetch_thumbnail(page), | |
52 | 'description': self._fetch_description(page), | |
53 | } | |
54 | ||
55 | timestamp = self._fetch_timestamp(page) | |
56 | if timestamp: | |
57 | attrs['timestamp'] = timestamp | |
58 | else: | |
59 | attrs['upload_date'] = self._fetch_upload_date(url) | |
60 | ||
61 | return attrs | |
62 | ||
63 | def _fetch_title(self, page): | |
64 | return self._og_search_title(page) | |
65 | ||
66 | def _fetch_thumbnail(self, page): | |
67 | return self._og_search_thumbnail(page) | |
68 | ||
69 | def _fetch_timestamp(self, page): | |
70 | dateCreated = self._search_regex('"dateCreated":"([^"]+)"', page, 'created time') | |
71 | return parse_iso8601(dateCreated) | |
72 | ||
73 | def _fetch_upload_date(self, url): | |
74 | return self._search_regex(self._VALID_URL, url, 'upload date', group='date') | |
75 | ||
76 | def _fetch_description(self, page): | |
77 | return self._og_search_property('description', page) | |
78 | ||
79 | ||
80 | class NextMediaActionNewsIE(NextMediaIE): | |
9d16788a | 81 | IE_DESC = '蘋果日報 - 動新聞' |
92519402 | 82 | _VALID_URL = r'https?://hk\.dv\.nextmedia\.com/actionnews/[^/]+/(?P<date>\d+)/(?P<id>\d+)/\d+' |
206dba27 YCH |
83 | _TESTS = [{ |
84 | 'url': 'http://hk.dv.nextmedia.com/actionnews/hit/20150121/19009428/20061460', | |
85 | 'md5': '05fce8ffeed7a5e00665d4b7cf0f9201', | |
86 | 'info_dict': { | |
87 | 'id': '19009428', | |
88 | 'ext': 'mp4', | |
89 | 'title': '【壹週刊】細10年男友偷食 50歲邵美琪再失戀', | |
ec85ded8 | 90 | 'thumbnail': r're:^https?://.*\.jpg$', |
206dba27 YCH |
91 | 'description': 'md5:cd802fad1f40fd9ea178c1e2af02d659', |
92 | 'timestamp': 1421791200, | |
93 | 'upload_date': '20150120', | |
94 | } | |
95 | }] | |
96 | ||
97 | def _real_extract(self, url): | |
98 | news_id = self._match_id(url) | |
99 | actionnews_page = self._download_webpage(url, news_id) | |
100 | article_url = self._og_search_url(actionnews_page) | |
101 | article_page = self._download_webpage(article_url, news_id) | |
102 | return self._extract_from_nextmedia_page(news_id, url, article_page) | |
103 | ||
104 | ||
9bf87ae3 | 105 | class AppleDailyIE(NextMediaIE): |
9d16788a | 106 | IE_DESC = '臺灣蘋果日報' |
7c20b748 | 107 | _VALID_URL = r'https?://(www|ent)\.appledaily\.com\.tw/[^/]+/[^/]+/[^/]+/(?P<date>\d+)/(?P<id>\d+)(/.*)?' |
206dba27 YCH |
108 | _TESTS = [{ |
109 | 'url': 'http://ent.appledaily.com.tw/enews/article/entertainment/20150128/36354694', | |
110 | 'md5': 'a843ab23d150977cc55ef94f1e2c1e4d', | |
111 | 'info_dict': { | |
112 | 'id': '36354694', | |
113 | 'ext': 'mp4', | |
114 | 'title': '周亭羽走過摩鐵陰霾2男陪吃 九把刀孤寒看醫生', | |
ec85ded8 | 115 | 'thumbnail': r're:^https?://.*\.jpg$', |
9bf87ae3 | 116 | 'description': 'md5:2acd430e59956dc47cd7f67cb3c003f4', |
206dba27 YCH |
117 | 'upload_date': '20150128', |
118 | } | |
119 | }, { | |
120 | 'url': 'http://www.appledaily.com.tw/realtimenews/article/strange/20150128/550549/%E4%B8%8D%E6%BB%BF%E8%A2%AB%E8%B8%A9%E8%85%B3%E3%80%80%E5%B1%B1%E6%9D%B1%E5%85%A9%E5%A4%A7%E5%AA%BD%E4%B8%80%E8%B7%AF%E6%89%93%E4%B8%8B%E8%BB%8A', | |
121 | 'md5': '86b4e9132d158279c7883822d94ccc49', | |
122 | 'info_dict': { | |
123 | 'id': '550549', | |
124 | 'ext': 'mp4', | |
125 | 'title': '不滿被踩腳 山東兩大媽一路打下車', | |
ec85ded8 | 126 | 'thumbnail': r're:^https?://.*\.jpg$', |
9bf87ae3 | 127 | 'description': 'md5:175b4260c1d7c085993474217e4ab1b4', |
206dba27 YCH |
128 | 'upload_date': '20150128', |
129 | } | |
9bf87ae3 | 130 | }, { |
206dba27 YCH |
131 | 'url': 'http://www.appledaily.com.tw/animation/realtimenews/new/20150128/5003671', |
132 | 'md5': '03df296d95dedc2d5886debbb80cb43f', | |
133 | 'info_dict': { | |
134 | 'id': '5003671', | |
135 | 'ext': 'mp4', | |
136 | 'title': '20正妹熱舞 《刀龍傳說Online》火辣上市', | |
ec85ded8 | 137 | 'thumbnail': r're:^https?://.*\.jpg$', |
206dba27 YCH |
138 | 'description': 'md5:23c0aac567dc08c9c16a3161a2c2e3cd', |
139 | 'upload_date': '20150128', | |
1f9fb20f | 140 | }, |
141 | 'skip': 'redirect to http://www.appledaily.com.tw/animation/', | |
206dba27 YCH |
142 | }, { |
143 | # No thumbnail | |
144 | 'url': 'http://www.appledaily.com.tw/animation/realtimenews/new/20150128/5003673/', | |
145 | 'md5': 'b06182cd386ea7bc6115ec7ff0f72aeb', | |
146 | 'info_dict': { | |
147 | 'id': '5003673', | |
148 | 'ext': 'mp4', | |
149 | 'title': '半夜尿尿 好像會看到___', | |
150 | 'description': 'md5:61d2da7fe117fede148706cdb85ac066', | |
151 | 'upload_date': '20150128', | |
152 | }, | |
153 | 'expected_warnings': [ | |
154 | 'video thumbnail', | |
1f9fb20f | 155 | ], |
156 | 'skip': 'redirect to http://www.appledaily.com.tw/animation/', | |
30455ce2 YCH |
157 | }, { |
158 | 'url': 'http://www.appledaily.com.tw/appledaily/article/supplement/20140417/35770334/', | |
1f9fb20f | 159 | 'md5': 'eaa20e6b9df418c912d7f5dec2ba734d', |
160 | 'info_dict': { | |
161 | 'id': '35770334', | |
162 | 'ext': 'mp4', | |
163 | 'title': '咖啡占卜測 XU裝熟指數', | |
ec85ded8 | 164 | 'thumbnail': r're:^https?://.*\.jpg$', |
1f9fb20f | 165 | 'description': 'md5:7b859991a6a4fedbdf3dd3b66545c748', |
166 | 'upload_date': '20140417', | |
167 | }, | |
b0082629 YCH |
168 | }, { |
169 | 'url': 'http://www.appledaily.com.tw/actionnews/appledaily/7/20161003/960588/', | |
170 | 'only_matching': True, | |
7c20b748 YCH |
171 | }, { |
172 | # Redirected from http://ent.appledaily.com.tw/enews/article/entertainment/20150128/36354694 | |
173 | 'url': 'http://ent.appledaily.com.tw/section/article/headline/20150128/36354694', | |
174 | 'only_matching': True, | |
206dba27 YCH |
175 | }] |
176 | ||
9bf87ae3 YCH |
177 | _URL_PATTERN = r'\{url: \'(.+)\'\}' |
178 | ||
206dba27 | 179 | def _fetch_title(self, page): |
3089bc74 S |
180 | return (self._html_search_regex(r'<h1 id="h1">([^<>]+)</h1>', page, 'news title', default=None) |
181 | or self._html_search_meta('description', page, 'news title')) | |
9bf87ae3 YCH |
182 | |
183 | def _fetch_thumbnail(self, page): | |
184 | return self._html_search_regex(r"setInitialImage\(\'([^']+)'\)", page, 'video thumbnail', fatal=False) | |
185 | ||
186 | def _fetch_timestamp(self, page): | |
187 | return None | |
206dba27 YCH |
188 | |
189 | def _fetch_description(self, page): | |
190 | return self._html_search_meta('description', page, 'news description') | |
bc35ed3f YCH |
191 | |
192 | ||
193 | class NextTVIE(InfoExtractor): | |
194 | IE_DESC = '壹電視' | |
195 | _VALID_URL = r'https?://(?:www\.)?nexttv\.com\.tw/(?:[^/]+/)+(?P<id>\d+)' | |
196 | ||
197 | _TEST = { | |
198 | 'url': 'http://www.nexttv.com.tw/news/realtime/politics/11779671', | |
199 | 'info_dict': { | |
200 | 'id': '11779671', | |
201 | 'ext': 'mp4', | |
202 | 'title': '「超收稅」近4千億! 藍議員籲發消費券', | |
203 | 'thumbnail': r're:^https?://.*\.jpg$', | |
204 | 'timestamp': 1484825400, | |
205 | 'upload_date': '20170119', | |
206 | 'view_count': int, | |
207 | }, | |
208 | } | |
209 | ||
210 | def _real_extract(self, url): | |
211 | video_id = self._match_id(url) | |
212 | ||
213 | webpage = self._download_webpage(url, video_id) | |
214 | ||
215 | title = self._html_search_regex( | |
216 | r'<h1[^>]*>([^<]+)</h1>', webpage, 'title') | |
217 | ||
218 | data = self._hidden_inputs(webpage) | |
219 | ||
220 | video_url = data['ntt-vod-src-detailview'] | |
221 | ||
222 | date_str = get_element_by_class('date', webpage) | |
223 | timestamp = unified_timestamp(date_str + '+0800') if date_str else None | |
224 | ||
225 | view_count = int_or_none(remove_start( | |
226 | clean_html(get_element_by_class('click', webpage)), '點閱:')) | |
227 | ||
228 | return { | |
229 | 'id': video_id, | |
230 | 'title': title, | |
231 | 'url': video_url, | |
232 | 'thumbnail': data.get('ntt-vod-img-src'), | |
233 | 'timestamp': timestamp, | |
234 | 'view_count': view_count, | |
235 | } |