mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-27 02:16:51 +01:00
[fox] detect geo restriction and authentication errors(#20208)
This commit is contained in:
parent
10734553fe
commit
0d08bcdb70
@ -6,10 +6,12 @@ import uuid
|
||||
|
||||
from .adobepass import AdobePassIE
|
||||
from ..compat import (
|
||||
compat_HTTPError,
|
||||
compat_str,
|
||||
compat_urllib_parse_unquote,
|
||||
)
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
int_or_none,
|
||||
parse_age_limit,
|
||||
parse_duration,
|
||||
@ -48,6 +50,7 @@ class FOXIE(AdobePassIE):
|
||||
'url': 'https://www.fox.com/watch/30056b295fb57f7452aeeb4920bc3024/',
|
||||
'only_matching': True,
|
||||
}]
|
||||
_GEO_BYPASS = False
|
||||
_HOME_PAGE_URL = 'https://www.fox.com/'
|
||||
_API_KEY = 'abdcbed02c124d393b39e818a4312055'
|
||||
_access_token = None
|
||||
@ -58,9 +61,22 @@ class FOXIE(AdobePassIE):
|
||||
}
|
||||
if self._access_token:
|
||||
headers['Authorization'] = 'Bearer ' + self._access_token
|
||||
try:
|
||||
return self._download_json(
|
||||
'https://api2.fox.com/v2.0/' + path,
|
||||
video_id, data=data, headers=headers)
|
||||
except ExtractorError as e:
|
||||
if isinstance(e.cause, compat_HTTPError) and e.cause.status == 403:
|
||||
entitlement_issues = self._parse_json(
|
||||
e.cause.read().decode(), video_id)['entitlementIssues']
|
||||
for e in entitlement_issues:
|
||||
if e.get('errorCode') == 1005:
|
||||
raise ExtractorError(
|
||||
'This video is only available via cable service provider '
|
||||
'subscription. You may want to use --cookies.', expected=True)
|
||||
messages = ', '.join([e['message'] for e in entitlement_issues])
|
||||
raise ExtractorError(messages, expected=True)
|
||||
raise
|
||||
|
||||
def _real_initialize(self):
|
||||
if not self._access_token:
|
||||
@ -81,7 +97,15 @@ class FOXIE(AdobePassIE):
|
||||
|
||||
title = video['name']
|
||||
release_url = video['url']
|
||||
try:
|
||||
m3u8_url = self._download_json(release_url, video_id)['playURL']
|
||||
except ExtractorError as e:
|
||||
if isinstance(e.cause, compat_HTTPError) and e.cause.status == 403:
|
||||
error = self._parse_json(e.cause.read().decode(), video_id)
|
||||
if error.get('exception') == 'GeoLocationBlocked':
|
||||
self.raise_geo_restricted(countries=['US'])
|
||||
raise ExtractorError(error['description'], expected=True)
|
||||
raise
|
||||
formats = self._extract_m3u8_formats(
|
||||
m3u8_url, video_id, 'mp4',
|
||||
entry_protocol='m3u8_native', m3u8_id='hls')
|
||||
|
Loading…
Reference in New Issue
Block a user