]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/crackle.py
f73ef6b63c8bf7a138e8dcaf8a35fc2798322aea
   2 from __future__ 
import unicode_literals
, division
 
   6 from .common 
import InfoExtractor
 
   7 from ..compat 
import compat_HTTPError
 
  19 class CrackleIE(InfoExtractor
): 
  20     _VALID_URL 
= r
'(?:crackle:|https?://(?:(?:www|m)\.)?(?:sony)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)' 
  22         # geo restricted to CA 
  23         'url': 'https://www.crackle.com/andromeda/2502343', 
  27             'title': 'Under The Night', 
  28             'description': 'md5:d2b8ca816579ae8a7bf28bfff8cefc8a', 
  33             'genre': 'Action, Sci-Fi', 
  34             'creator': 'Allan Kroeker', 
  35             'artist': 'Keith Hamilton Cobb, Kevin Sorbo, Lisa Ryder, Lexa Doig, Robert Hewitt Wolfe', 
  37             'series': 'Andromeda', 
  38             'episode': 'Under The Night', 
  44             'skip_download': True, 
  47         'url': 'https://www.sonycrackle.com/andromeda/2502343', 
  48         'only_matching': True, 
  66     def _real_extract(self
, url
): 
  67         video_id 
= self
._match
_id
(url
) 
  69         country_code 
= self
._downloader
.params
.get('geo_bypass_country', None) 
  70         countries 
= [country_code
] if country_code 
else ( 
  71             'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI') 
  75         for country 
in countries
: 
  77                 media 
= self
._download
_json
( 
  78                     'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s' 
  79                     % (video_id
, country
), video_id
, 
  80                     'Downloading media JSON as %s' % country
, 
  81                     'Unable to download media JSON', query
={ 
  82                         'disableProtocols': 'true', 
  85             except ExtractorError 
as e
: 
  86                 # 401 means geo restriction, trying next country 
  87                 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code 
== 401: 
  92             media_urls 
= media
.get('MediaURLs') 
  93             if not media_urls 
or not isinstance(media_urls
, list): 
  96             title 
= media
['Title'] 
  99             for e 
in media
['MediaURLs']: 
 100                 if e
.get('UseDRM') is True: 
 102                 format_url 
= url_or_none(e
.get('Path')) 
 105                 ext 
= determine_ext(format_url
) 
 107                     formats
.extend(self
._extract
_m
3u8_formats
( 
 108                         format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
 109                         m3u8_id
='hls', fatal
=False)) 
 111                     formats
.extend(self
._extract
_mpd
_formats
( 
 112                         format_url
, video_id
, mpd_id
='dash', fatal
=False)) 
 113                 elif format_url
.endswith('.ism/Manifest'): 
 114                     formats
.extend(self
._extract
_ism
_formats
( 
 115                         format_url
, video_id
, ism_id
='mss', fatal
=False)) 
 117                     mfs_path 
= e
.get('Type') 
 118                     mfs_info 
= self
._MEDIA
_FILE
_SLOTS
.get(mfs_path
) 
 123                         'format_id': 'http-' + mfs_path
.split('.')[0], 
 124                         'width': mfs_info
['width'], 
 125                         'height': mfs_info
['height'], 
 127             self
._sort
_formats
(formats
) 
 129             description 
= media
.get('Description') 
 130             duration 
= int_or_none(media
.get( 
 131                 'DurationInSeconds')) or parse_duration(media
.get('Duration')) 
 132             view_count 
= int_or_none(media
.get('CountViews')) 
 133             average_rating 
= float_or_none(media
.get('UserRating')) 
 134             age_limit 
= parse_age_limit(media
.get('Rating')) 
 135             genre 
= media
.get('Genre') 
 136             release_year 
= int_or_none(media
.get('ReleaseYear')) 
 137             creator 
= media
.get('Directors') 
 138             artist 
= media
.get('Cast') 
 140             if media
.get('MediaTypeDisplayValue') == 'Full Episode': 
 141                 series 
= media
.get('ShowName') 
 143                 season_number 
= int_or_none(media
.get('Season')) 
 144                 episode_number 
= int_or_none(media
.get('Episode')) 
 146                 series 
= episode 
= season_number 
= episode_number 
= None 
 149             cc_files 
= media
.get('ClosedCaptionFiles') 
 150             if isinstance(cc_files
, list): 
 151                 for cc_file 
in cc_files
: 
 152                     if not isinstance(cc_file
, dict): 
 154                     cc_url 
= url_or_none(cc_file
.get('Path')) 
 157                     lang 
= cc_file
.get('Locale') or 'en' 
 158                     subtitles
.setdefault(lang
, []).append({'url': cc_url
}) 
 161             images 
= media
.get('Images') 
 162             if isinstance(images
, list): 
 163                 for image_key
, image_url 
in images
.items(): 
 164                     mobj 
= re
.search(r
'Img_(\d+)[xX](\d+)', image_key
) 
 169                         'width': int(mobj
.group(1)), 
 170                         'height': int(mobj
.group(2)), 
 176                 'description': description
, 
 177                 'duration': duration
, 
 178                 'view_count': view_count
, 
 179                 'average_rating': average_rating
, 
 180                 'age_limit': age_limit
, 
 184                 'release_year': release_year
, 
 187                 'season_number': season_number
, 
 188                 'episode_number': episode_number
, 
 189                 'thumbnails': thumbnails
, 
 190                 'subtitles': subtitles
,