mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-22 20:20:09 +09:00
added error handling for geo-restriction
This commit is contained in:
parent
82523cd573
commit
acea8f31d4
@ -4,15 +4,17 @@ from __future__ import unicode_literals
|
|||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
extract_attributes,
|
clean_html,
|
||||||
int_or_none,
|
try_get,
|
||||||
traverse_obj
|
|
||||||
)
|
)
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
|
|
||||||
class CanalrcnIE(InfoExtractor):
|
class CanalrcnIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?canalrcn\.com/(?:[^/]+/)+(?P<id>[^/?&#]+)'
|
_VALID_URL = r'https?://(?:www\.)?canalrcn\.com/(?:[^/]+/)+(?P<id>[^/?&#]+)'
|
||||||
|
|
||||||
|
# Specify geo-restriction
|
||||||
|
_GEO_COUNTRIES = ['CO']
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.canalrcn.com/la-rosa-de-guadalupe/capitulos/la-rosa-de-guadalupe-capitulo-58-los-enamorados-3619',
|
'url': 'https://www.canalrcn.com/la-rosa-de-guadalupe/capitulos/la-rosa-de-guadalupe-capitulo-58-los-enamorados-3619',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
@ -25,14 +27,14 @@ class CanalrcnIE(InfoExtractor):
|
|||||||
'params': {
|
'params': {
|
||||||
'skip_download': True,
|
'skip_download': True,
|
||||||
},
|
},
|
||||||
'skip': 'Geo-restricted to Colombia',
|
'expected_warnings': ['Video is geo-restricted to Colombia'],
|
||||||
|
'skip': 'Geo-restricted to Colombia'
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
# Extract JSON-LD data
|
|
||||||
json_ld = self._search_regex(
|
json_ld = self._search_regex(
|
||||||
r'<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json>[^<]+)</script>',
|
r'<script[^>]+type=(["\'])application/ld\+json\1[^>]*>(?P<json>[^<]+)</script>',
|
||||||
webpage, 'JSON-LD', group='json', default='{}')
|
webpage, 'JSON-LD', group='json', default='{}')
|
||||||
@ -42,7 +44,6 @@ class CanalrcnIE(InfoExtractor):
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
raise ExtractorError('Could not parse JSON-LD data')
|
raise ExtractorError('Could not parse JSON-LD data')
|
||||||
|
|
||||||
# Find the VideoObject in the JSON-LD array
|
|
||||||
video_data = None
|
video_data = None
|
||||||
if isinstance(json_data, list):
|
if isinstance(json_data, list):
|
||||||
for item in json_data:
|
for item in json_data:
|
||||||
@ -53,20 +54,21 @@ class CanalrcnIE(InfoExtractor):
|
|||||||
if not video_data:
|
if not video_data:
|
||||||
raise ExtractorError('Could not find video information in JSON-LD data')
|
raise ExtractorError('Could not find video information in JSON-LD data')
|
||||||
|
|
||||||
# Extract player information
|
embed_url = video_data.get('embedUrl')
|
||||||
player_match = re.search(r'dailymotion\.createPlayer\("([^"]+)",\s*{([^}]+)}', webpage)
|
if not embed_url:
|
||||||
if not player_match:
|
raise ExtractorError('Could not find video embed URL')
|
||||||
raise ExtractorError('Could not find player configuration')
|
|
||||||
|
|
||||||
player_config = player_match.group(2)
|
dailymotion_id = self._search_regex(
|
||||||
video_url_match = re.search(r'video:\s*["\']([^"\']+)', player_config)
|
r'dailymotion\.com/(?:embed/)?video/([a-zA-Z0-9]+)',
|
||||||
if not video_url_match:
|
embed_url,
|
||||||
raise ExtractorError('Could not find video URL')
|
'dailymotion id'
|
||||||
|
)
|
||||||
dailymotion_id = video_url_match.group(1).split('&&')[0]
|
|
||||||
|
#geo-restriction handling
|
||||||
# Configure geo-bypass headers
|
self.raise_geo_restricted(
|
||||||
self._downloader.params['geo_verification_proxy'] = 'co'
|
msg='This video is only available in Colombia',
|
||||||
|
countries=self._GEO_COUNTRIES
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'_type': 'url_transparent',
|
'_type': 'url_transparent',
|
||||||
@ -77,5 +79,4 @@ class CanalrcnIE(InfoExtractor):
|
|||||||
'description': video_data.get('description'),
|
'description': video_data.get('description'),
|
||||||
'thumbnail': video_data.get('thumbnailUrl'),
|
'thumbnail': video_data.get('thumbnailUrl'),
|
||||||
'duration': video_data.get('duration'),
|
'duration': video_data.get('duration'),
|
||||||
'note': 'Video is geo-restricted to Colombia',
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user