2 from __future__ import unicode_literals
8 from .common import InfoExtractor
16 from ..compat import compat_urllib_request
19 class ToggleSgIE(InfoExtractor):
21 _VALID_URL = r'https?://video\.toggle\.sg/(?:(en|zh))/(?:(series|clips|movies))/.+?/(?P<id>[0-9]+)'
23 'url': 'http://video.toggle.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115',
27 'title': 'Lion Moms Premiere',
28 'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b',
29 'upload_date': '20150910',
30 'timestamp': 1441858274,
33 'skip_download': 'm3u8 download',
36 'note': 'DRM-protected video',
37 'url': 'http://video.toggle.sg/en/movies/dug-s-special-mission/341413',
41 'title': 'Dug\'s Special Mission',
42 'description': 'md5:e86c6f4458214905c1772398fabc93e0',
43 'upload_date': '20150827',
44 'timestamp': 1440644006,
47 'skip_download': 'DRM-protected wvm download',
50 'note': 'm3u8 links are geo-restricted, but Android/mp4 is okay',
51 'url': 'http://video.toggle.sg/en/series/28th-sea-games-5-show/ep11/332861',
55 'title': '28th SEA Games (5 Show) - Episode 11',
56 'description': 'md5:3cd4f5f56c7c3b1340c50a863f896faa',
57 'upload_date': '20150605',
58 'timestamp': 1433480166,
61 'skip_download': 'DRM-protected wvm download',
63 'skip': 'm3u8 links are geo-restricted'
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,
68 'url': 'http://video.toggle.sg/zh/series/zero-calling-s2-hd/ep13/336367',
69 'only_matching': True,
71 'url': 'http://video.toggle.sg/en/series/vetri-s2/webisodes/jeeva-is-an-orphan-vetri-s2-webisode-7/342302',
72 'only_matching': True,
74 'url': 'http://video.toggle.sg/en/movies/seven-days/321936',
75 'only_matching': True,
78 _FORMAT_PREFERENCES = {
81 'wvm-iPhoneMain': -30,
84 _API_USER = 'tvpapi_147'
87 def _real_extract(self, url):
88 video_id = self._match_id(url)
90 webpage = self._download_webpage(url, video_id, note='Downloading video page')
92 api_user = self._search_regex(
93 r'apiUser:\s*"([^"]+)"', webpage, 'apiUser', default=self._API_USER, fatal=False)
94 api_pass = self._search_regex(
95 r'apiPass:\s*"([^"]+)"', webpage, 'apiPass', default=self._API_PASS, fatal=False)
100 'LocaleLanguage': '', 'LocaleCountry': '',
101 'LocaleDevice': '', 'LocaleUserState': 0
103 'Platform': 0, 'SiteGuid': 0, 'DomainID': '0', 'UDID': '',
104 'ApiUser': api_user, 'ApiPass': api_pass
110 req = compat_urllib_request.Request(
111 'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo',
112 json.dumps(params).encode('utf-8'))
113 info = self._download_json(req, video_id, 'Downloading video info json')
115 title = info['MediaName']
116 duration = int_or_none(info.get('Duration'))
117 thumbnail = info.get('PicURL')
118 description = info.get('Description')
119 created_at = parse_iso8601(info.get('CreationDate') or None)
122 for video_file in info.get('Files', []):
123 ext = determine_ext(video_file['URL'])
124 vid_format = video_file['Format'].replace(' ', '')
125 # if geo-restricted, m3u8 is inaccessible, but mp4 is okay
127 m3u8_formats = self._extract_m3u8_formats(
128 video_file['URL'], video_id, ext='mp4', m3u8_id=vid_format,
129 note='Downloading %s m3u8 information' % vid_format,
130 errnote='Failed to download %s m3u8 information' % vid_format,
134 formats.extend(m3u8_formats)
135 if ext in ['mp4', 'wvm']:
136 # wvm are drm-protected files
139 'url': video_file['URL'],
140 'format_id': vid_format,
141 'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1,
142 'format_note': 'DRM-protected video' if ext == 'wvm' else None
146 # Most likely because geo-blocked
147 raise ExtractorError('No downloadable videos found', expected=True)
149 self._sort_formats(formats)
154 'description': description,
155 'duration': duration,
156 'timestamp': created_at,
157 'thumbnail': thumbnail,