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