mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-01-24 05:57:15 +01:00
aplied requested changes
This commit is contained in:
parent
ed2735b3d6
commit
352b1576e4
1 changed files with 29 additions and 82 deletions
|
|
@ -1,111 +1,58 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
filter_dict,
|
||||
int_or_none,
|
||||
js_to_json,
|
||||
url_or_none,
|
||||
)
|
||||
from ..utils.traversal import (
|
||||
traverse_obj,
|
||||
)
|
||||
from ..utils.traversal import traverse_obj
|
||||
|
||||
|
||||
class TVIPlayerIE(InfoExtractor):
|
||||
_VALID_URL = (
|
||||
r'https?://tviplayer\.iol\.pt(?:/programa/[\w-]+/[a-f0-9]+)?/\w+/(?P<id>\w+)'
|
||||
)
|
||||
_TESTS = [
|
||||
{
|
||||
'url': 'https://tviplayer.iol.pt/programa/a-protegida/67a63479d34ef72ee441fa79/episodio/t1e120',
|
||||
'info_dict': {
|
||||
'id': '689683000cf20ac1d5f35341',
|
||||
'ext': 'mp4',
|
||||
'duration': 1593,
|
||||
'title': 'A Protegida - Clarice descobre o que une Óscar a Gonçalo e Mónica',
|
||||
'thumbnail': 'https://img.iol.pt/image/id/68971037d34ef72ee44941a6/',
|
||||
'season_number': 1,
|
||||
},
|
||||
_VALID_URL = r'https?://tviplayer\.iol\.pt(?:/programa/[\w-]+/[a-f0-9]+)?/\w+/(?P<id>\w+)'
|
||||
_TESTS = [{
|
||||
'url': 'https://tviplayer.iol.pt/programa/a-protegida/67a63479d34ef72ee441fa79/episodio/t1e120',
|
||||
'info_dict': {
|
||||
'id': '689683000cf20ac1d5f35341',
|
||||
'ext': 'mp4',
|
||||
'duration': 1593,
|
||||
'title': 'A Protegida - Clarice descobre o que une Óscar a Gonçalo e Mónica',
|
||||
'thumbnail': 'https://img.iol.pt/image/id/68971037d34ef72ee44941a6/',
|
||||
'season_number': 1,
|
||||
},
|
||||
]
|
||||
}]
|
||||
|
||||
def _real_initialize(self):
|
||||
# Obtain the wmsAuthSign token (non-fatal)
|
||||
self.wms_auth_sign_token = self._download_webpage(
|
||||
'https://services.iol.pt/matrix?userId=',
|
||||
'wmsAuthSign',
|
||||
note='Downloading wmsAuthSign token',
|
||||
fatal=False,
|
||||
)
|
||||
'https://services.iol.pt/matrix?userId=', 'wmsAuthSign',
|
||||
note='Trying to get wmsAuthSign token')
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, video_id)
|
||||
|
||||
# Try to locate a JS "video: [ {...} ]" block
|
||||
json_data = self._search_json(
|
||||
r'(?<!-)\bvideo\s*:\s*\[',
|
||||
webpage,
|
||||
'json_data',
|
||||
video_id,
|
||||
transform_source=js_to_json,
|
||||
default={},
|
||||
)
|
||||
webpage, 'json_data', video_id, transform_source=js_to_json)
|
||||
|
||||
# Structured metadata from ld+json
|
||||
_ = self._search_json_ld(webpage, video_id, default={}) or {}
|
||||
|
||||
# Merge data safely without type errors
|
||||
def first_of(*keys):
|
||||
for k in keys:
|
||||
v = traverse_obj(json_data, (k,))
|
||||
if v:
|
||||
return v
|
||||
return None
|
||||
|
||||
info_id = first_of('id')
|
||||
title = first_of('title') or self._og_search_title(webpage)
|
||||
thumbnail = first_of('cover', 'thumbnail') or self._og_search_thumbnail(webpage)
|
||||
duration = first_of('duration')
|
||||
|
||||
try:
|
||||
duration = int(duration) if duration is not None else None
|
||||
except Exception:
|
||||
try:
|
||||
duration = int(float(duration))
|
||||
except Exception:
|
||||
duration = None
|
||||
|
||||
video_url = first_of('videoUrl', 'url', 'video_url')
|
||||
video_url = traverse_obj(json_data, ('videoUrl',), expected_type=url_or_none)
|
||||
if not video_url:
|
||||
m = re.search(
|
||||
r'["\']videoUrl["\']\s*:\s*["\'](https?://[^"\']+)["\']', webpage,
|
||||
)
|
||||
if m:
|
||||
video_url = m.group(1)
|
||||
raise ExtractorError('Unable to locate video URL in webpage')
|
||||
|
||||
if not video_url:
|
||||
raise ExtractorError('Unable to locate video URL in webpage', expected=True)
|
||||
|
||||
query = (
|
||||
{'wmsAuthSign': self.wms_auth_sign_token}
|
||||
if self.wms_auth_sign_token
|
||||
else {}
|
||||
)
|
||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||
video_url, video_id, ext='mp4', query=query, fatal=False,
|
||||
)
|
||||
|
||||
season_number = traverse_obj(json_data, ('program', 'seasonNum'))
|
||||
video_url, video_id, ext='mp4', query=filter_dict({
|
||||
'wmsAuthSign': self.wms_auth_sign_token,
|
||||
}))
|
||||
|
||||
return {
|
||||
'id': info_id or video_id,
|
||||
'id': traverse_obj(json_data, ('id',)) or video_id,
|
||||
'display_id': video_id,
|
||||
'title': title,
|
||||
'thumbnail': thumbnail,
|
||||
'duration': duration,
|
||||
'title': traverse_obj(json_data, ('title',)) or self._og_search_title(webpage),
|
||||
'thumbnail': traverse_obj(
|
||||
json_data, ('cover',), ('thumbnail',), expected_type=url_or_none) or self._og_search_thumbnail(webpage),
|
||||
'duration': int_or_none(traverse_obj(json_data, ('duration',))),
|
||||
'formats': formats,
|
||||
'subtitles': subtitles,
|
||||
'season_number': season_number,
|
||||
'season_number': traverse_obj(json_data, ('program', 'seasonNum')),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue