]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/crackle.py
2 from __future__
import unicode_literals
, division
9 from .common
import InfoExtractor
10 from ..compat
import compat_HTTPError
23 class CrackleIE(InfoExtractor
):
24 _VALID_URL
= r
'(?:crackle:|https?://(?:(?:www|m)\.)?(?:sony)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
26 # geo restricted to CA
27 'url': 'https://www.crackle.com/andromeda/2502343',
31 'title': 'Under The Night',
32 'description': 'md5:d2b8ca816579ae8a7bf28bfff8cefc8a',
37 'genre': 'Action, Sci-Fi',
38 'creator': 'Allan Kroeker',
39 'artist': 'Keith Hamilton Cobb, Kevin Sorbo, Lisa Ryder, Lexa Doig, Robert Hewitt Wolfe',
41 'series': 'Andromeda',
42 'episode': 'Under The Night',
48 'skip_download': True,
51 'url': 'https://www.sonycrackle.com/andromeda/2502343',
52 'only_matching': True,
70 def _download_json(self
, url
, *args
, **kwargs
):
71 # Authorization generation algorithm is reverse engineered from:
72 # https://www.sonycrackle.com/static/js/main.ea93451f.chunk.js
73 timestamp
= time
.strftime('%Y%m%d%H%M', time
.gmtime())
74 h
= hmac
.new(b
'IGSLUQCBDFHEOIFM', '|'.join([url
, timestamp
]).encode(), hashlib
.sha1
).hexdigest().upper()
76 'Accept': 'application/json',
77 'Authorization': '|'.join([h
, timestamp
, '117', '1']),
79 return InfoExtractor
._download
_json
(self
, url
, *args
, headers
=headers
, **kwargs
)
81 def _real_extract(self
, url
):
82 video_id
= self
._match
_id
(url
)
84 geo_bypass_country
= self
.get_param('geo_bypass_country', None)
85 countries
= orderedSet((geo_bypass_country
, 'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI', ''))
86 num_countries
, num
= len(countries
) - 1, 0
89 for num
, country
in enumerate(countries
):
90 if num
== 1: # start hard-coded list
91 self
.report_warning('%s. Trying with a list of known countries' % (
92 'Unable to obtain video formats from %s API' % geo_bypass_country
if geo_bypass_country
93 else 'No country code was given using --geo-bypass-country'))
94 elif num
== num_countries
: # end of list
95 geo_info
= self
._download
_json
(
96 'https://web-api-us.crackle.com/Service.svc/geo/country',
97 video_id
, fatal
=False, note
='Downloading geo-location information from crackle API',
98 errnote
='Unable to fetch geo-location information from crackle') or {}
99 country
= geo_info
.get('CountryCode')
102 self
.to_screen('%s identified country as %s' % (self
.IE_NAME
, country
))
103 if country
in countries
:
104 self
.to_screen('Downloading from %s API was already attempted. Skipping...' % country
)
110 media
= self
._download
_json
(
111 'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s?disableProtocols=true' % (video_id
, country
),
112 video_id
, note
='Downloading media JSON from %s API' % country
,
113 errnote
='Unable to download media JSON')
114 except ExtractorError
as e
:
115 # 401 means geo restriction, trying next country
116 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
120 status
= media
.get('status')
121 if status
.get('messageCode') != '0':
122 raise ExtractorError(
123 '%s said: %s %s - %s' % (
124 self
.IE_NAME
, status
.get('messageCodeDescription'), status
.get('messageCode'), status
.get('message')),
127 # Found video formats
128 if isinstance(media
.get('MediaURLs'), list):
131 ignore_no_formats
= self
.get_param('ignore_no_formats_error')
132 allow_unplayable_formats
= self
.get_param('allow_unplayable_formats')
134 if not media
or (not media
.get('MediaURLs') and not ignore_no_formats
):
135 raise ExtractorError(
136 'Unable to access the crackle API. Try passing your country code '
137 'to --geo-bypass-country. If it still does not work and the '
138 'video is available in your country')
139 title
= media
['Title']
141 formats
, subtitles
= [], {}
143 for e
in media
.get('MediaURLs') or []:
146 if not allow_unplayable_formats
:
148 format_url
= url_or_none(e
.get('Path'))
151 ext
= determine_ext(format_url
)
153 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
154 format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
155 m3u8_id
='hls', fatal
=False)
157 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
159 fmts
, subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
160 format_url
, video_id
, mpd_id
='dash', fatal
=False)
162 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
163 elif format_url
.endswith('.ism/Manifest'):
164 fmts
, subs
= self
._extract
_ism
_formats
_and
_subtitles
(
165 format_url
, video_id
, ism_id
='mss', fatal
=False)
167 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
169 mfs_path
= e
.get('Type')
170 mfs_info
= self
._MEDIA
_FILE
_SLOTS
.get(mfs_path
)
175 'format_id': 'http-' + mfs_path
.split('.')[0],
176 'width': mfs_info
['width'],
177 'height': mfs_info
['height'],
179 if not formats
and has_drm
:
180 self
.report_drm(video_id
)
181 self
._sort
_formats
(formats
)
183 description
= media
.get('Description')
184 duration
= int_or_none(media
.get(
185 'DurationInSeconds')) or parse_duration(media
.get('Duration'))
186 view_count
= int_or_none(media
.get('CountViews'))
187 average_rating
= float_or_none(media
.get('UserRating'))
188 age_limit
= parse_age_limit(media
.get('Rating'))
189 genre
= media
.get('Genre')
190 release_year
= int_or_none(media
.get('ReleaseYear'))
191 creator
= media
.get('Directors')
192 artist
= media
.get('Cast')
194 if media
.get('MediaTypeDisplayValue') == 'Full Episode':
195 series
= media
.get('ShowName')
197 season_number
= int_or_none(media
.get('Season'))
198 episode_number
= int_or_none(media
.get('Episode'))
200 series
= episode
= season_number
= episode_number
= None
202 cc_files
= media
.get('ClosedCaptionFiles')
203 if isinstance(cc_files
, list):
204 for cc_file
in cc_files
:
205 if not isinstance(cc_file
, dict):
207 cc_url
= url_or_none(cc_file
.get('Path'))
210 lang
= cc_file
.get('Locale') or 'en'
211 subtitles
.setdefault(lang
, []).append({'url': cc_url}
)
214 images
= media
.get('Images')
215 if isinstance(images
, list):
216 for image_key
, image_url
in images
.items():
217 mobj
= re
.search(r
'Img_(\d+)[xX](\d+)', image_key
)
222 'width': int(mobj
.group(1)),
223 'height': int(mobj
.group(2)),
229 'description': description
,
230 'duration': duration
,
231 'view_count': view_count
,
232 'average_rating': average_rating
,
233 'age_limit': age_limit
,
237 'release_year': release_year
,
240 'season_number': season_number
,
241 'episode_number': episode_number
,
242 'thumbnails': thumbnails
,
243 'subtitles': subtitles
,