]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import json | |
5 | import re | |
6 | ||
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
9 | determine_ext, | |
10 | float_or_none, | |
11 | int_or_none, | |
12 | parse_iso8601, | |
13 | strip_or_none, | |
14 | ) | |
15 | ||
16 | ||
17 | class ToggleIE(InfoExtractor): | |
18 | IE_NAME = 'toggle' | |
19 | _VALID_URL = r'(?:https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:en|zh)/(?:[^/]+/){2,}|toggle:)(?P<id>[0-9]+)' | |
20 | _TESTS = [{ | |
21 | 'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115', | |
22 | 'info_dict': { | |
23 | 'id': '343115', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'Lion Moms Premiere', | |
26 | 'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b', | |
27 | 'upload_date': '20150910', | |
28 | 'timestamp': 1441858274, | |
29 | }, | |
30 | 'params': { | |
31 | 'skip_download': 'm3u8 download', | |
32 | } | |
33 | }, { | |
34 | 'note': 'DRM-protected video', | |
35 | 'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413', | |
36 | 'info_dict': { | |
37 | 'id': '341413', | |
38 | 'ext': 'wvm', | |
39 | 'title': 'Dug\'s Special Mission', | |
40 | 'description': 'md5:e86c6f4458214905c1772398fabc93e0', | |
41 | 'upload_date': '20150827', | |
42 | 'timestamp': 1440644006, | |
43 | }, | |
44 | 'params': { | |
45 | 'skip_download': 'DRM-protected wvm download', | |
46 | } | |
47 | }, { | |
48 | # this also tests correct video id extraction | |
49 | 'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay', | |
50 | 'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861', | |
51 | 'info_dict': { | |
52 | 'id': '332861', | |
53 | 'ext': 'mp4', | |
54 | 'title': '28th SEA Games (5 Show) - Episode 11', | |
55 | 'description': 'md5:3cd4f5f56c7c3b1340c50a863f896faa', | |
56 | 'upload_date': '20150605', | |
57 | 'timestamp': 1433480166, | |
58 | }, | |
59 | 'params': { | |
60 | 'skip_download': 'DRM-protected wvm download', | |
61 | }, | |
62 | 'skip': 'm3u8 links are geo-restricted' | |
63 | }, { | |
64 | 'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331', | |
65 | 'only_matching': True, | |
66 | }, { | |
67 | 'url': 'http://www.mewatch.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331', | |
68 | 'only_matching': True, | |
69 | }, { | |
70 | 'url': 'http://www.mewatch.sg/zh/series/zero-calling-s2-hd/ep13/336367', | |
71 | 'only_matching': True, | |
72 | }, { | |
73 | 'url': 'http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302', | |
74 | 'only_matching': True, | |
75 | }, { | |
76 | 'url': 'http://www.mewatch.sg/en/movies/seven-days/321936', | |
77 | 'only_matching': True, | |
78 | }, { | |
79 | 'url': 'https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456', | |
80 | 'only_matching': True, | |
81 | }, { | |
82 | 'url': 'http://www.mewatch.sg/en/channels/eleven-plus/401585', | |
83 | 'only_matching': True, | |
84 | }] | |
85 | ||
86 | _API_USER = 'tvpapi_147' | |
87 | _API_PASS = '11111' | |
88 | ||
89 | def _real_extract(self, url): | |
90 | video_id = self._match_id(url) | |
91 | ||
92 | params = { | |
93 | 'initObj': { | |
94 | 'Locale': { | |
95 | 'LocaleLanguage': '', | |
96 | 'LocaleCountry': '', | |
97 | 'LocaleDevice': '', | |
98 | 'LocaleUserState': 0 | |
99 | }, | |
100 | 'Platform': 0, | |
101 | 'SiteGuid': 0, | |
102 | 'DomainID': '0', | |
103 | 'UDID': '', | |
104 | 'ApiUser': self._API_USER, | |
105 | 'ApiPass': self._API_PASS | |
106 | }, | |
107 | 'MediaID': video_id, | |
108 | 'mediaType': 0, | |
109 | } | |
110 | ||
111 | info = self._download_json( | |
112 | 'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo', | |
113 | video_id, 'Downloading video info json', data=json.dumps(params).encode('utf-8')) | |
114 | ||
115 | title = info['MediaName'] | |
116 | ||
117 | formats = [] | |
118 | for video_file in info.get('Files', []): | |
119 | video_url, vid_format = video_file.get('URL'), video_file.get('Format') | |
120 | if not video_url or video_url == 'NA' or not vid_format: | |
121 | continue | |
122 | ext = determine_ext(video_url) | |
123 | vid_format = vid_format.replace(' ', '') | |
124 | # if geo-restricted, m3u8 is inaccessible, but mp4 is okay | |
125 | if ext == 'm3u8': | |
126 | m3u8_formats = self._extract_m3u8_formats( | |
127 | video_url, video_id, ext='mp4', m3u8_id=vid_format, | |
128 | note='Downloading %s m3u8 information' % vid_format, | |
129 | errnote='Failed to download %s m3u8 information' % vid_format, | |
130 | fatal=False) | |
131 | for f in m3u8_formats: | |
132 | # Apple FairPlay Streaming | |
133 | if '/fpshls/' in f['url']: | |
134 | continue | |
135 | formats.append(f) | |
136 | elif ext == 'mpd': | |
137 | formats.extend(self._extract_mpd_formats( | |
138 | video_url, video_id, mpd_id=vid_format, | |
139 | note='Downloading %s MPD manifest' % vid_format, | |
140 | errnote='Failed to download %s MPD manifest' % vid_format, | |
141 | fatal=False)) | |
142 | elif ext == 'ism': | |
143 | formats.extend(self._extract_ism_formats( | |
144 | video_url, video_id, ism_id=vid_format, | |
145 | note='Downloading %s ISM manifest' % vid_format, | |
146 | errnote='Failed to download %s ISM manifest' % vid_format, | |
147 | fatal=False)) | |
148 | elif ext == 'mp4': | |
149 | formats.append({ | |
150 | 'ext': ext, | |
151 | 'url': video_url, | |
152 | 'format_id': vid_format, | |
153 | }) | |
154 | if not formats: | |
155 | for meta in (info.get('Metas') or []): | |
156 | if (not self.get_param('allow_unplayable_formats') | |
157 | and meta.get('Key') == 'Encryption' and meta.get('Value') == '1'): | |
158 | self.report_drm(video_id) | |
159 | # Most likely because geo-blocked if no formats and no DRM | |
160 | self._sort_formats(formats) | |
161 | ||
162 | thumbnails = [] | |
163 | for picture in info.get('Pictures', []): | |
164 | if not isinstance(picture, dict): | |
165 | continue | |
166 | pic_url = picture.get('URL') | |
167 | if not pic_url: | |
168 | continue | |
169 | thumbnail = { | |
170 | 'url': pic_url, | |
171 | } | |
172 | pic_size = picture.get('PicSize', '') | |
173 | m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size) | |
174 | if m: | |
175 | thumbnail.update({ | |
176 | 'width': int(m.group('width')), | |
177 | 'height': int(m.group('height')), | |
178 | }) | |
179 | thumbnails.append(thumbnail) | |
180 | ||
181 | def counter(prefix): | |
182 | return int_or_none( | |
183 | info.get(prefix + 'Counter') or info.get(prefix.lower() + '_counter')) | |
184 | ||
185 | return { | |
186 | 'id': video_id, | |
187 | 'title': title, | |
188 | 'description': strip_or_none(info.get('Description')), | |
189 | 'duration': int_or_none(info.get('Duration')), | |
190 | 'timestamp': parse_iso8601(info.get('CreationDate') or None), | |
191 | 'average_rating': float_or_none(info.get('Rating')), | |
192 | 'view_count': counter('View'), | |
193 | 'like_count': counter('Like'), | |
194 | 'thumbnails': thumbnails, | |
195 | 'formats': formats, | |
196 | } | |
197 | ||
198 | ||
199 | class MeWatchIE(InfoExtractor): | |
200 | IE_NAME = 'mewatch' | |
201 | _VALID_URL = r'https?://(?:(?:www|live)\.)?mewatch\.sg/watch/[^/?#&]+-(?P<id>[0-9]+)' | |
202 | _TESTS = [{ | |
203 | 'url': 'https://www.mewatch.sg/watch/Recipe-Of-Life-E1-179371', | |
204 | 'info_dict': { | |
205 | 'id': '1008625', | |
206 | 'ext': 'mp4', | |
207 | 'title': 'Recipe Of Life 味之道', | |
208 | 'timestamp': 1603306526, | |
209 | 'description': 'md5:6e88cde8af2068444fc8e1bc3ebf257c', | |
210 | 'upload_date': '20201021', | |
211 | }, | |
212 | 'params': { | |
213 | 'skip_download': 'm3u8 download', | |
214 | }, | |
215 | }, { | |
216 | 'url': 'https://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-搜密。打卡。小红点-S2-E1-176232', | |
217 | 'only_matching': True, | |
218 | }, { | |
219 | 'url': 'https://www.mewatch.sg/watch/Little-Red-Dot-Detectives-S2-%E6%90%9C%E5%AF%86%E3%80%82%E6%89%93%E5%8D%A1%E3%80%82%E5%B0%8F%E7%BA%A2%E7%82%B9-S2-E1-176232', | |
220 | 'only_matching': True, | |
221 | }, { | |
222 | 'url': 'https://live.mewatch.sg/watch/Recipe-Of-Life-E41-189759', | |
223 | 'only_matching': True, | |
224 | }] | |
225 | ||
226 | def _real_extract(self, url): | |
227 | item_id = self._match_id(url) | |
228 | custom_id = self._download_json( | |
229 | 'https://cdn.mewatch.sg/api/items/' + item_id, | |
230 | item_id, query={'segments': 'all'})['customId'] | |
231 | return self.url_result( | |
232 | 'toggle:' + custom_id, ToggleIE.ie_key(), custom_id) |