2 from __future__ import unicode_literals
8 from .common import InfoExtractor
17 from ..compat import compat_urllib_request
20 class ToggleSgIE(InfoExtractor):
22 _VALID_URL = r'https?://video\.toggle\.sg/(?:en|zh)/(?:series|clips|movies)/.+?/(?P<id>[0-9]+)'
24 'url': 'http://video.toggle.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
28 'title': 'Lion Moms Premiere',
29 'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b',
30 'upload_date': '20150910',
31 'timestamp': 1441858274,
34 'skip_download': 'm3u8 download',
37 'note': 'DRM-protected video',
38 'url': 'http://video.toggle.sg/en/movies/dug-s-special-mission/341413',
42 'title': 'Dug\'s Special Mission',
43 'description': 'md5:e86c6f4458214905c1772398fabc93e0',
44 'upload_date': '20150827',
45 'timestamp': 1440644006,
48 'skip_download': 'DRM-protected wvm download',
51 'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay',
52 'url': 'http://video.toggle.sg/en/series/28th-sea-games-5-show/ep11/332861',
56 'title': '28th SEA Games (5 Show) - Episode 11',
57 'description': 'md5:3cd4f5f56c7c3b1340c50a863f896faa',
58 'upload_date': '20150605',
59 'timestamp': 1433480166,
62 'skip_download': 'DRM-protected wvm download',
64 'skip': 'm3u8 links are geo-restricted'
66 'url': 'http://video.toggle.sg/en/clips/seraph-sun-aloysius-will-suddenly-sing-some-old-songs-in-high-pitch-on-set/343331',
67 'only_matching': True,
69 'url': 'http://video.toggle.sg/zh/series/zero-calling-s2-hd/ep13/336367',
70 'only_matching': True,
72 'url': 'http://video.toggle.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302',
73 'only_matching': True,
75 'url': 'http://video.toggle.sg/en/movies/seven-days/321936',
76 'only_matching': True,
79 _FORMAT_PREFERENCES = {
82 'wvm-iPhoneMain': -30,
85 _API_USER = 'tvpapi_147'
88 def _real_extract(self, url):
89 video_id = self._match_id(url)
91 webpage = self._download_webpage(url, video_id, note='Downloading video page')
93 api_user = self._search_regex(
94 r'apiUser:\s*"([^"]+)"', webpage, 'apiUser', default=self._API_USER)
95 api_pass = self._search_regex(
96 r'apiPass:\s*"([^"]+)"', webpage, 'apiPass', default=self._API_PASS)
101 'LocaleLanguage': '', 'LocaleCountry': '',
102 'LocaleDevice': '', 'LocaleUserState': 0
104 'Platform': 0, 'SiteGuid': 0, 'DomainID': '0', 'UDID': '',
105 'ApiUser': api_user, 'ApiPass': api_pass
111 req = sanitized_Request(
112 'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
113 json.dumps(params).encode('utf-8'))
114 info = self._download_json(req, video_id, 'Downloading video info json')
116 title = info['MediaName']
117 duration = int_or_none(info.get('Duration'))
118 thumbnail = info.get('PicURL')
119 description = info.get('Description')
120 created_at = parse_iso8601(info.get('CreationDate') or None)
123 for video_file in info.get('Files', []):
124 ext = determine_ext(video_file['URL'])
125 vid_format = video_file['Format'].replace(' ', '')
126 # if geo-restricted, m3u8 is inaccessible, but mp4 is okay
128 m3u8_formats = self._extract_m3u8_formats(
129 video_file['URL'], video_id, ext='mp4', m3u8_id=vid_format,
130 note='Downloading %s m3u8 information' % vid_format,
131 errnote='Failed to download %s m3u8 information' % vid_format,
135 formats.extend(m3u8_formats)
136 if ext in ['mp4', 'wvm']:
137 # wvm are drm-protected files
140 'url': video_file['URL'],
141 'format_id': vid_format,
142 'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1,
143 'format_note': 'DRM-protected video' if ext == 'wvm' else None
147 # Most likely because geo-blocked
148 raise ExtractorError('No downloadable videos found', expected=True)
150 self._sort_formats(formats)
155 'description': description,
156 'duration': duration,
157 'timestamp': created_at,
158 'thumbnail': thumbnail,