]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/crackle.py
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,
51 def _real_extract(self
, url
):
52 video_id
= self
._match
_id
(url
)
54 country_code
= self
._downloader
.params
.get('geo_bypass_country', None)
55 countries
= [country_code
] if country_code
else (
56 'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI')
60 for country
in countries
:
62 media
= self
._download
_json
(
63 'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s'
64 % (video_id
, country
), video_id
,
65 'Downloading media JSON as %s' % country
,
66 'Unable to download media JSON', query
={
67 'disableProtocols': 'true',
70 except ExtractorError
as e
:
71 # 401 means geo restriction, trying next country
72 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
77 media_urls
= media
.get('MediaURLs')
78 if not media_urls
or not isinstance(media_urls
, list):
81 title
= media
['Title']
84 for e
in media
['MediaURLs']:
85 if e
.get('UseDRM') is True:
87 format_url
= url_or_none(e
.get('Path'))
90 ext
= determine_ext(format_url
)
92 formats
.extend(self
._extract
_m
3u8_formats
(
93 format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
94 m3u8_id
='hls', fatal
=False))
96 formats
.extend(self
._extract
_mpd
_formats
(
97 format_url
, video_id
, mpd_id
='dash', fatal
=False))
98 self
._sort
_formats
(formats
)
100 description
= media
.get('Description')
101 duration
= int_or_none(media
.get(
102 'DurationInSeconds')) or parse_duration(media
.get('Duration'))
103 view_count
= int_or_none(media
.get('CountViews'))
104 average_rating
= float_or_none(media
.get('UserRating'))
105 age_limit
= parse_age_limit(media
.get('Rating'))
106 genre
= media
.get('Genre')
107 release_year
= int_or_none(media
.get('ReleaseYear'))
108 creator
= media
.get('Directors')
109 artist
= media
.get('Cast')
111 if media
.get('MediaTypeDisplayValue') == 'Full Episode':
112 series
= media
.get('ShowName')
114 season_number
= int_or_none(media
.get('Season'))
115 episode_number
= int_or_none(media
.get('Episode'))
117 series
= episode
= season_number
= episode_number
= None
120 cc_files
= media
.get('ClosedCaptionFiles')
121 if isinstance(cc_files
, list):
122 for cc_file
in cc_files
:
123 if not isinstance(cc_file
, dict):
125 cc_url
= url_or_none(cc_file
.get('Path'))
128 lang
= cc_file
.get('Locale') or 'en'
129 subtitles
.setdefault(lang
, []).append({'url': cc_url
})
132 images
= media
.get('Images')
133 if isinstance(images
, list):
134 for image_key
, image_url
in images
.items():
135 mobj
= re
.search(r
'Img_(\d+)[xX](\d+)', image_key
)
140 'width': int(mobj
.group(1)),
141 'height': int(mobj
.group(2)),
147 'description': description
,
148 'duration': duration
,
149 'view_count': view_count
,
150 'average_rating': average_rating
,
151 'age_limit': age_limit
,
155 'release_year': release_year
,
158 'season_number': season_number
,
159 'episode_number': episode_number
,
160 'thumbnails': thumbnails
,
161 'subtitles': subtitles
,