2 from __future__ import unicode_literals, division
6 from .common import InfoExtractor
21 class CrackleIE(InfoExtractor):
22 _VALID_URL = r'(?:crackle:|https?://(?:(?:www|m)\.)?(?:sony)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
24 # geo restricted to CA
25 'url': 'https://www.crackle.com/andromeda/2502343',
29 'title': 'Under The Night',
30 'description': 'md5:d2b8ca816579ae8a7bf28bfff8cefc8a',
35 'genre': 'Action, Sci-Fi',
36 'creator': 'Allan Kroeker',
37 'artist': 'Keith Hamilton Cobb, Kevin Sorbo, Lisa Ryder, Lexa Doig, Robert Hewitt Wolfe',
39 'series': 'Andromeda',
40 'episode': 'Under The Night',
46 'skip_download': True,
49 'url': 'https://www.sonycrackle.com/andromeda/2502343',
50 'only_matching': True,
53 def _real_extract(self, url):
54 video_id = self._match_id(url)
56 country_code = self._downloader.params.get('geo_bypass_country', None)
57 countries = [country_code] if country_code else (
58 'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI')
62 for country in countries:
64 media = self._download_json(
65 'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s'
66 % (video_id, country), video_id,
67 'Downloading media JSON as %s' % country,
68 'Unable to download media JSON', query={
69 'disableProtocols': 'true',
72 except ExtractorError as e:
73 # 401 means geo restriction, trying next country
74 if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
79 media_urls = media.get('MediaURLs')
80 if not media_urls or not isinstance(media_urls, list):
83 title = media['Title']
86 for e in media['MediaURLs']:
87 if e.get('UseDRM') is True:
89 format_url = e.get('Path')
90 if not format_url or not isinstance(format_url, compat_str):
92 ext = determine_ext(format_url)
94 formats.extend(self._extract_m3u8_formats(
95 format_url, video_id, 'mp4', entry_protocol='m3u8_native',
96 m3u8_id='hls', fatal=False))
98 formats.extend(self._extract_mpd_formats(
99 format_url, video_id, mpd_id='dash', fatal=False))
100 self._sort_formats(formats)
102 description = media.get('Description')
103 duration = int_or_none(media.get(
104 'DurationInSeconds')) or parse_duration(media.get('Duration'))
105 view_count = int_or_none(media.get('CountViews'))
106 average_rating = float_or_none(media.get('UserRating'))
107 age_limit = parse_age_limit(media.get('Rating'))
108 genre = media.get('Genre')
109 release_year = int_or_none(media.get('ReleaseYear'))
110 creator = media.get('Directors')
111 artist = media.get('Cast')
113 if media.get('MediaTypeDisplayValue') == 'Full Episode':
114 series = media.get('ShowName')
116 season_number = int_or_none(media.get('Season'))
117 episode_number = int_or_none(media.get('Episode'))
119 series = episode = season_number = episode_number = None
122 cc_files = media.get('ClosedCaptionFiles')
123 if isinstance(cc_files, list):
124 for cc_file in cc_files:
125 if not isinstance(cc_file, dict):
127 cc_url = cc_file.get('Path')
128 if not cc_url or not isinstance(cc_url, compat_str):
130 lang = cc_file.get('Locale') or 'en'
131 subtitles.setdefault(lang, []).append({'url': cc_url})
134 images = media.get('Images')
135 if isinstance(images, list):
136 for image_key, image_url in images.items():
137 mobj = re.search(r'Img_(\d+)[xX](\d+)', image_key)
142 'width': int(mobj.group(1)),
143 'height': int(mobj.group(2)),
149 'description': description,
150 'duration': duration,
151 'view_count': view_count,
152 'average_rating': average_rating,
153 'age_limit': age_limit,
157 'release_year': release_year,
160 'season_number': season_number,
161 'episode_number': episode_number,
162 'thumbnails': thumbnails,
163 'subtitles': subtitles,