mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-21 12:34:08 +00:00
[crackle] Bypass geo restriction
This commit is contained in:
parent
b9f5a41207
commit
7d34016fb0
@ -4,20 +4,24 @@ from __future__ import unicode_literals, division
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_str
|
from ..compat import (
|
||||||
|
compat_str,
|
||||||
|
compat_HTTPError,
|
||||||
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
determine_ext,
|
determine_ext,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
parse_age_limit,
|
parse_age_limit,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
|
ExtractorError
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CrackleIE(InfoExtractor):
|
class CrackleIE(InfoExtractor):
|
||||||
_GEO_COUNTRIES = ['US']
|
|
||||||
_VALID_URL = r'(?:crackle:|https?://(?:(?:www|m)\.)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
|
_VALID_URL = r'(?:crackle:|https?://(?:(?:www|m)\.)?crackle\.com/(?:playlist/\d+/|(?:[^/]+/)+))(?P<id>\d+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
|
# geo restricted to CA
|
||||||
'url': 'https://www.crackle.com/andromeda/2502343',
|
'url': 'https://www.crackle.com/andromeda/2502343',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '2502343',
|
'id': '2502343',
|
||||||
@ -46,12 +50,32 @@ class CrackleIE(InfoExtractor):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
|
country_code = self._downloader.params.get('geo_bypass_country', None)
|
||||||
|
countries = [country_code] if country_code else (
|
||||||
|
'US', 'AU', 'CA', 'AS', 'FM', 'GU', 'MP', 'PR', 'PW', 'MH', 'VI')
|
||||||
|
|
||||||
|
last_e = None
|
||||||
|
|
||||||
|
for country in countries:
|
||||||
|
try:
|
||||||
media = self._download_json(
|
media = self._download_json(
|
||||||
'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s'
|
'https://web-api-us.crackle.com/Service.svc/details/media/%s/%s'
|
||||||
% (video_id, self._GEO_COUNTRIES[0]), video_id, query={
|
% (video_id, country), video_id,
|
||||||
|
'Downloading media JSON as %s' % country,
|
||||||
|
'Unable to download media JSON', query={
|
||||||
'disableProtocols': 'true',
|
'disableProtocols': 'true',
|
||||||
'format': 'json'
|
'format': 'json'
|
||||||
})
|
})
|
||||||
|
except ExtractorError as e:
|
||||||
|
# 401 means geo restriction, trying next country
|
||||||
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
|
||||||
|
last_e = e
|
||||||
|
continue
|
||||||
|
raise
|
||||||
|
|
||||||
|
media_urls = media.get('MediaURLs')
|
||||||
|
if not media_urls or not isinstance(media_urls, list):
|
||||||
|
continue
|
||||||
|
|
||||||
title = media['Title']
|
title = media['Title']
|
||||||
|
|
||||||
@ -136,3 +160,5 @@ class CrackleIE(InfoExtractor):
|
|||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise last_e
|
||||||
|
Loading…
Reference in New Issue
Block a user