mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-01-31 09:41:18 +02:00
[ie/francetv:site] Fix extractor (#12236)
Closes #12209 Authored by: bashonly
This commit is contained in:
parent
861aeec449
commit
817483ccc6
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import re
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
@ -5,6 +6,7 @@ from .common import InfoExtractor
|
|||||||
from .dailymotion import DailymotionIE
|
from .dailymotion import DailymotionIE
|
||||||
from ..networking import HEADRequest
|
from ..networking import HEADRequest
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
|
ExtractorError,
|
||||||
clean_html,
|
clean_html,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
filter_dict,
|
filter_dict,
|
||||||
@ -29,6 +31,7 @@ class FranceTVBaseInfoExtractor(InfoExtractor):
|
|||||||
|
|
||||||
|
|
||||||
class FranceTVIE(InfoExtractor):
|
class FranceTVIE(InfoExtractor):
|
||||||
|
IE_NAME = 'francetv'
|
||||||
_VALID_URL = r'francetv:(?P<id>[^@#]+)'
|
_VALID_URL = r'francetv:(?P<id>[^@#]+)'
|
||||||
_GEO_COUNTRIES = ['FR']
|
_GEO_COUNTRIES = ['FR']
|
||||||
_GEO_BYPASS = False
|
_GEO_BYPASS = False
|
||||||
@ -248,18 +251,19 @@ class FranceTVIE(InfoExtractor):
|
|||||||
|
|
||||||
|
|
||||||
class FranceTVSiteIE(FranceTVBaseInfoExtractor):
|
class FranceTVSiteIE(FranceTVBaseInfoExtractor):
|
||||||
|
IE_NAME = 'francetv:site'
|
||||||
_VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
|
_VALID_URL = r'https?://(?:(?:www\.)?france\.tv|mobile\.france\.tv)/(?:[^/]+/)*(?P<id>[^/]+)\.html'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
|
'url': 'https://www.france.tv/france-2/13h15-le-dimanche/140921-les-mysteres-de-jesus.html',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'c5bda21d-2c6f-4470-8849-3d8327adb2ba',
|
'id': 'ec217ecc-0733-48cf-ac06-af1347b849d1', # old: c5bda21d-2c6f-4470-8849-3d8327adb2ba'
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': '13h15, le dimanche... - Les mystères de Jésus',
|
'title': '13h15, le dimanche... - Les mystères de Jésus',
|
||||||
'timestamp': 1514118300,
|
'timestamp': 1502623500,
|
||||||
'duration': 2880,
|
'duration': 2580,
|
||||||
'thumbnail': r're:^https?://.*\.jpg$',
|
'thumbnail': r're:^https?://.*\.jpg$',
|
||||||
'upload_date': '20171224',
|
'upload_date': '20170813',
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'skip_download': True,
|
'skip_download': True,
|
||||||
@ -282,6 +286,7 @@ class FranceTVSiteIE(FranceTVBaseInfoExtractor):
|
|||||||
'thumbnail': r're:^https?://.*\.jpg$',
|
'thumbnail': r're:^https?://.*\.jpg$',
|
||||||
'duration': 1441,
|
'duration': 1441,
|
||||||
},
|
},
|
||||||
|
'skip': 'No longer available',
|
||||||
}, {
|
}, {
|
||||||
# geo-restricted livestream (workflow == 'token-akamai')
|
# geo-restricted livestream (workflow == 'token-akamai')
|
||||||
'url': 'https://www.france.tv/france-4/direct.html',
|
'url': 'https://www.france.tv/france-4/direct.html',
|
||||||
@ -336,19 +341,32 @@ class FranceTVSiteIE(FranceTVBaseInfoExtractor):
|
|||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
# XXX: For parsing next.js v15+ data; see also yt_dlp.extractor.goplay
|
||||||
|
def _find_json(self, s):
|
||||||
|
return self._search_json(
|
||||||
|
r'\w+\s*:\s*', s, 'next js data', None, contains_pattern=r'\[(?s:.+)\]', default=None)
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
display_id = self._match_id(url)
|
||||||
|
|
||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
|
||||||
video_id = self._search_regex(
|
nextjs_data = traverse_obj(
|
||||||
r'(?:data-main-video\s*=|videoId["\']?\s*[:=])\s*(["\'])(?P<id>(?:(?!\1).)+)\1',
|
re.findall(r'<script[^>]*>\s*self\.__next_f\.push\(\s*(\[.+?\])\s*\);?\s*</script>', webpage),
|
||||||
webpage, 'video id', default=None, group='id')
|
(..., {json.loads}, ..., {self._find_json}, ..., 'children', ..., ..., 'children', ..., ..., 'children'))
|
||||||
|
|
||||||
|
if traverse_obj(nextjs_data, (..., ..., 'children', ..., 'isLive', {bool}, any)):
|
||||||
|
# For livestreams we need the id of the stream instead of the currently airing episode id
|
||||||
|
video_id = traverse_obj(nextjs_data, (
|
||||||
|
..., ..., 'children', ..., 'children', ..., 'children', ..., 'children', ..., ...,
|
||||||
|
'children', ..., ..., 'children', ..., ..., 'children', ..., 'options', 'id', {str}, any))
|
||||||
|
else:
|
||||||
|
video_id = traverse_obj(nextjs_data, (
|
||||||
|
..., ..., ..., 'children',
|
||||||
|
lambda _, v: v['video']['url'] == urllib.parse.urlparse(url).path,
|
||||||
|
'video', ('playerReplayId', 'siId'), {str}, any))
|
||||||
|
|
||||||
if not video_id:
|
if not video_id:
|
||||||
video_id = self._html_search_regex(
|
raise ExtractorError('Unable to extract video ID')
|
||||||
r'(?:href=|player\.setVideo\(\s*)"http://videos?\.francetv\.fr/video/([^@"]+@[^"]+)"',
|
|
||||||
webpage, 'video ID')
|
|
||||||
|
|
||||||
return self._make_url_result(video_id, url=url)
|
return self._make_url_result(video_id, url=url)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user