Compare commits

...

2 Commits

Author SHA1 Message Date
bashonly
942aaf9c29
add geo-restriction error handling
Authored by: bashonly
2025-05-03 09:29:19 -05:00
bashonly
d701a5d20d
wtf is this garbage? be gone
Authored by: bashonly
2025-05-03 09:07:20 -05:00

View File

@ -4,6 +4,7 @@ import re
from .common import InfoExtractor
from ..networking import HEADRequest
from ..networking.exceptions import HTTPError
from ..utils import (
ExtractorError,
OnDemandPagedList,
@ -92,28 +93,6 @@ class BitChuteIE(InfoExtractor):
'timestamp': 1542130287,
},
'params': {'check_formats': None},
}, {
# restricted video
'url': 'https://www.bitchute.com/video/WEnQU7XGcTdl/',
'info_dict': {
'id': 'WEnQU7XGcTdl',
'ext': 'mp4',
'title': 'Impartial Truth - Ein Letzter Appell an die Vernunft',
'description': 'md5:e7e8390ab79d2c84f3f5d068ed333535',
'uploader': 'Freier_Mann',
'uploader_id': 'OBhKX1Ss0jyL',
'uploader_url': 'https://www.bitchute.com/profile/OBhKX1Ss0jyL/',
'channel': 'Der Freie',
'channel_id': 'dV8xxWKIxSVU',
'channel_url': 'https://www.bitchute.com/channel/freier_mann/',
'view_count': int,
'duration': 4806.0,
'thumbnail': r're:https?://.+/.+\.jpg$',
'timestamp': 1609918804,
'upload_date': '20210106',
},
'params': {'skip_download': True},
'skip': 'Georestricted in DE',
}, {
'url': 'https://www.bitchute.com/embed/lbb5G1hjPhw/',
'only_matching': True,
@ -149,15 +128,25 @@ class BitChuteIE(InfoExtractor):
def _call_api(self, endpoint, data, display_id, fatal=True):
note = endpoint.rpartition('/')[2]
# TODO: Add error handling for geo-restriction
try:
return self._download_json(
f'https://api.bitchute.com/api/beta/{endpoint}', display_id,
f'Downloading {note} API JSON', f'Unable to download {note} API JSON',
fatal=fatal, data=json.dumps(data).encode(),
data=json.dumps(data).encode(),
headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
})
except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 403:
errors = '. '.join(traverse_obj(e.cause.response.read().decode(), (
{json.loads}, 'errors', lambda _, v: v['context'] == 'reason', 'message', {str})))
if errors and 'location' in errors:
# Can always be fatal since the video/media call will reach this code first
self.raise_geo_restricted(errors)
if fatal:
raise
self.report_warning(e.msg)
def _real_extract(self, url):
video_id = self._match_id(url)