Compare commits

...

2 Commits

Author SHA1 Message Date
sepro
3b9558e4f9 Oops 2024-01-14 20:24:56 +01:00
sepro
2ecbfb0727 Apply review suggestions 2024-01-14 20:24:02 +01:00
3 changed files with 28 additions and 40 deletions

View File

@ -1,20 +0,0 @@
import pytest
from yt_dlp.extractor.arte import ArteTVIE
ACCESSIBLE_TESTS = [
({'fr': [{'url': 'https://arte-cmafhls.akamaized.net/am/cmaf/103000/103500/103522-000-A/230804153206/medias/103522-000-A_st_VF-FRA.m3u8', 'ext': 'vtt', 'protocol': 'm3u8_native'}]}, 'fr'),
({'fr': [{'url': 'https://arte-cmafhls.akamaized.net/am/cmaf/103000/103500/103522-000-A/230804153206/medias/103522-000-A_st_VF-MAL.m3u8', 'ext': 'vtt', 'protocol': 'm3u8_native'}]}, 'fr-acc'),
]
@pytest.mark.parametrize('original_subs,expected_locale', ACCESSIBLE_TESTS)
def test_extract_accessible_subtitles(original_subs, expected_locale):
extractor = ArteTVIE()
subs = extractor._contvert_accessible_subs_locale(original_subs)
assert len(subs) == 1
assert expected_locale in subs
assert subs[expected_locale] == original_subs['fr']

View File

@ -16,7 +16,6 @@ from ..utils import (
class ArteTVBaseIE(InfoExtractor): class ArteTVBaseIE(InfoExtractor):
_ARTE_LANGUAGES = 'fr|de|en|es|it|pl' _ARTE_LANGUAGES = 'fr|de|en|es|it|pl'
_API_BASE = 'https://api.arte.tv/api/player/v2' _API_BASE = 'https://api.arte.tv/api/player/v2'
_ARTE_ACCESSIBLE_SUBS_SUFFIX = '-MAL.m3u8'
class ArteTVIE(ArteTVBaseIE): class ArteTVIE(ArteTVBaseIE):
@ -71,7 +70,24 @@ class ArteTVIE(ArteTVBaseIE):
'thumbnail': 'https://api-cdn.arte.tv/img/v2/image/q82dTTfyuCXupPsGxXsd7B/940x530', 'thumbnail': 'https://api-cdn.arte.tv/img/v2/image/q82dTTfyuCXupPsGxXsd7B/940x530',
'upload_date': '20230930', 'upload_date': '20230930',
'ext': 'mp4', 'ext': 'mp4',
} },
}, {
'url': 'https://www.arte.tv/de/videos/085374-003-A/im-hohen-norden-geboren/',
'info_dict': {
'id': '085374-003-A',
'ext': 'mp4',
'description': 'md5:ab79ec7cc472a93164415b4e4916abf9',
'timestamp': 1702872000,
'thumbnail': 'https://api-cdn.arte.tv/img/v2/image/TnyHBfPxv3v2GEY3suXGZP/940x530',
'duration': 2594,
'title': 'Die kurze Zeit der Jugend',
'alt_title': 'Im hohen Norden geboren',
'upload_date': '20231218',
'subtitles': {
'fr': 'mincount:1',
'fr-acc': 'mincount:1',
},
},
}] }]
_GEO_BYPASS = True _GEO_BYPASS = True
@ -122,23 +138,15 @@ class ArteTVIE(ArteTVBaseIE):
), ),
} }
def _contvert_accessible_subs_locale(self, subs): @staticmethod
"""Gives a different locale code to accessible subttiles. def _fix_accessible_subs_locale(subs):
updated_subs = {}
Some videos have multiple subtitles for the same language. A normal for lang, sub_formats in subs.items():
subtitle and some accessible subtitles. This method will transform for format in sub_formats:
the language code for accessible subtitles by appending a '-acc' suffix if format.get('url', '').endswith('-MAL.m3u8'):
to its language code. lang += '-acc'
""" updated_subs.setdefault(lang, []).append(format)
extracted_subs = {} return updated_subs
for locale, sub_content in subs.items():
if any(item.get('url', '').endswith(self._ARTE_ACCESSIBLE_SUBS_SUFFIX) for item in sub_content):
locale += '-acc'
extracted_subs[locale] = sub_content
return extracted_subs
def _real_extract(self, url): def _real_extract(self, url):
mobj = self._match_valid_url(url) mobj = self._match_valid_url(url)
@ -184,7 +192,6 @@ class ArteTVIE(ArteTVBaseIE):
if 'HLS' in stream['protocol']: if 'HLS' in stream['protocol']:
fmts, subs = self._extract_m3u8_formats_and_subtitles( fmts, subs = self._extract_m3u8_formats_and_subtitles(
stream['url'], video_id=video_id, ext='mp4', m3u8_id=stream_version_code, fatal=False) stream['url'], video_id=video_id, ext='mp4', m3u8_id=stream_version_code, fatal=False)
subs = self._contvert_accessible_subs_locale(subs)
for fmt in fmts: for fmt in fmts:
fmt.update({ fmt.update({
'format_note': f'{stream_version.get("label", "unknown")} [{short_label}]', 'format_note': f'{stream_version.get("label", "unknown")} [{short_label}]',
@ -194,6 +201,7 @@ class ArteTVIE(ArteTVBaseIE):
secondary_formats.extend(fmts) secondary_formats.extend(fmts)
else: else:
formats.extend(fmts) formats.extend(fmts)
subs = self._fix_accessible_subs_locale(subs)
self._merge_subtitles(subs, target=subtitles) self._merge_subtitles(subs, target=subtitles)
elif stream['protocol'] in ('HTTPS', 'RTMP'): elif stream['protocol'] in ('HTTPS', 'RTMP'):