import json
import re
-import itertools
from .common import InfoExtractor
from ..utils import (
+ determine_ext,
ExtractorError,
int_or_none,
- determine_ext,
parse_iso8601,
- remove_end
+ sanitized_Request,
)
-from ..compat import compat_urllib_request
class ToggleSgIE(InfoExtractor):
IE_NAME = 'togglesg'
- _VALID_URL = r'https?://video\.toggle\.sg/(?:(en|zh))/(?:(series|clips|movies))/.+?/(?P<id>[0-9]+)'
+ _VALID_URL = r'https?://video\.toggle\.sg/(?:en|zh)/(?:series|clips|movies)/.+?/(?P<id>[0-9]+)'
_TESTS = [{
'url': 'http://video.toggle.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
'info_dict': {
def _real_extract(self, url):
video_id = self._match_id(url)
- webpage = self._download_webpage(url, video_id, note='Downloading video page')
+ webpage = self._download_webpage(
+ url, video_id, note='Downloading video page')
api_user = self._search_regex(
- r'apiUser:\s*"([^"]+)"', webpage, 'apiUser', default=self._API_USER, fatal=False)
+ r'apiUser\s*:\s*(["\'])(?P<user>.+?)\1', webpage, 'apiUser',
+ default=self._API_USER, group='user')
api_pass = self._search_regex(
- r'apiPass:\s*"([^"]+)"', webpage, 'apiPass', default=self._API_PASS, fatal=False)
+ r'apiPass\s*:\s*(["\'])(?P<pass>.+?)\1', webpage, 'apiPass',
+ default=self._API_PASS, group='pass')
params = {
'initObj': {
'Locale': {
- 'LocaleLanguage': '', 'LocaleCountry': '',
- 'LocaleDevice': '', 'LocaleUserState': 0
+ 'LocaleLanguage': '',
+ 'LocaleCountry': '',
+ 'LocaleDevice': '',
+ 'LocaleUserState': 0
},
- 'Platform': 0, 'SiteGuid': 0, 'DomainID': '0', 'UDID': '',
- 'ApiUser': api_user, 'ApiPass': api_pass
+ 'Platform': 0,
+ 'SiteGuid': 0,
+ 'DomainID': '0',
+ 'UDID': '',
+ 'ApiUser': api_user,
+ 'ApiPass': api_pass
},
'MediaID': video_id,
'mediaType': 0,
}
- req = compat_urllib_request.Request(
+ req = sanitized_Request(
'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
json.dumps(params).encode('utf-8'))
info = self._download_json(req, video_id, 'Downloading video info json')
title = info['MediaName']
- duration = int_or_none(info.get('Duration'))
- thumbnail = info.get('PicURL')
- description = info.get('Description')
- created_at = parse_iso8601(info.get('CreationDate') or None)
- formats = []
+ formats = []
for video_file in info.get('Files', []):
ext = determine_ext(video_file['URL'])
vid_format = video_file['Format'].replace(' ', '')
video_file['URL'], video_id, ext='mp4', m3u8_id=vid_format,
note='Downloading %s m3u8 information' % vid_format,
errnote='Failed to download %s m3u8 information' % vid_format,
- fatal=False
- )
+ fatal=False)
if m3u8_formats:
formats.extend(m3u8_formats)
- if ext in ['mp4', 'wvm']:
+ elif ext in ('mp4', 'wvm'):
# wvm are drm-protected files
formats.append({
'ext': ext,
'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1,
'format_note': 'DRM-protected video' if ext == 'wvm' else None
})
-
if not formats:
# Most likely because geo-blocked
raise ExtractorError('No downloadable videos found', expected=True)
-
self._sort_formats(formats)
+ duration = int_or_none(info.get('Duration'))
+ description = info.get('Description')
+ created_at = parse_iso8601(info.get('CreationDate') or None)
+
+ thumbnails = []
+ for picture in info.get('Pictures', []):
+ if not isinstance(picture, dict):
+ continue
+ pic_url = picture.get('URL')
+ if not pic_url:
+ continue
+ thumbnail = {
+ 'url': pic_url,
+ }
+ pic_size = picture.get('PicSize', '')
+ m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size)
+ if m:
+ thumbnail.update({
+ 'width': int(m.group('width')),
+ 'height': int(m.group('height')),
+ })
+ thumbnails.append(thumbnail)
+
return {
'id': video_id,
'title': title,
'description': description,
'duration': duration,
'timestamp': created_at,
- 'thumbnail': thumbnail,
+ 'thumbnails': thumbnails,
'formats': formats,
}