mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-29 10:41:23 +01:00
Compare commits
No commits in common. "3b9558e4f92ee379514232f13593177b0df1be08" and "b47f4a80fd426c0411e46a12f9fd854420e574b7" have entirely different histories.
3b9558e4f9
...
b47f4a80fd
0
test/extractor/__init__.py
Normal file
0
test/extractor/__init__.py
Normal file
20
test/extractor/test_arte.py
Normal file
20
test/extractor/test_arte.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
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']
|
|
@ -16,6 +16,7 @@ from ..utils import (
|
|||
class ArteTVBaseIE(InfoExtractor):
|
||||
_ARTE_LANGUAGES = 'fr|de|en|es|it|pl'
|
||||
_API_BASE = 'https://api.arte.tv/api/player/v2'
|
||||
_ARTE_ACCESSIBLE_SUBS_SUFFIX = '-MAL.m3u8'
|
||||
|
||||
|
||||
class ArteTVIE(ArteTVBaseIE):
|
||||
|
@ -70,24 +71,7 @@ class ArteTVIE(ArteTVBaseIE):
|
|||
'thumbnail': 'https://api-cdn.arte.tv/img/v2/image/q82dTTfyuCXupPsGxXsd7B/940x530',
|
||||
'upload_date': '20230930',
|
||||
'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
|
||||
|
@ -138,15 +122,23 @@ class ArteTVIE(ArteTVBaseIE):
|
|||
),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _fix_accessible_subs_locale(subs):
|
||||
updated_subs = {}
|
||||
for lang, sub_formats in subs.items():
|
||||
for format in sub_formats:
|
||||
if format.get('url', '').endswith('-MAL.m3u8'):
|
||||
lang += '-acc'
|
||||
updated_subs.setdefault(lang, []).append(format)
|
||||
return updated_subs
|
||||
def _contvert_accessible_subs_locale(self, subs):
|
||||
"""Gives a different locale code to accessible subttiles.
|
||||
|
||||
Some videos have multiple subtitles for the same language. A normal
|
||||
subtitle and some accessible subtitles. This method will transform
|
||||
the language code for accessible subtitles by appending a '-acc' suffix
|
||||
to its language code.
|
||||
"""
|
||||
extracted_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):
|
||||
mobj = self._match_valid_url(url)
|
||||
|
@ -192,6 +184,7 @@ class ArteTVIE(ArteTVBaseIE):
|
|||
if 'HLS' in stream['protocol']:
|
||||
fmts, subs = self._extract_m3u8_formats_and_subtitles(
|
||||
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:
|
||||
fmt.update({
|
||||
'format_note': f'{stream_version.get("label", "unknown")} [{short_label}]',
|
||||
|
@ -201,7 +194,6 @@ class ArteTVIE(ArteTVBaseIE):
|
|||
secondary_formats.extend(fmts)
|
||||
else:
|
||||
formats.extend(fmts)
|
||||
subs = self._fix_accessible_subs_locale(subs)
|
||||
self._merge_subtitles(subs, target=subtitles)
|
||||
|
||||
elif stream['protocol'] in ('HTTPS', 'RTMP'):
|
||||
|
|
Loading…
Reference in New Issue
Block a user