]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hidive.py
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_str
 
  16 class HiDiveIE(InfoExtractor
): 
  17     _VALID_URL 
= r
'https?://(?:www\.)?hidive\.com/stream/(?P<title>[^/]+)/(?P<key>[^/?#&]+)' 
  18     # Using X-Forwarded-For results in 403 HTTP error for HLS fragments, 
  19     # so disabling geo bypass completely 
  21     _NETRC_MACHINE 
= 'hidive' 
  22     _LOGIN_URL 
= 'https://www.hidive.com/account/login' 
  25         'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001', 
  27             'id': 'the-comic-artist-and-his-assistants/s01e001', 
  29             'title': 'the-comic-artist-and-his-assistants/s01e001', 
  30             'series': 'the-comic-artist-and-his-assistants', 
  35             'skip_download': True, 
  37         'skip': 'Requires Authentication', 
  40     def _real_initialize(self
): 
  41         email
, password 
= self
._get
_login
_info
() 
  45         webpage 
= self
._download
_webpage
(self
._LOGIN
_URL
, None) 
  46         form 
= self
._search
_regex
( 
  47             r
'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>', 
  48             webpage
, 'login form') 
  49         data 
= self
._hidden
_inputs
(form
) 
  54         self
._download
_webpage
( 
  55             self
._LOGIN
_URL
, None, 'Logging in', data
=urlencode_postdata(data
)) 
  57     def _real_extract(self
, url
): 
  58         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  59         title
, key 
= mobj
.group('title', 'key') 
  60         video_id 
= '%s/%s' % (title
, key
) 
  62         settings 
= self
._download
_json
( 
  63             'https://www.hidive.com/play/settings', video_id
, 
  64             data
=urlencode_postdata({ 
  67                 'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783', 
  70         restriction 
= settings
.get('restrictionReason') 
  71         if restriction 
== 'RegionRestricted': 
  72             self
.raise_geo_restricted() 
  74         if restriction 
and restriction 
!= 'None': 
  76                 '%s said: %s' % (self
.IE_NAME
, restriction
), expected
=True) 
  80         for rendition_id
, rendition 
in settings
['renditions'].items(): 
  81             bitrates 
= rendition
.get('bitrates') 
  82             if not isinstance(bitrates
, dict): 
  84             m3u8_url 
= url_or_none(bitrates
.get('hls')) 
  87             formats
.extend(self
._extract
_m
3u8_formats
( 
  88                 m3u8_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
  89                 m3u8_id
='%s-hls' % rendition_id
, fatal
=False)) 
  90             cc_files 
= rendition
.get('ccFiles') 
  91             if not isinstance(cc_files
, list): 
  93             for cc_file 
in cc_files
: 
  94                 if not isinstance(cc_file
, list) or len(cc_file
) < 3: 
  97                 cc_url 
= url_or_none(cc_file
[2]) 
  98                 if not isinstance(cc_lang
, compat_str
) or not cc_url
: 
 100                 subtitles
.setdefault(cc_lang
, []).append({ 
 103         self
._sort
_formats
(formats
) 
 105         season_number 
= int_or_none(self
._search
_regex
( 
 106             r
's(\d+)', key
, 'season number', default
=None)) 
 107         episode_number 
= int_or_none(self
._search
_regex
( 
 108             r
'e(\d+)', key
, 'episode number', default
=None)) 
 113             'subtitles': subtitles
, 
 116             'season_number': season_number
, 
 117             'episode_number': episode_number
,