Compare commits

..

No commits in common. "ed24640943872c4cf30d7cc4601bec87b50ba03c" and "1e28f6bf743627b909135bb9a88537ad2deccaf0" have entirely different histories.

2 changed files with 49 additions and 66 deletions

View File

@ -979,7 +979,6 @@ def parse_options(argv=None):
'geo_bypass': opts.geo_bypass, 'geo_bypass': opts.geo_bypass,
'geo_bypass_country': opts.geo_bypass_country, 'geo_bypass_country': opts.geo_bypass_country,
'geo_bypass_ip_block': opts.geo_bypass_ip_block, 'geo_bypass_ip_block': opts.geo_bypass_ip_block,
'useid': opts.useid or None,
'warn_when_outdated': opts.update_self is None, 'warn_when_outdated': opts.update_self is None,
'_warnings': warnings, '_warnings': warnings,
'_deprecation_warnings': deprecation_warnings, '_deprecation_warnings': deprecation_warnings,

View File

@ -1,14 +1,22 @@
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
clean_html, clean_html,
merge_dicts,
traverse_obj,
unified_timestamp, unified_timestamp,
url_or_none, url_or_none,
urljoin, urljoin,
) )
from ..utils.traversal import traverse_obj
class LRTStreamIE(InfoExtractor): class LRTBaseIE(InfoExtractor):
def _extract_js_var(self, webpage, var_name, default=None):
return self._search_regex(
fr'{var_name}\s*=\s*(["\'])((?:(?!\1).)+)\1',
webpage, var_name.replace('_', ' '), default, group=2)
class LRTStreamIE(LRTBaseIE):
_VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/tiesiogiai/(?P<id>[\w-]+)' _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/tiesiogiai/(?P<id>[\w-]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://www.lrt.lt/mediateka/tiesiogiai/lrt-opus', 'url': 'https://www.lrt.lt/mediateka/tiesiogiai/lrt-opus',
@ -23,110 +31,86 @@ class LRTStreamIE(InfoExtractor):
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)
streams_data = self._download_json(self._extract_js_var(webpage, 'tokenURL'), video_id)
# TODO: Use _search_nextjs_v13_data once fixed
get_stream_url = self._search_regex(
r'\\"get_streams_url\\":\\"([^"]+)\\"', webpage, 'stream URL')
streams_data = self._download_json(get_stream_url, video_id)
formats, subtitles = [], {} formats, subtitles = [], {}
for stream_url in traverse_obj(streams_data, ( for stream_url in traverse_obj(streams_data, (
'response', 'data', lambda k, _: k.startswith('content'), {url_or_none})): 'response', 'data', lambda k, _: k.startswith('content')), expected_type=url_or_none):
fmts, subs = self._extract_m3u8_formats_and_subtitles( fmts, subs = self._extract_m3u8_formats_and_subtitles(stream_url, video_id, 'mp4', m3u8_id='hls', live=True)
stream_url, video_id, 'mp4', m3u8_id='hls', live=True)
formats.extend(fmts) formats.extend(fmts)
subtitles = self._merge_subtitles(subtitles, subs) subtitles = self._merge_subtitles(subtitles, subs)
stream_title = self._extract_js_var(webpage, 'video_title', 'LRT')
return { return {
'id': video_id, 'id': video_id,
'formats': formats, 'formats': formats,
'subtitles': subtitles, 'subtitles': subtitles,
'is_live': True, 'is_live': True,
'title': self._og_search_title(webpage), 'title': f'{self._og_search_title(webpage)} - {stream_title}',
} }
class LRTVODIE(InfoExtractor): class LRTVODIE(LRTBaseIE):
_VALID_URL = [ _VALID_URL = r'https?://(?:www\.)?lrt\.lt(?P<path>/mediateka/irasas/(?P<id>[0-9]+))'
r'https?://(?:(?:www|archyvai)\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)',
r'https?://(?:(?:www|archyvai)\.)?lrt\.lt/mediateka/video/[^?#]+\?(?:[^#]*&)?episode=(?P<id>[0-9]+)',
]
_TESTS = [{ _TESTS = [{
# m3u8 download # m3u8 download
'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene', 'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene',
'info_dict': { 'info_dict': {
'id': '2000127261', 'id': '2000127261',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Nustebinkite svečius klasikiniu makaronų su baklažanais receptu', 'title': 'Greita ir gardu: Sicilijos įkvėpta klasikinių makaronų su baklažanais vakarienė',
'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa', 'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa',
'timestamp': 1604086200, 'duration': 3035,
'timestamp': 1604079000,
'upload_date': '20201030', 'upload_date': '20201030',
'tags': ['LRT TELEVIZIJA', 'Beatos virtuvė', 'Beata Nicholson', 'Makaronai', 'Baklažanai', 'Vakarienė', 'Receptas'], 'tags': ['LRT TELEVIZIJA', 'Beatos virtuvė', 'Beata Nicholson', 'Makaronai', 'Baklažanai', 'Vakarienė', 'Receptas'],
'thumbnail': 'https://www.lrt.lt/img/2020/10/30/764041-126478-1287x836.jpg', 'thumbnail': 'https://www.lrt.lt/img/2020/10/30/764041-126478-1287x836.jpg',
'channel': 'Beatos virtuvė',
}, },
}, { }, {
# audio download # direct mp3 download
'url': 'https://www.lrt.lt/mediateka/irasas/1013074524/kita-tema', 'url': 'http://www.lrt.lt/mediateka/irasas/1013074524/',
'md5': 'fc982f10274929c66fdff65f75615cb0', 'md5': '389da8ca3cad0f51d12bed0c844f6a0a',
'info_dict': { 'info_dict': {
'id': '1013074524', 'id': '1013074524',
'ext': 'mp4', 'ext': 'mp3',
'title': 'Kita tema', 'title': 'Kita tema 2016-09-05 15:05',
'description': 'md5:1b295a8fc7219ed0d543fc228c931fb5', 'description': 'md5:1b295a8fc7219ed0d543fc228c931fb5',
'channel': 'Kita tema', 'duration': 3008,
'timestamp': 1473087900, 'view_count': int,
'upload_date': '20160905', 'like_count': int,
}, },
}, {
'url': 'https://www.lrt.lt/mediateka/video/auksinis-protas-vasara?episode=2000420320&season=%2Fmediateka%2Fvideo%2Fauksinis-protas-vasara%2F2025',
'info_dict': {
'id': '2000420320',
'ext': 'mp4',
'title': 'Kuris senovės romėnų poetas aprašė Narcizo mitą?',
'description': 'Intelektinė viktorina. Ved. Arūnas Valinskas ir Andrius Tapinas.',
'channel': 'Auksinis protas. Vasara',
'thumbnail': 'https://www.lrt.lt/img/2025/06/09/2094343-987905-1287x836.jpg',
'tags': ['LRT TELEVIZIJA', 'Auksinis protas'],
'timestamp': 1749851040,
'upload_date': '20250613',
},
}, {
'url': 'https://archyvai.lrt.lt/mediateka/video/ziniu-riteriai-ir-damos?episode=49685&season=%2Fmediateka%2Fvideo%2Fziniu-riteriai-ir-damos%2F2013',
'only_matching': True,
}, {
'url': 'https://archyvai.lrt.lt/mediateka/irasas/2000077058/panorama-1989-baltijos-kelias',
'only_matching': True,
}] }]
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) path, video_id = self._match_valid_url(url).group('path', 'id')
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
# TODO: Use _search_nextjs_v13_data once fixed media_url = self._extract_js_var(webpage, 'main_url', path)
canonical_url = ( media = self._download_json(self._extract_js_var(
self._search_regex(r'\\"(?:article|data)\\":{[^}]*\\"url\\":\\"(/[^"]+)\\"', webpage, 'content URL', fatal=False) webpage, 'media_info_url',
or self._search_regex(r'<link\s+rel="canonical"\s*href="(/[^"]+)"', webpage, 'canonical URL')) 'https://www.lrt.lt/servisai/stream_url/vod/media_info/'),
video_id, query={'url': media_url})
media = self._download_json(
'https://www.lrt.lt/servisai/stream_url/vod/media_info/',
video_id, query={'url': canonical_url})
jw_data = self._parse_jwplayer_data( jw_data = self._parse_jwplayer_data(
media['playlist_item'], video_id, base_url=url) media['playlist_item'], video_id, base_url=url)
return { json_ld_data = self._search_json_ld(webpage, video_id)
**jw_data,
**traverse_obj(media, { tags = []
'id': ('id', {str}), for tag in (media.get('tags') or []):
'title': ('title', {str}), tag_name = tag.get('name')
'description': ('content', {clean_html}), if not tag_name:
'timestamp': ('date', {lambda x: x.replace('.', '/')}, {unified_timestamp}), continue
'tags': ('tags', ..., 'name', {str}), tags.append(tag_name)
}),
clean_info = {
'description': clean_html(media.get('content')),
'tags': tags,
} }
return merge_dicts(clean_info, jw_data, json_ld_data)
class LRTRadioIE(InfoExtractor):
class LRTRadioIE(LRTBaseIE):
_VALID_URL = r'https?://(?:www\.)?lrt\.lt/radioteka/irasas/(?P<id>\d+)/(?P<path>[^?#/]+)' _VALID_URL = r'https?://(?:www\.)?lrt\.lt/radioteka/irasas/(?P<id>\d+)/(?P<path>[^?#/]+)'
_TESTS = [{ _TESTS = [{
# m3u8 download # m3u8 download