[toggle] Style
[youtube-dl] / youtube_dl / extractor / togglesg.py
index 56ef4b464f29492fb1113d1284124430765b8a8c..d3903b58d8e533ff12277d5853883f666ae1fda6 100644 (file)
@@ -2,23 +2,20 @@
 from __future__ import unicode_literals
 
 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': {
@@ -90,24 +87,30 @@ class ToggleSgIE(InfoExtractor):
         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*"([^"]+)"', webpage, 'apiUser', default=self._API_USER)
         api_pass = self._search_regex(
-            r'apiPass:\s*"([^"]+)"', webpage, 'apiPass', default=self._API_PASS, fatal=False)
+            r'apiPass:\s*"([^"]+)"', webpage, 'apiPass', default=self._API_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')