]>
Commit | Line | Data |
---|---|---|
27231526 ZM |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | import urllib.parse | |
6 | ||
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
9 | HEADRequest, | |
10 | ExtractorError, | |
11 | determine_ext, | |
12 | scale_thumbnails_to_max_format_width, | |
13 | unescapeHTML, | |
14 | ) | |
15 | ||
16 | ||
17 | class Ant1NewsGrBaseIE(InfoExtractor): | |
18 | def _download_and_extract_api_data(self, video_id, netloc, cid=None): | |
19 | url = f'{self.http_scheme()}//{netloc}{self._API_PATH}' | |
20 | info = self._download_json(url, video_id, query={'cid': cid or video_id}) | |
21 | try: | |
22 | source = info['url'] | |
23 | except KeyError: | |
24 | raise ExtractorError('no source found for %s' % video_id) | |
25 | formats, subs = (self._extract_m3u8_formats_and_subtitles(source, video_id, 'mp4') | |
26 | if determine_ext(source) == 'm3u8' else ([{'url': source}], {})) | |
27 | self._sort_formats(formats) | |
28 | thumbnails = scale_thumbnails_to_max_format_width( | |
29 | formats, [{'url': info['thumb']}], r'(?<=/imgHandler/)\d+') | |
30 | return { | |
31 | 'id': video_id, | |
32 | 'title': info.get('title'), | |
33 | 'thumbnails': thumbnails, | |
34 | 'formats': formats, | |
35 | 'subtitles': subs, | |
36 | } | |
37 | ||
38 | ||
39 | class Ant1NewsGrWatchIE(Ant1NewsGrBaseIE): | |
40 | IE_NAME = 'ant1newsgr:watch' | |
41 | IE_DESC = 'ant1news.gr videos' | |
42 | _VALID_URL = r'https?://(?P<netloc>(?:www\.)?ant1news\.gr)/watch/(?P<id>\d+)/' | |
43 | _API_PATH = '/templates/data/player' | |
44 | ||
45 | _TESTS = [{ | |
46 | 'url': 'https://www.ant1news.gr/watch/1506168/ant1-news-09112021-stis-18-45', | |
47 | 'md5': '95925e6b32106754235f2417e0d2dfab', | |
48 | 'info_dict': { | |
49 | 'id': '1506168', | |
50 | 'ext': 'mp4', | |
51 | 'title': 'md5:0ad00fa66ecf8aa233d26ab0dba7514a', | |
52 | 'description': 'md5:18665af715a6dcfeac1d6153a44f16b0', | |
53 | 'thumbnail': 'https://ant1media.azureedge.net/imgHandler/640/26d46bf6-8158-4f02-b197-7096c714b2de.jpg', | |
54 | }, | |
55 | }] | |
56 | ||
57 | def _real_extract(self, url): | |
58 | video_id, netloc = self._match_valid_url(url).group('id', 'netloc') | |
59 | webpage = self._download_webpage(url, video_id) | |
60 | info = self._download_and_extract_api_data(video_id, netloc) | |
61 | info['description'] = self._og_search_description(webpage) | |
62 | return info | |
63 | ||
64 | ||
65 | class Ant1NewsGrArticleIE(Ant1NewsGrBaseIE): | |
66 | IE_NAME = 'ant1newsgr:article' | |
67 | IE_DESC = 'ant1news.gr articles' | |
68 | _VALID_URL = r'https?://(?:www\.)?ant1news\.gr/[^/]+/article/(?P<id>\d+)/' | |
69 | ||
70 | _TESTS = [{ | |
71 | 'url': 'https://www.ant1news.gr/afieromata/article/549468/o-tzeims-mpont-sta-meteora-oi-apeiles-kai-o-xesikomos-ton-kalogeron', | |
72 | 'md5': '294f18331bb516539d72d85a82887dcc', | |
73 | 'info_dict': { | |
74 | 'id': '_xvg/m_cmbatw=', | |
75 | 'ext': 'mp4', | |
76 | 'title': 'md5:a93e8ecf2e4073bfdffcb38f59945411', | |
77 | 'timestamp': 1603092840, | |
78 | 'upload_date': '20201019', | |
79 | 'thumbnail': 'https://ant1media.azureedge.net/imgHandler/640/756206d2-d640-40e2-b201-3555abdfc0db.jpg', | |
80 | }, | |
81 | }, { | |
82 | 'url': 'https://ant1news.gr/Society/article/620286/symmoria-anilikon-dikigoros-thymaton-ithelan-na-toys-apoteleiosoyn', | |
83 | 'info_dict': { | |
84 | 'id': '620286', | |
85 | 'title': 'md5:91fe569e952e4d146485740ae927662b', | |
86 | }, | |
87 | 'playlist_mincount': 2, | |
88 | 'params': { | |
89 | 'skip_download': True, | |
90 | }, | |
91 | }] | |
92 | ||
93 | def _real_extract(self, url): | |
94 | video_id = self._match_id(url) | |
95 | webpage = self._download_webpage(url, video_id) | |
96 | info = self._search_json_ld(webpage, video_id, expected_type='NewsArticle') | |
97 | embed_urls = list(Ant1NewsGrEmbedIE._extract_urls(webpage)) | |
98 | if not embed_urls: | |
99 | raise ExtractorError('no videos found for %s' % video_id, expected=True) | |
100 | return self.url_result_or_playlist_from_matches( | |
101 | embed_urls, video_id, info['title'], ie=Ant1NewsGrEmbedIE.ie_key(), | |
102 | video_kwargs={'url_transparent': True, 'timestamp': info.get('timestamp')}) | |
103 | ||
104 | ||
105 | class Ant1NewsGrEmbedIE(Ant1NewsGrBaseIE): | |
106 | IE_NAME = 'ant1newsgr:embed' | |
107 | IE_DESC = 'ant1news.gr embedded videos' | |
108 | _BASE_PLAYER_URL_RE = r'(?:https?:)?//(?:[a-zA-Z0-9\-]+\.)?(?:antenna|ant1news)\.gr/templates/pages/player' | |
109 | _VALID_URL = rf'{_BASE_PLAYER_URL_RE}\?([^#]+&)?cid=(?P<id>[^#&]+)' | |
110 | _API_PATH = '/news/templates/data/jsonPlayer' | |
111 | ||
112 | _TESTS = [{ | |
113 | 'url': 'https://www.antenna.gr/templates/pages/player?cid=3f_li_c_az_jw_y_u=&w=670&h=377', | |
114 | 'md5': 'dfc58c3a11a5a9aad2ba316ed447def3', | |
115 | 'info_dict': { | |
116 | 'id': '3f_li_c_az_jw_y_u=', | |
117 | 'ext': 'mp4', | |
118 | 'title': 'md5:a30c93332455f53e1e84ae0724f0adf7', | |
119 | 'thumbnail': 'https://ant1media.azureedge.net/imgHandler/640/bbe31201-3f09-4a4e-87f5-8ad2159fffe2.jpg', | |
120 | }, | |
121 | }] | |
122 | ||
123 | @classmethod | |
124 | def _extract_urls(cls, webpage): | |
125 | _EMBED_URL_RE = rf'{cls._BASE_PLAYER_URL_RE}\?(?:(?!(?P=_q1)).)+' | |
126 | _EMBED_RE = rf'<iframe[^>]+?src=(?P<_q1>["\'])(?P<url>{_EMBED_URL_RE})(?P=_q1)' | |
127 | for mobj in re.finditer(_EMBED_RE, webpage): | |
128 | url = unescapeHTML(mobj.group('url')) | |
129 | if not cls.suitable(url): | |
130 | continue | |
131 | yield url | |
132 | ||
133 | def _real_extract(self, url): | |
134 | video_id = self._match_id(url) | |
135 | ||
136 | canonical_url = self._request_webpage( | |
137 | HEADRequest(url), video_id, | |
138 | note='Resolve canonical player URL', | |
139 | errnote='Could not resolve canonical player URL').geturl() | |
140 | _, netloc, _, _, query, _ = urllib.parse.urlparse(canonical_url) | |
141 | cid = urllib.parse.parse_qs(query)['cid'][0] | |
142 | ||
143 | return self._download_and_extract_api_data(video_id, netloc, cid=cid) |