]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/toggle.py
348d6ecdf19ecde7787cbb12331561c8bb2a0284
   2 from __future__ 
import unicode_literals
 
   7 from .common 
import InfoExtractor
 
  18 class ToggleIE(InfoExtractor
): 
  20     _VALID_URL 
= r
'https?://video\.toggle\.sg/(?:en|zh)/(?:[^/]+/){2,}(?P<id>[0-9]+)' 
  22         'url': 'http://video.toggle.sg/en/series/lion-moms-tif/trailers/lion-moms-premier/343115', 
  26             'title': 'Lion Moms Premiere', 
  27             'description': 'md5:aea1149404bff4d7f7b6da11fafd8e6b', 
  28             'upload_date': '20150910', 
  29             'timestamp': 1441858274, 
  32             'skip_download': 'm3u8 download', 
  35         'note': 'DRM-protected video', 
  36         'url': 'http://video.toggle.sg/en/movies/dug-s-special-mission/341413', 
  40             'title': 'Dug\'s Special Mission', 
  41             'description': 'md5:e86c6f4458214905c1772398fabc93e0', 
  42             'upload_date': '20150827', 
  43             'timestamp': 1440644006, 
  46             'skip_download': 'DRM-protected wvm download', 
  49         # this also tests correct video id extraction 
  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/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, 
  77         'url': 'https://video.toggle.sg/en/tv-show/news/may-2017-cna-singapore-tonight/fri-19-may-2017/512456', 
  78         'only_matching': True, 
  80         'url': 'http://video.toggle.sg/en/channels/eleven-plus/401585', 
  81         'only_matching': True, 
  84     _FORMAT_PREFERENCES 
= { 
  87         'wvm-iPhoneMain': -30, 
  90     _API_USER 
= 'tvpapi_147' 
  93     def _real_extract(self
, url
): 
  94         video_id 
= self
._match
_id
(url
) 
  96         webpage 
= self
._download
_webpage
( 
  97             url
, video_id
, note
='Downloading video page') 
  99         api_user 
= self
._search
_regex
( 
 100             r
'apiUser\s*:\s*(["\'])(?P
<user
>.+?
)\
1', webpage, 'apiUser
', 
 101             default=self._API_USER, group='user
') 
 102         api_pass = self._search_regex( 
 103             r'apiPass\s
*:\s
*(["\'])(?P<pass>.+?)\1', webpage, 'apiPass', 
 104             default=self._API_PASS, group='pass') 
 109                     'LocaleLanguage': '', 
 125         req = sanitized_Request( 
 126             'http://tvpapi.as.tvinci.com/v2_9/gateways/jsonpostgw.aspx?m=GetMediaInfo', 
 127             json.dumps(params).encode('utf-8')) 
 128         info = self._download_json(req, video_id, 'Downloading video info json') 
 130         title = info['MediaName'] 
 133         for video_file in info.get('Files', []): 
 134             video_url, vid_format = video_file.get('URL'), video_file.get('Format') 
 135             if not video_url or not vid_format: 
 137             ext = determine_ext(video_url) 
 138             vid_format = vid_format.replace(' ', '') 
 139             # if geo-restricted, m3u8 is inaccessible, but mp4 is okay 
 141                 formats.extend(self._extract_m3u8_formats( 
 142                     video_url, video_id, ext='mp4', m3u8_id=vid_format, 
 143                     note='Downloading %s m3u8 information' % vid_format, 
 144                     errnote='Failed to download %s m3u8 information' % vid_format, 
 146             elif ext in ('mp4', 'wvm'): 
 147                 # wvm are drm-protected files 
 151                     'format_id': vid_format, 
 152                     'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1, 
 153                     'format_note': 'DRM-protected video' if ext == 'wvm' else None 
 156             # Most likely because geo-blocked 
 157             raise ExtractorError('No downloadable videos found', expected=True) 
 158         self._sort_formats(formats) 
 160         duration = int_or_none(info.get('Duration')) 
 161         description = info.get('Description') 
 162         created_at = parse_iso8601(info.get('CreationDate') or None) 
 164         average_rating = float_or_none(info.get('Rating')) 
 165         view_count = int_or_none(info.get('ViewCounter') or info.get('view_counter')) 
 166         like_count = int_or_none(info.get('LikeCounter') or info.get('like_counter')) 
 169         for picture in info.get('Pictures', []): 
 170             if not isinstance(picture, dict): 
 172             pic_url = picture.get('URL') 
 178             pic_size = picture.get('PicSize', '') 
 179             m = re.search(r'(?P<width>\d+)[xX](?P<height>\d+)', pic_size) 
 182                     'width': int(m.group('width')), 
 183                     'height': int(m.group('height')), 
 185             thumbnails.append(thumbnail) 
 190             'description': description, 
 191             'duration': duration, 
 192             'timestamp': created_at, 
 193             'average_rating': average_rating, 
 194             'view_count': view_count, 
 195             'like_count': like_count, 
 196             'thumbnails': thumbnails,