]>
Commit | Line | Data |
---|---|---|
1a20d295 ZM |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | determine_ext, | |
4 | get_elements_text_and_html_by_attribute, | |
27231526 | 5 | scale_thumbnails_to_max_format_width, |
1a20d295 ZM |
6 | ) |
7 | ||
8 | ||
9 | class TVOpenGrBaseIE(InfoExtractor): | |
10 | def _return_canonical_url(self, url, video_id): | |
11 | webpage = self._download_webpage(url, video_id) | |
12 | canonical_url = self._og_search_url(webpage) | |
13 | title = self._og_search_title(webpage) | |
14 | return self.url_result(canonical_url, ie=TVOpenGrWatchIE.ie_key(), video_id=video_id, video_title=title) | |
15 | ||
16 | ||
17 | class TVOpenGrWatchIE(TVOpenGrBaseIE): | |
18 | IE_NAME = 'tvopengr:watch' | |
19 | IE_DESC = 'tvopen.gr (and ethnos.gr) videos' | |
20 | _VALID_URL = r'https?://(?P<netloc>(?:www\.)?(?:tvopen|ethnos)\.gr)/watch/(?P<id>\d+)/(?P<slug>[^/]+)' | |
21 | _API_ENDPOINT = 'https://www.tvopen.gr/templates/data/player' | |
22 | ||
23 | _TESTS = [{ | |
24 | 'url': 'https://www.ethnos.gr/watch/101009/nikoskaprabelosdenexoymekanenanasthenhsemethmethmetallaxhomikron', | |
25 | 'md5': '8728570e3a72e0f8d9475ba94859fdc1', | |
26 | 'info_dict': { | |
27 | 'id': '101009', | |
28 | 'title': 'md5:51f68773dcb6c70498cd326f45fefdf0', | |
29 | 'display_id': 'nikoskaprabelosdenexoymekanenanasthenhsemethmethmetallaxhomikron', | |
30 | 'description': 'md5:78fff49f18fb3effe41b070e5c7685d6', | |
31 | 'thumbnail': 'https://opentv-static.siliconweb.com/imgHandler/1920/d573ba71-ec5f-43c6-b4cb-d181f327d3a8.jpg', | |
32 | 'ext': 'mp4', | |
33 | 'upload_date': '20220109', | |
34 | 'timestamp': 1641686400, | |
35 | }, | |
36 | }, { | |
37 | 'url': 'https://www.tvopen.gr/watch/100979/se28099agapaomenalla7cepeisodio267cmhthrargiapashskakias', | |
38 | 'md5': '38f98a1be0c577db4ea2d1b1c0770c48', | |
39 | 'info_dict': { | |
40 | 'id': '100979', | |
41 | 'title': 'md5:e021f3001e16088ee40fa79b20df305b', | |
42 | 'display_id': 'se28099agapaomenalla7cepeisodio267cmhthrargiapashskakias', | |
43 | 'description': 'md5:ba17db53954134eb8d625d199e2919fb', | |
44 | 'thumbnail': 'https://opentv-static.siliconweb.com/imgHandler/1920/9bb71cf1-21da-43a9-9d65-367950fde4e3.jpg', | |
45 | 'ext': 'mp4', | |
46 | 'upload_date': '20220108', | |
47 | 'timestamp': 1641600000, | |
48 | }, | |
49 | }] | |
50 | ||
51 | def _extract_formats_and_subs(self, response, video_id): | |
52 | formats, subs = [], {} | |
53 | for format_id, format_url in response.items(): | |
54 | if format_id not in ('stream', 'httpstream', 'mpegdash'): | |
55 | continue | |
56 | ext = determine_ext(format_url) | |
57 | if ext == 'm3u8': | |
58 | formats_, subs_ = self._extract_m3u8_formats_and_subtitles( | |
59 | format_url, video_id, 'mp4', m3u8_id=format_id, | |
60 | fatal=False) | |
61 | elif ext == 'mpd': | |
62 | formats_, subs_ = self._extract_mpd_formats_and_subtitles( | |
63 | format_url, video_id, 'mp4', fatal=False) | |
64 | else: | |
65 | formats.append({ | |
66 | 'url': format_url, | |
67 | 'format_id': format_id, | |
68 | }) | |
69 | continue | |
70 | formats.extend(formats_) | |
71 | self._merge_subtitles(subs_, target=subs) | |
1a20d295 ZM |
72 | return formats, subs |
73 | ||
1a20d295 ZM |
74 | def _real_extract(self, url): |
75 | netloc, video_id, display_id = self._match_valid_url(url).group('netloc', 'id', 'slug') | |
76 | if netloc.find('tvopen.gr') == -1: | |
77 | return self._return_canonical_url(url, video_id) | |
78 | webpage = self._download_webpage(url, video_id) | |
79 | info = self._search_json_ld(webpage, video_id, expected_type='VideoObject') | |
80 | info['formats'], info['subtitles'] = self._extract_formats_and_subs( | |
81 | self._download_json(self._API_ENDPOINT, video_id, query={'cid': video_id}), | |
82 | video_id) | |
27231526 | 83 | info['thumbnails'] = scale_thumbnails_to_max_format_width( |
1a20d295 ZM |
84 | info['formats'], info['thumbnails'], r'(?<=/imgHandler/)\d+') |
85 | description, _html = next(get_elements_text_and_html_by_attribute('class', 'description', webpage)) | |
86 | if description and _html.startswith('<span '): | |
87 | info['description'] = description | |
88 | info['id'] = video_id | |
89 | info['display_id'] = display_id | |
90 | return info | |
91 | ||
92 | ||
93 | class TVOpenGrEmbedIE(TVOpenGrBaseIE): | |
94 | IE_NAME = 'tvopengr:embed' | |
95 | IE_DESC = 'tvopen.gr embedded videos' | |
96 | _VALID_URL = r'(?:https?:)?//(?:www\.|cdn\.|)(?:tvopen|ethnos).gr/embed/(?P<id>\d+)' | |
bfd973ec | 97 | _EMBED_REGEX = [rf'''<iframe[^>]+?src=(?P<_q1>["'])(?P<url>{_VALID_URL})(?P=_q1)'''] |
1a20d295 ZM |
98 | |
99 | _TESTS = [{ | |
100 | 'url': 'https://cdn.ethnos.gr/embed/100963', | |
101 | 'md5': '2da147881f45571d81662d94d086628b', | |
102 | 'info_dict': { | |
103 | 'id': '100963', | |
104 | 'display_id': 'koronoiosapotoysdieythyntestonsxoleionselftestgiaosoysdenbrhkan', | |
105 | 'title': 'md5:2c71876fadf0cda6043da0da5fca2936', | |
106 | 'description': 'md5:17482b4432e5ed30eccd93b05d6ea509', | |
107 | 'thumbnail': 'https://opentv-static.siliconweb.com/imgHandler/1920/5804e07f-799a-4247-a696-33842c94ca37.jpg', | |
108 | 'ext': 'mp4', | |
109 | 'upload_date': '20220108', | |
110 | 'timestamp': 1641600000, | |
111 | }, | |
112 | }] | |
113 | ||
1a20d295 ZM |
114 | def _real_extract(self, url): |
115 | video_id = self._match_id(url) | |
116 | return self._return_canonical_url(url, video_id) |