[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / elonet.py
blobc5558ffcd9efb6856fc544b97459ede5fe117b8b
1 from .common import InfoExtractor
2 from ..utils import determine_ext
5 class ElonetIE(InfoExtractor):
6 _VALID_URL = r'https?://elonet\.finna\.fi/Record/kavi\.elonet_elokuva_(?P<id>[0-9]+)'
7 _TESTS = [{
8 'url': 'https://elonet.finna.fi/Record/kavi.elonet_elokuva_107867',
9 'info_dict': {
10 'id': '107867',
11 'ext': 'mp4',
12 'title': 'Valkoinen peura',
13 'thumbnail': r're:^https?://elonet\.finna\.fi/Cover/Show\?id=kavi\.elonet_elokuva_107867.+',
14 'description': 'md5:bded4201c9677fab10854884fe8f7312',
16 'params': {'skip_download': 'dash'},
17 }, {
18 # DASH with subtitles
19 'url': 'https://elonet.finna.fi/Record/kavi.elonet_elokuva_116539',
20 'info_dict': {
21 'id': '116539',
22 'ext': 'mp4',
23 'title': 'Minulla on tiikeri',
24 'thumbnail': r're:^https?://elonet\.finna\.fi/Cover/Show\?id=kavi\.elonet_elokuva_116539.+',
25 'description': 'md5:5ab72b3fe76d3414e46cc8f277104419',
27 'params': {'skip_download': 'dash'},
28 }, {
29 # Page with multiple videos, download the main one
30 'url': 'https://elonet.finna.fi/Record/kavi.elonet_elokuva_117396',
31 'info_dict': {
32 'id': '117396',
33 'ext': 'mp4',
34 'title': 'Sampo',
35 'thumbnail': r're:^https?://elonet\.finna\.fi/Cover/Show\?id=kavi\.elonet_elokuva_117396.+',
36 'description': 'md5:ec69572a5b054d0ecafe8086b1fa96f7',
38 'params': {'skip_download': 'dash'},
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
43 webpage = self._download_webpage(url, video_id)
45 src = self._parse_json(self._html_search_regex(
46 r'id=\'video-data\'[^>]+data-video-sources="([^"]+)"', webpage, 'json'), video_id)[0]['src']
47 ext = determine_ext(src)
49 if ext == 'm3u8':
50 formats, subtitles = self._extract_m3u8_formats_and_subtitles(src, video_id, fatal=False)
51 elif ext == 'mpd':
52 formats, subtitles = self._extract_mpd_formats_and_subtitles(src, video_id, fatal=False)
53 else:
54 formats, subtitles = [], {}
55 self.raise_no_formats(f'Unknown streaming format {ext}')
57 return {
58 'id': video_id,
59 'title': self._og_search_title(webpage),
60 'description': self._og_search_description(webpage),
61 'thumbnail': self._og_search_thumbnail(webpage),
62 'formats': formats,
63 'subtitles': subtitles,