]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/crackle.py
2 from __future__
import unicode_literals
, division
6 from .common
import InfoExtractor
21 class CrackleIE(InfoExtractor
):
22 _VALID_URL
= r
'(?:crackle:|https?://(?:(?:www|m)\.)?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,
50 def _real_extract(self
, url
):
51 video_id
= self
._match
_id
(url
)
53 country_code
= self
._downloader
.params
.get('geo_bypass_country', None)
54 countries
= [country_code
] if country_code
else (
55 'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI')
59 for country
in countries
:
61 media
= self
._download
_json
(
62 'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s'
63 % (video_id
, country
), video_id
,
64 'Downloading media JSON as %s' % country
,
65 'Unable to download media JSON', query
={
66 'disableProtocols': 'true',
69 except ExtractorError
as e
:
70 # 401 means geo restriction, trying next country
71 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
76 media_urls
= media
.get('MediaURLs')
77 if not media_urls
or not isinstance(media_urls
, list):
80 title
= media
['Title']
83 for e
in media
['MediaURLs']:
84 if e
.get('UseDRM') is True:
86 format_url
= e
.get('Path')
87 if not format_url
or not isinstance(format_url
, compat_str
):
89 ext
= determine_ext(format_url
)
91 formats
.extend(self
._extract
_m
3u8_formats
(
92 format_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
93 m3u8_id
='hls', fatal
=False))
95 formats
.extend(self
._extract
_mpd
_formats
(
96 format_url
, video_id
, mpd_id
='dash', fatal
=False))
97 self
._sort
_formats
(formats
)
99 description
= media
.get('Description')
100 duration
= int_or_none(media
.get(
101 'DurationInSeconds')) or parse_duration(media
.get('Duration'))
102 view_count
= int_or_none(media
.get('CountViews'))
103 average_rating
= float_or_none(media
.get('UserRating'))
104 age_limit
= parse_age_limit(media
.get('Rating'))
105 genre
= media
.get('Genre')
106 release_year
= int_or_none(media
.get('ReleaseYear'))
107 creator
= media
.get('Directors')
108 artist
= media
.get('Cast')
110 if media
.get('MediaTypeDisplayValue') == 'Full Episode':
111 series
= media
.get('ShowName')
113 season_number
= int_or_none(media
.get('Season'))
114 episode_number
= int_or_none(media
.get('Episode'))
116 series
= episode
= season_number
= episode_number
= None
119 cc_files
= media
.get('ClosedCaptionFiles')
120 if isinstance(cc_files
, list):
121 for cc_file
in cc_files
:
122 if not isinstance(cc_file
, dict):
124 cc_url
= cc_file
.get('Path')
125 if not cc_url
or not isinstance(cc_url
, compat_str
):
127 lang
= cc_file
.get('Locale') or 'en'
128 subtitles
.setdefault(lang
, []).append({'url': cc_url
})
131 images
= media
.get('Images')
132 if isinstance(images
, list):
133 for image_key
, image_url
in images
.items():
134 mobj
= re
.search(r
'Img_(\d+)[xX](\d+)', image_key
)
139 'width': int(mobj
.group(1)),
140 'height': int(mobj
.group(2)),
146 'description': description
,
147 'duration': duration
,
148 'view_count': view_count
,
149 'average_rating': average_rating
,
150 'age_limit': age_limit
,
154 'release_year': release_year
,
157 'season_number': season_number
,
158 'episode_number': episode_number
,
159 'thumbnails': thumbnails
,
160 'subtitles': subtitles
,