[orf:tvthek] Lazy playlist extraction and obey --no-playlist

Closes #2411
This commit is contained in:
pukkandan 2022-01-23 23:26:55 +05:30
parent 6a5a30f9e2
commit b695e3f9bd
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698
1 changed files with 126 additions and 100 deletions

View File

@ -1,33 +1,68 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import functools
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import ( from ..utils import (
clean_html, clean_html,
determine_ext, determine_ext,
float_or_none, float_or_none,
HEADRequest, HEADRequest,
InAdvancePagedList,
int_or_none, int_or_none,
join_nonempty, join_nonempty,
orderedSet, orderedSet,
remove_end, remove_end,
smuggle_url,
str_or_none, str_or_none,
strip_jsonp, strip_jsonp,
unescapeHTML, unescapeHTML,
unified_strdate, unified_strdate,
unsmuggle_url,
url_or_none, url_or_none,
urljoin,
) )
class ORFTVthekIE(InfoExtractor): class ORFTVthekIE(InfoExtractor):
IE_NAME = 'orf:tvthek' IE_NAME = 'orf:tvthek'
IE_DESC = 'ORF TVthek' IE_DESC = 'ORF TVthek'
_VALID_URL = r'https?://tvthek\.orf\.at/(?:[^/]+/)+(?P<id>\d+)' _VALID_URL = r'(?P<url>https?://tvthek\.orf\.at/(?:(?:[^/]+/){2}){1,2}(?P<id>\d+))(/[^/]+/(?P<vid>\d+))?(?:$|[?#])'
_TESTS = [{ _TESTS = [{
'url': 'https://tvthek.orf.at/profile/ZIB-2/1211/ZIB-2/14121079',
'info_dict': {
'id': '14121079',
},
'playlist_count': 11,
'params': {'noplaylist': True}
}, {
'url': 'https://tvthek.orf.at/profile/ZIB-2/1211/ZIB-2/14121079/Umfrage-Welches-Tier-ist-Sebastian-Kurz/15083150',
'info_dict': {
'id': '14121079',
},
'playlist_count': 1,
'params': {'playlist_items': '5'}
}, {
'url': 'https://tvthek.orf.at/profile/ZIB-2/1211/ZIB-2/14121079/Umfrage-Welches-Tier-ist-Sebastian-Kurz/15083150',
'info_dict': {
'id': '14121079',
'playlist_count': 1
},
'playlist': [{
'info_dict': {
'id': '15083150',
'ext': 'mp4',
'description': 'md5:7be1c485425f5f255a5e4e4815e77d04',
'thumbnail': 'https://api-tvthek.orf.at/uploads/media/segments/0130/59/824271ea35cd8931a0fb08ab316a5b0a1562342c.jpeg',
'title': 'Umfrage: Welches Tier ist Sebastian Kurz?',
}
}],
'playlist_count': 1,
'params': {'noplaylist': True, 'skip_download': 'm3u8'}
}, {
'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389', 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389',
'playlist': [{ 'playlist': [{
'md5': '2942210346ed779588f428a92db88712', 'md5': '2942210346ed779588f428a92db88712',
@ -62,22 +97,9 @@ class ORFTVthekIE(InfoExtractor):
'only_matching': True, 'only_matching': True,
}] }]
def _real_extract(self, url): def _pagefunc(self, url, data_jsb, n, *, image=None):
playlist_id = self._match_id(url) sd = data_jsb[n]
webpage = self._download_webpage(url, playlist_id) video_id, title = str(sd['id']), sd['title']
data_jsb = self._parse_json(
self._search_regex(
r'<div[^>]+class=(["\']).*?VideoPlaylist.*?\1[^>]+data-jsb=(["\'])(?P<json>.+?)\2',
webpage, 'playlist', group='json'),
playlist_id, transform_source=unescapeHTML)['playlist']['videos']
entries = []
for sd in data_jsb:
video_id, title = sd.get('id'), sd.get('title')
if not video_id or not title:
continue
video_id = compat_str(video_id)
formats = [] formats = []
for fd in sd['sources']: for fd in sd['sources']:
src = url_or_none(fd.get('src')) src = url_or_none(fd.get('src'))
@ -87,7 +109,7 @@ class ORFTVthekIE(InfoExtractor):
ext = determine_ext(src) ext = determine_ext(src)
if ext == 'm3u8': if ext == 'm3u8':
m3u8_formats = self._extract_m3u8_formats( m3u8_formats = self._extract_m3u8_formats(
src, video_id, 'mp4', m3u8_id=format_id, fatal=False) src, video_id, 'mp4', m3u8_id=format_id, fatal=False, note=f'Downloading {format_id} m3u8 manifest')
if any('/geoprotection' in f['url'] for f in m3u8_formats): if any('/geoprotection' in f['url'] for f in m3u8_formats):
self.raise_geo_restricted() self.raise_geo_restricted()
formats.extend(m3u8_formats) formats.extend(m3u8_formats)
@ -96,7 +118,7 @@ class ORFTVthekIE(InfoExtractor):
src, video_id, f4m_id=format_id, fatal=False)) src, video_id, f4m_id=format_id, fatal=False))
elif ext == 'mpd': elif ext == 'mpd':
formats.extend(self._extract_mpd_formats( formats.extend(self._extract_mpd_formats(
src, video_id, mpd_id=format_id, fatal=False)) src, video_id, mpd_id=format_id, fatal=False, note=f'Downloading {format_id} mpd manifest'))
else: else:
formats.append({ formats.append({
'format_id': format_id, 'format_id': format_id,
@ -107,26 +129,14 @@ class ORFTVthekIE(InfoExtractor):
# Check for geoblocking. # Check for geoblocking.
# There is a property is_geoprotection, but that's always false # There is a property is_geoprotection, but that's always false
geo_str = sd.get('geoprotection_string') geo_str = sd.get('geoprotection_string')
if geo_str:
try:
http_url = next( http_url = next(
f['url'] (f['url'] for f in formats if re.match(r'^https?://.*\.mp4$', f['url'])),
for f in formats None) if geo_str else None
if re.match(r'^https?://.*\.mp4$', f['url'])) if http_url:
except StopIteration:
pass
else:
req = HEADRequest(http_url)
self._request_webpage( self._request_webpage(
req, video_id, HEADRequest(http_url), video_id, fatal=False, note='Testing for geoblocking',
note='Testing for geoblocking', errnote=f'This video seems to be blocked outside of {geo_str}. You may want to try the streaming-* formats')
errnote=((
'This video seems to be blocked outside of %s. '
'You may want to try the streaming-* formats.')
% geo_str),
fatal=False)
self._check_formats(formats, video_id)
self._sort_formats(formats) self._sort_formats(formats)
subtitles = {} subtitles = {}
@ -148,9 +158,7 @@ class ORFTVthekIE(InfoExtractor):
'url': preview, 'url': preview,
'preference': 0, 'preference': 0,
}) })
image = sd.get('image_full_url') image = sd.get('image_full_url') or image
if not image and len(data_jsb) == 1:
image = self._og_search_thumbnail(webpage)
if image: if image:
thumbnails.append({ thumbnails.append({
'id': 'full', 'id': 'full',
@ -158,21 +166,39 @@ class ORFTVthekIE(InfoExtractor):
'preference': 1, 'preference': 1,
}) })
entries.append({ yield {
'_type': 'video',
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'webpage_url': smuggle_url(f'{url}/part/{video_id}', {'force_noplaylist': True}),
'formats': formats, 'formats': formats,
'subtitles': subtitles, 'subtitles': subtitles,
'description': sd.get('description'), 'description': sd.get('description'),
'duration': int_or_none(sd.get('duration_in_seconds')), 'duration': int_or_none(sd.get('duration_in_seconds')),
'upload_date': upload_date, 'upload_date': upload_date,
'thumbnails': thumbnails, 'thumbnails': thumbnails,
}) }
def _real_extract(self, url):
url, smuggled_data = unsmuggle_url(url)
playlist_id, video_id, base_url = self._match_valid_url(url).group('id', 'vid', 'url')
webpage = self._download_webpage(url, playlist_id)
data_jsb = self._parse_json(
self._search_regex(
r'<div[^>]+class=(["\']).*?VideoPlaylist.*?\1[^>]+data-jsb=(["\'])(?P<json>.+?)\2',
webpage, 'playlist', group='json'),
playlist_id, transform_source=unescapeHTML)['playlist']['videos']
if not self._yes_playlist(playlist_id, video_id, smuggled_data):
data_jsb = [sd for sd in data_jsb if str(sd.get('id')) == video_id]
playlist_count = len(data_jsb)
image = self._og_search_thumbnail(webpage) if playlist_count == 1 else None
page_func = functools.partial(self._pagefunc, base_url, data_jsb, image=image)
return { return {
'_type': 'playlist', '_type': 'playlist',
'entries': entries, 'entries': InAdvancePagedList(page_func, playlist_count, 1),
'id': playlist_id, 'id': playlist_id,
} }