2 from __future__ import unicode_literals
6 from .common import InfoExtractor
16 class ToggleSgIE(InfoExtractor):
18 _VALID_URL = r'https?://video\.toggle\.sg/(?:en|zh)/(?:series|clips|movies)/.+?/(?P<id>[0-9]+)'
20 'url': 'http://video.toggle.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
24 'title': 'Lion Moms Premiere',
25 'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b',
26 'upload_date': '20150910',
27 'timestamp': 1441858274,
30 'skip_download': 'm3u8 download',
33 'note': 'DRM-protected video',
34 'url': 'http://video.toggle.sg/en/movies/dug-s-special-mission/341413',
38 'title': 'Dug\'s Special Mission',
39 'description': 'md5:e86c6f4458214905c1772398fabc93e0',
40 'upload_date': '20150827',
41 'timestamp': 1440644006,
44 'skip_download': 'DRM-protected wvm download',
47 'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay',
48 'url': 'http://video.toggle.sg/en/series/28th-sea-games-5-show/ep11/332861',
52 'title': '28th SEA Games (5 Show) - Episode 11',
53 'description': 'md5:3cd4f5f56c7c3b1340c50a863f896faa',
54 'upload_date': '20150605',
55 'timestamp': 1433480166,
58 'skip_download': 'DRM-protected wvm download',
60 'skip': 'm3u8 links are geo-restricted'
62 'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
63 'only_matching': True,
65 'url': 'http://video.toggle.sg/zh/series/zero-calling-s2-hd/ep13/336367',
66 'only_matching': True,
68 'url': 'http://video.toggle.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302',
69 'only_matching': True,
71 'url': 'http://video.toggle.sg/en/movies/seven-days/321936',
72 'only_matching': True,
75 _FORMAT_PREFERENCES = {
78 'wvm-iPhoneMain': -30,
81 _API_USER = 'tvpapi_147'
84 def _real_extract(self, url):
85 video_id = self._match_id(url)
87 webpage = self._download_webpage(
88 url, video_id, note='Downloading video page')
90 api_user = self._search_regex(
91 r'apiUser\s*:\s*(["\'])(?P<user>.+?)\1', webpage, 'apiUser',
92 default=self._API_USER, group='user')
93 api_pass = self._search_regex(
94 r'apiPass\s*:\s*(["\'])(?P<pass>.+?)\1', webpage, 'apiPass',
95 default=self._API_PASS, group='pass')
100 'LocaleLanguage': '',
116 req = sanitized_Request(
117 'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
118 json.dumps(params).encode('utf-8'))
119 info = self._download_json(req, video_id, 'Downloading video info json')
121 title = info['MediaName']
122 duration = int_or_none(info.get('Duration'))
123 thumbnail = info.get('PicURL')
124 description = info.get('Description')
125 created_at = parse_iso8601(info.get('CreationDate') or None)
128 for video_file in info.get('Files', []):
129 ext = determine_ext(video_file['URL'])
130 vid_format = video_file['Format'].replace(' ', '')
131 # if geo-restricted, m3u8 is inaccessible, but mp4 is okay
133 m3u8_formats = self._extract_m3u8_formats(
134 video_file['URL'], video_id, ext='mp4', m3u8_id=vid_format,
135 note='Downloading %s m3u8 information' % vid_format,
136 errnote='Failed to download %s m3u8 information' % vid_format,
139 formats.extend(m3u8_formats)
140 elif ext in ('mp4', 'wvm'):
141 # wvm are drm-protected files
144 'url': video_file['URL'],
145 'format_id': vid_format,
146 'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1,
147 'format_note': 'DRM-protected video' if ext == 'wvm' else None
151 # Most likely because geo-blocked
152 raise ExtractorError('No downloadable videos found', expected=True)
154 self._sort_formats(formats)
159 'description': description,
160 'duration': duration,
161 'timestamp': created_at,
162 'thumbnail': thumbnail,