]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/duoplay.py
[ie/JoqrAg] Add extractor (#8384)
[yt-dlp.git] / yt_dlp / extractor / duoplay.py
CommitLineData
66a0127d
ER
1from .common import InfoExtractor
2from ..utils import (
3 ExtractorError,
4 extract_attributes,
5 get_element_text_and_html_by_tag,
6 int_or_none,
7 join_nonempty,
8 str_or_none,
9 try_call,
10 unified_timestamp,
11)
12from ..utils.traversal import traverse_obj
13
14
15class DuoplayIE(InfoExtractor):
16 _VALID_URL = r'https://duoplay\.ee/(?P<id>\d+)/[\w-]+/?(?:\?(?:[^#]+&)?ep=(?P<ep>\d+))?'
17 _TESTS = [{
18 'note': 'Siberi võmm S02E12',
19 'url': 'https://duoplay.ee/4312/siberi-vomm?ep=24',
20 'md5': '1ff59d535310ac9c5cf5f287d8f91b2d',
21 'info_dict': {
22 'id': '4312_24',
23 'ext': 'mp4',
24 'title': 'Operatsioon "Öö"',
25 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
26 'description': 'md5:8ef98f38569d6b8b78f3d350ccc6ade8',
27 'upload_date': '20170523',
28 'timestamp': 1495567800,
29 'series': 'Siberi võmm',
30 'series_id': '4312',
31 'season': 'Season 2',
32 'season_number': 2,
33 'episode': 'Operatsioon "Öö"',
34 'episode_number': 12,
35 'episode_id': 24,
36 },
37 }, {
38 'note': 'Empty title',
39 'url': 'https://duoplay.ee/17/uhikarotid?ep=14',
40 'md5': '6aca68be71112314738dd17cced7f8bf',
41 'info_dict': {
42 'id': '17_14',
43 'ext': 'mp4',
44 'title': 'Ühikarotid',
45 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
46 'description': 'md5:4719b418e058c209def41d48b601276e',
47 'upload_date': '20100916',
48 'timestamp': 1284661800,
49 'series': 'Ühikarotid',
50 'series_id': '17',
51 'season': 'Season 2',
52 'season_number': 2,
53 'episode_id': 14,
54 'release_year': 2010,
55 },
56 }, {
57 'note': 'Movie',
58 'url': 'https://duoplay.ee/4325/naljamangud',
59 'md5': '2b0bcac4159a08b1844c2bfde06b1199',
60 'info_dict': {
61 'id': '4325',
62 'ext': 'mp4',
63 'title': 'Näljamängud',
64 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
65 'description': 'md5:fb35f5eb2ff46cdb82e4d5fbe7b49a13',
66 'cast': ['Jennifer Lawrence', 'Josh Hutcherson', 'Liam Hemsworth'],
67 'upload_date': '20231109',
68 'timestamp': 1699552800,
69 'release_year': 2012,
70 },
71 }, {
72 'note': 'Movie without expiry',
73 'url': 'https://duoplay.ee/5501/pilvede-all.-neljas-ode',
74 'md5': '7abf63d773a49ef7c39f2c127842b8fd',
75 'info_dict': {
76 'id': '5501',
77 'ext': 'mp4',
78 'title': 'Pilvede all. Neljas õde',
79 'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
80 'description': 'md5:d86a70f8f31e82c369d4d4f4c79b1279',
81 'cast': 'count:9',
82 'upload_date': '20221214',
83 'timestamp': 1671054000,
84 'release_year': 2018,
85 },
86 }]
87
88 def _real_extract(self, url):
89 telecast_id, episode = self._match_valid_url(url).group('id', 'ep')
90 video_id = join_nonempty(telecast_id, episode, delim='_')
91 webpage = self._download_webpage(url, video_id)
92 video_player = try_call(lambda: extract_attributes(
93 get_element_text_and_html_by_tag('video-player', webpage)[1]))
94 if not video_player or not video_player.get('manifest-url'):
95 raise ExtractorError('No video found', expected=True)
96
97 episode_attr = self._parse_json(video_player.get(':episode') or '', video_id, fatal=False) or {}
98
99 return {
100 'id': video_id,
101 'formats': self._extract_m3u8_formats(video_player['manifest-url'], video_id, 'mp4'),
102 **traverse_obj(episode_attr, {
103 'title': 'title',
104 'description': 'synopsis',
105 'thumbnail': ('images', 'original'),
106 'timestamp': ('airtime', {lambda x: unified_timestamp(x + ' +0200')}),
107 'cast': ('cast', {lambda x: x.split(', ')}),
108 'release_year': ('year', {int_or_none}),
109 }),
110 **(traverse_obj(episode_attr, {
111 'title': (None, ('subtitle', ('episode_nr', {lambda x: f'Episode {x}' if x else None}))),
112 'series': 'title',
113 'series_id': ('telecast_id', {str_or_none}),
114 'season_number': ('season_id', {int_or_none}),
115 'episode': 'subtitle',
116 'episode_number': ('episode_nr', {int_or_none}),
117 'episode_id': ('episode_id', {int_or_none}),
118 }, get_all=False) if episode_attr.get('category') != 'movies' else {}),
119 }