]>
Commit | Line | Data |
---|---|---|
ee0f0393 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import json | |
c40dbb19 | 5 | import re |
ee0f0393 | 6 | |
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
c82a8dd1 | 9 | determine_ext, |
ee0f0393 | 10 | ExtractorError, |
8f097af4 | 11 | float_or_none, |
ee0f0393 | 12 | int_or_none, |
ee0f0393 | 13 | parse_iso8601, |
f8253af5 | 14 | sanitized_Request, |
ee0f0393 | 15 | ) |
ee0f0393 | 16 | |
17 | ||
cc0f378d | 18 | class ToggleIE(InfoExtractor): |
0f206ee8 | 19 | IE_NAME = 'toggle' |
b827ee92 | 20 | _VALID_URL = r'https?://(?:(?:www\.)?mewatch|video\.toggle)\.sg/(?:en|zh)/(?:[^/]+/){2,}(?P<id>[0-9]+)' |
ee0f0393 | 21 | _TESTS = [{ |
b827ee92 | 22 | 'url': 'http://www.mewatch.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115', |
ee0f0393 | 23 | 'info_dict': { |
24 | 'id': '343115', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Lion Moms Premiere', | |
27 | 'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b', | |
28 | 'upload_date': '20150910', | |
29 | 'timestamp': 1441858274, | |
30 | }, | |
31 | 'params': { | |
32 | 'skip_download': 'm3u8 download', | |
33 | } | |
34 | }, { | |
35 | 'note': 'DRM-protected video', | |
b827ee92 | 36 | 'url': 'http://www.mewatch.sg/en/movies/dug-s-special-mission/341413', |
ee0f0393 | 37 | 'info_dict': { |
38 | 'id': '341413', | |
39 | 'ext': 'wvm', | |
40 | 'title': 'Dug\'s Special Mission', | |
41 | 'description': 'md5:e86c6f4458214905c1772398fabc93e0', | |
42 | 'upload_date': '20150827', | |
43 | 'timestamp': 1440644006, | |
44 | }, | |
45 | 'params': { | |
46 | 'skip_download': 'DRM-protected wvm download', | |
47 | } | |
48 | }, { | |
e33c9cba | 49 | # this also tests correct video id extraction |
ee0f0393 | 50 | 'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay', |
b827ee92 | 51 | 'url': 'http://www.mewatch.sg/en/series/28th-sea-games-5-show/28th-sea-games-5-show-ep11/332861', |
ee0f0393 | 52 | 'info_dict': { |
53 | 'id': '332861', | |
54 | 'ext': 'mp4', | |
55 | 'title': '28th SEA Games (5 Show) - Episode 11', | |
56 | 'description': 'md5:3cd4f5f56c7c3b1340c50a863f896faa', | |
57 | 'upload_date': '20150605', | |
58 | 'timestamp': 1433480166, | |
59 | }, | |
60 | 'params': { | |
61 | 'skip_download': 'DRM-protected wvm download', | |
62 | }, | |
63 | 'skip': 'm3u8 links are geo-restricted' | |
64 | }, { | |
65 | 'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331', | |
66 | 'only_matching': True, | |
67 | }, { | |
b827ee92 | 68 | 'url': 'http://www.mewatch.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331', |
ee0f0393 | 69 | 'only_matching': True, |
70 | }, { | |
b827ee92 | 71 | 'url': 'http://www.mewatch.sg/zh/series/zero-calling-s2-hd/ep13/336367', |
ee0f0393 | 72 | 'only_matching': True, |
73 | }, { | |
b827ee92 | 74 | 'url': 'http://www.mewatch.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302', |
ee0f0393 | 75 | 'only_matching': True, |
35a2d221 | 76 | }, { |
b827ee92 | 77 | 'url': 'http://www.mewatch.sg/en/movies/seven-days/321936', |
35a2d221 S |
78 | 'only_matching': True, |
79 | }, { | |
b827ee92 AG |
80 | 'url': 'https://www.mewatch.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456', |
81 | 'only_matching': True, | |
82 | }, { | |
83 | 'url': 'http://www.mewatch.sg/en/channels/eleven-plus/401585', | |
35a2d221 | 84 | 'only_matching': True, |
ee0f0393 | 85 | }] |
86 | ||
87 | _FORMAT_PREFERENCES = { | |
88 | 'wvm-STBMain': -10, | |
89 | 'wvm-iPadMain': -20, | |
90 | 'wvm-iPhoneMain': -30, | |
91 | 'wvm-Android': -40, | |
92 | } | |
93 | _API_USER = 'tvpapi_147' | |
94 | _API_PASS = '11111' | |
95 | ||
96 | def _real_extract(self, url): | |
97 | video_id = self._match_id(url) | |
98 | ||
ffaf6e66 S |
99 | webpage = self._download_webpage( |
100 | url, video_id, note='Downloading video page') | |
ee0f0393 | 101 | |
102 | api_user = self._search_regex( | |
ffaf6e66 S |
103 | r'apiUser\s*:\s*(["\'])(?P<user>.+?)\1', webpage, 'apiUser', |
104 | default=self._API_USER, group='user') | |
ee0f0393 | 105 | api_pass = self._search_regex( |
ffaf6e66 S |
106 | r'apiPass\s*:\s*(["\'])(?P<pass>.+?)\1', webpage, 'apiPass', |
107 | default=self._API_PASS, group='pass') | |
ee0f0393 | 108 | |
109 | params = { | |
110 | 'initObj': { | |
111 | 'Locale': { | |
74c73017 S |
112 | 'LocaleLanguage': '', |
113 | 'LocaleCountry': '', | |
114 | 'LocaleDevice': '', | |
115 | 'LocaleUserState': 0 | |
ee0f0393 | 116 | }, |
74c73017 S |
117 | 'Platform': 0, |
118 | 'SiteGuid': 0, | |
119 | 'DomainID': '0', | |
120 | 'UDID': '', | |
121 | 'ApiUser': api_user, | |
122 | 'ApiPass': api_pass | |
ee0f0393 | 123 | }, |
124 | 'MediaID': video_id, | |
125 | 'mediaType': 0, | |
126 | } | |
127 | ||
f8253af5 | 128 | req = sanitized_Request( |
ee0f0393 | 129 | 'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo', |
130 | json.dumps(params).encode('utf-8')) | |
131 | info = self._download_json(req, video_id, 'Downloading video info json') | |
132 | ||
133 | title = info['MediaName'] | |
ee0f0393 | 134 | |
c40dbb19 | 135 | formats = [] |
ee0f0393 | 136 | for video_file in info.get('Files', []): |
989e9f8e | 137 | video_url, vid_format = video_file.get('URL'), video_file.get('Format') |
949faa15 | 138 | if not video_url or video_url == 'NA' or not vid_format: |
989e9f8e S |
139 | continue |
140 | ext = determine_ext(video_url) | |
141 | vid_format = vid_format.replace(' ', '') | |
ee0f0393 | 142 | # if geo-restricted, m3u8 is inaccessible, but mp4 is okay |
143 | if ext == 'm3u8': | |
7e5edcfd | 144 | formats.extend(self._extract_m3u8_formats( |
989e9f8e | 145 | video_url, video_id, ext='mp4', m3u8_id=vid_format, |
ee0f0393 | 146 | note='Downloading %s m3u8 information' % vid_format, |
147 | errnote='Failed to download %s m3u8 information' % vid_format, | |
7e5edcfd | 148 | fatal=False)) |
949faa15 S |
149 | elif ext == 'mpd': |
150 | formats.extend(self._extract_mpd_formats( | |
151 | video_url, video_id, mpd_id=vid_format, | |
152 | note='Downloading %s MPD manifest' % vid_format, | |
153 | errnote='Failed to download %s MPD manifest' % vid_format, | |
154 | fatal=False)) | |
155 | elif ext == 'ism': | |
156 | formats.extend(self._extract_ism_formats( | |
157 | video_url, video_id, ism_id=vid_format, | |
158 | note='Downloading %s ISM manifest' % vid_format, | |
159 | errnote='Failed to download %s ISM manifest' % vid_format, | |
160 | fatal=False)) | |
ffaf6e66 | 161 | elif ext in ('mp4', 'wvm'): |
ee0f0393 | 162 | # wvm are drm-protected files |
163 | formats.append({ | |
164 | 'ext': ext, | |
989e9f8e | 165 | 'url': video_url, |
ee0f0393 | 166 | 'format_id': vid_format, |
167 | 'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1, | |
168 | 'format_note': 'DRM-protected video' if ext == 'wvm' else None | |
169 | }) | |
ee0f0393 | 170 | if not formats: |
171 | # Most likely because geo-blocked | |
172 | raise ExtractorError('No downloadable videos found', expected=True) | |
ee0f0393 | 173 | self._sort_formats(formats) |
174 | ||
c40dbb19 S |
175 | duration = int_or_none(info.get('Duration')) |
176 | description = info.get('Description') | |
177 | created_at = parse_iso8601(info.get('CreationDate') or None) | |
178 | ||
8f097af4 S |
179 | average_rating = float_or_none(info.get('Rating')) |
180 | view_count = int_or_none(info.get('ViewCounter') or info.get('view_counter')) | |
181 | like_count = int_or_none(info.get('LikeCounter') or info.get('like_counter')) | |
182 | ||
c40dbb19 S |
183 | thumbnails = [] |
184 | for picture in info.get('Pictures', []): | |
185 | if not isinstance(picture, dict): | |
186 | continue | |
187 | pic_url = picture.get('URL') | |
188 | if not pic_url: | |
189 | continue | |
190 | thumbnail = { | |
191 | 'url': pic_url, | |
192 | } | |
193 | pic_size = picture.get('PicSize', '') | |
194 | m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size) | |
195 | if m: | |
196 | thumbnail.update({ | |
197 | 'width': int(m.group('width')), | |
198 | 'height': int(m.group('height')), | |
199 | }) | |
200 | thumbnails.append(thumbnail) | |
201 | ||
ee0f0393 | 202 | return { |
203 | 'id': video_id, | |
204 | 'title': title, | |
205 | 'description': description, | |
206 | 'duration': duration, | |
207 | 'timestamp': created_at, | |
8f097af4 S |
208 | 'average_rating': average_rating, |
209 | 'view_count': view_count, | |
210 | 'like_count': like_count, | |
c40dbb19 | 211 | 'thumbnails': thumbnails, |
ee0f0393 | 212 | 'formats': formats, |
213 | } |