6 from .common
import InfoExtractor
7 from ..networking
.exceptions
import HTTPError
20 class CrackleIE(InfoExtractor
):
21 _VALID_URL
= r
'(?:crackle:|https?://(?:(?:www|m)\.)?(?:sony)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
23 # Crackle is available in the United States and territories
24 'url': 'https://www.crackle.com/thanksgiving/2510064',
28 'title': 'Touch Football',
29 'description': 'md5:cfbb513cf5de41e8b56d7ab756cff4df',
35 'creator': 'Daniel Powell',
36 'artist': 'Chris Elliott, Amy Sedaris',
38 'series': 'Thanksgiving',
39 'episode': 'Touch Football',
45 'skip_download': True,
47 'expected_warnings': [
48 'Trying with a list of known countries',
51 'url': 'https://www.sonycrackle.com/thanksgiving/2510064',
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 f
'Unable to obtain video formats from {geo_bypass_country} API' 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(f
'{self.IE_NAME} identified country as {country}')
103 if country
in countries
:
104 self
.to_screen(f
'Downloading from {country} API was already attempted. Skipping...')
110 media
= self
._download
_json
(
111 f
'https://web-api-us.crackle.com/Service.svc/details/media/{video_id}/{country}?disableProtocols=true',
112 video_id
, note
=f
'Downloading media JSON from {country} API',
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
, HTTPError
) and e
.cause
.status
== 401:
120 status
= media
.get('status')
121 if status
.get('messageCode') != '0':
122 raise ExtractorError(
123 '{} said: {} {} - {}'.format(
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')
133 if not media
or (not media
.get('MediaURLs') and not ignore_no_formats
):
134 raise ExtractorError(
135 'Unable to access the crackle API. Try passing your country code '
136 'to --geo-bypass-country. If it still does not work and the '
137 'video is available in your country')
138 title
= media
['Title']
140 formats
, subtitles
= [], {}
142 for e
in media
.get('MediaURLs') or []:
145 format_url
= url_or_none(e
.get('DRMPath'))
147 format_url
= url_or_none(e
.get('Path'))
150 ext
= determine_ext(format_url
)
152 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
153 format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
154 m3u8_id
='hls', fatal
=False)
156 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
158 fmts
, subs
= self
._extract
_mpd
_formats
_and
_subtitles
(
159 format_url
, video_id
, mpd_id
='dash', fatal
=False)
161 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
162 elif format_url
.endswith('.ism/Manifest'):
163 fmts
, subs
= self
._extract
_ism
_formats
_and
_subtitles
(
164 format_url
, video_id
, ism_id
='mss', fatal
=False)
166 subtitles
= self
._merge
_subtitles
(subtitles
, subs
)
168 mfs_path
= e
.get('Type')
169 mfs_info
= self
._MEDIA
_FILE
_SLOTS
.get(mfs_path
)
174 'format_id': 'http-' + mfs_path
.split('.')[0],
175 'width': mfs_info
['width'],
176 'height': mfs_info
['height'],
178 if not formats
and has_drm
:
179 self
.report_drm(video_id
)
181 description
= media
.get('Description')
182 duration
= int_or_none(media
.get(
183 'DurationInSeconds')) or parse_duration(media
.get('Duration'))
184 view_count
= int_or_none(media
.get('CountViews'))
185 average_rating
= float_or_none(media
.get('UserRating'))
186 age_limit
= parse_age_limit(media
.get('Rating'))
187 genre
= media
.get('Genre')
188 release_year
= int_or_none(media
.get('ReleaseYear'))
189 creator
= media
.get('Directors')
190 artist
= media
.get('Cast')
192 if media
.get('MediaTypeDisplayValue') == 'Full Episode':
193 series
= media
.get('ShowName')
195 season_number
= int_or_none(media
.get('Season'))
196 episode_number
= int_or_none(media
.get('Episode'))
198 series
= episode
= season_number
= episode_number
= None
200 cc_files
= media
.get('ClosedCaptionFiles')
201 if isinstance(cc_files
, list):
202 for cc_file
in cc_files
:
203 if not isinstance(cc_file
, dict):
205 cc_url
= url_or_none(cc_file
.get('Path'))
208 lang
= cc_file
.get('Locale') or 'en'
209 subtitles
.setdefault(lang
, []).append({'url': cc_url
})
212 images
= media
.get('Images')
213 if isinstance(images
, list):
214 for image_key
, image_url
in images
.items():
215 mobj
= re
.search(r
'Img_(\d+)[xX](\d+)', image_key
)
220 'width': int(mobj
.group(1)),
221 'height': int(mobj
.group(2)),
227 'description': description
,
228 'duration': duration
,
229 'view_count': view_count
,
230 'average_rating': average_rating
,
231 'age_limit': age_limit
,
235 'release_year': release_year
,
238 'season_number': season_number
,
239 'episode_number': episode_number
,
240 'thumbnails': thumbnails
,
241 'subtitles': subtitles
,