]>
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 # Crackle is available in the United States and territories
27 'url': 'https://www.crackle.com/thanksgiving/2510064',
31 'title': 'Touch Football',
32 'description': 'md5:cfbb513cf5de41e8b56d7ab756cff4df',
38 'creator': 'Daniel Powell',
39 'artist': 'Chris Elliott, Amy Sedaris',
41 'series': 'Thanksgiving',
42 'episode': 'Touch Football',
48 'skip_download': True,
50 'expected_warnings': [
51 'Trying with a list of known countries'
54 'url': 'https://www.sonycrackle.com/thanksgiving/2510064',
55 'only_matching': True,
73 def _download_json(self
, url
, *args
, **kwargs
):
74 # Authorization generation algorithm is reverse engineered from:
75 # https://www.sonycrackle.com/static/js/main.ea93451f.chunk.js
76 timestamp
= time
.strftime('%Y%m%d%H%M', time
.gmtime())
77 h
= hmac
.new(b
'IGSLUQCBDFHEOIFM', '|'.join([url
, timestamp
]).encode(), hashlib
.sha1
).hexdigest().upper()
79 'Accept': 'application/json',
80 'Authorization': '|'.join([h
, timestamp
, '117', '1']),
82 return InfoExtractor
._download
_json
(self
, url
, *args
, headers
=headers
, **kwargs
)
84 def _real_extract(self
, url
):
85 video_id
= self
._match
_id
(url
)
87 geo_bypass_country
= self
.get_param('geo_bypass_country', None)
88 countries
= orderedSet((geo_bypass_country
, 'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI', ''))
89 num_countries
, num
= len(countries
) - 1, 0
92 for num
, country
in enumerate(countries
):
93 if num
== 1: # start hard-coded list
94 self
.report_warning('%s. Trying with a list of known countries' % (
95 'Unable to obtain video formats from %s API' % geo_bypass_country
if geo_bypass_country
96 else 'No country code was given using --geo-bypass-country'))
97 elif num
== num_countries
: # end of list
98 geo_info
= self
._download
_json
(
99 'https://web-api-us.crackle.com/Service.svc/geo/country',
100 video_id
, fatal
=False, note
='Downloading geo-location information from crackle API',
101 errnote
='Unable to fetch geo-location information from crackle') or {}
102 country
= geo_info
.get('CountryCode')
105 self
.to_screen('%s identified country as %s' % (self
.IE_NAME
, country
))
106 if country
in countries
:
107 self
.to_screen('Downloading from %s API was already attempted. Skipping...' % country
)
113 media
= self
._download
_json
(
114 'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s?disableProtocols=true' % (video_id
, country
),
115 video_id
, note
='Downloading media JSON from %s API' % country
,
116 errnote
='Unable to download media JSON')
117 except ExtractorError
as e
:
118 # 401 means geo restriction, trying next country
119 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
123 status
= media
.get('status')
124 if status
.get('messageCode') != '0':
125 raise ExtractorError(
126 '%s said: %s %s - %s' % (
127 self
.IE_NAME
, status
.get('messageCodeDescription'), status
.get('messageCode'), status
.get('message')),
130 # Found video formats
131 if isinstance(media
.get('MediaURLs'), list):
134 ignore_no_formats
= self
.get_param('ignore_no_formats_error')
136 if not media
or (not media
.get('MediaURLs') and not ignore_no_formats
):
137 raise ExtractorError(
138 'Unable to access the crackle API. Try passing your country code '
139 'to --geo-bypass-country. If it still does not work and the '
140 'video is available in your country')
141 title
= media
['Title']
143 formats
, subtitles
= [], {}
145 for e
in media
.get('MediaURLs') or []:
148 format_url
= url_or_none(e
.get('DRMPath'))
150 format_url
= url_or_none(e
.get('Path'))
153 ext
= determine_ext(format_url
)
155 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
156 format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
157 m3u8_id
='hls', fatal
=False)
159 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
161 fmts
, subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
162 format_url
, video_id
, mpd_id
='dash', fatal
=False)
164 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
165 elif format_url
.endswith('.ism/Manifest'):
166 fmts
, subs
= self
._extract
_ism
_formats
_and
_subtitles
(
167 format_url
, video_id
, ism_id
='mss', fatal
=False)
169 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
171 mfs_path
= e
.get('Type')
172 mfs_info
= self
._MEDIA
_FILE
_SLOTS
.get(mfs_path
)
177 'format_id': 'http-' + mfs_path
.split('.')[0],
178 'width': mfs_info
['width'],
179 'height': mfs_info
['height'],
181 if not formats
and has_drm
:
182 self
.report_drm(video_id
)
183 self
._sort
_formats
(formats
)
185 description
= media
.get('Description')
186 duration
= int_or_none(media
.get(
187 'DurationInSeconds')) or parse_duration(media
.get('Duration'))
188 view_count
= int_or_none(media
.get('CountViews'))
189 average_rating
= float_or_none(media
.get('UserRating'))
190 age_limit
= parse_age_limit(media
.get('Rating'))
191 genre
= media
.get('Genre')
192 release_year
= int_or_none(media
.get('ReleaseYear'))
193 creator
= media
.get('Directors')
194 artist
= media
.get('Cast')
196 if media
.get('MediaTypeDisplayValue') == 'Full Episode':
197 series
= media
.get('ShowName')
199 season_number
= int_or_none(media
.get('Season'))
200 episode_number
= int_or_none(media
.get('Episode'))
202 series
= episode
= season_number
= episode_number
= None
204 cc_files
= media
.get('ClosedCaptionFiles')
205 if isinstance(cc_files
, list):
206 for cc_file
in cc_files
:
207 if not isinstance(cc_file
, dict):
209 cc_url
= url_or_none(cc_file
.get('Path'))
212 lang
= cc_file
.get('Locale') or 'en'
213 subtitles
.setdefault(lang
, []).append({'url': cc_url}
)
216 images
= media
.get('Images')
217 if isinstance(images
, list):
218 for image_key
, image_url
in images
.items():
219 mobj
= re
.search(r
'Img_(\d+)[xX](\d+)', image_key
)
224 'width': int(mobj
.group(1)),
225 'height': int(mobj
.group(2)),
231 'description': description
,
232 'duration': duration
,
233 'view_count': view_count
,
234 'average_rating': average_rating
,
235 'age_limit': age_limit
,
239 'release_year': release_year
,
242 'season_number': season_number
,
243 'episode_number': episode_number
,
244 'thumbnails': thumbnails
,
245 'subtitles': subtitles
,