3 from .common
import InfoExtractor
10 get_element_html_by_id
,
18 class MegaTVComBaseIE(InfoExtractor
):
19 _PLAYER_DIV_ID
= 'player_div_id'
21 def _extract_player_attrs(self
, webpage
):
22 player_el
= get_element_html_by_id(self
._PLAYER
_DIV
_ID
, webpage
)
24 re
.sub(r
'^data-(?:kwik_)?', '', k
): v
25 for k
, v
in extract_attributes(player_el
).items()
30 class MegaTVComIE(MegaTVComBaseIE
):
32 IE_DESC
= 'megatv.com videos'
33 _VALID_URL
= r
'https?://(?:www\.)?megatv\.com/(?:\d{4}/\d{2}/\d{2}|[^/]+/(?P<id>\d+))/(?P<slug>[^/]+)'
36 'url': 'https://www.megatv.com/2021/10/23/egkainia-gia-ti-nea-skini-omega-tou-dimotikou-theatrou-peiraia/',
37 'md5': '6546a1a37fff0dd51c9dce5f490b7d7d',
41 'title': 'md5:70eef71a9cd2c1ecff7ee428354dded2',
42 'description': 'md5:0209fa8d318128569c0d256a5c404db1',
43 'timestamp': 1634975747,
44 'upload_date': '20211023',
45 'display_id': 'egkainia-gia-ti-nea-skini-omega-tou-dimotikou-theatrou-peiraia',
46 'thumbnail': 'https://www.megatv.com/wp-content/uploads/2021/10/ΠΕΙΡΑΙΑΣ-1024x450.jpg',
49 'url': 'https://www.megatv.com/tvshows/527800/epeisodio-65-12/',
50 'md5': 'cba2085d45c1abeb8e7e9b7e1d6c0072',
54 'title': 'md5:fc322cb51f682eecfe2f54cd5ab3a157',
55 'description': 'md5:b2b7ed3690a78f2a0156eb790fdc00df',
56 'timestamp': 1636048859,
57 'upload_date': '20211104',
58 'display_id': 'epeisodio-65-12',
59 'thumbnail': 'https://www.megatv.com/wp-content/uploads/2021/11/16-1-1.jpg',
63 def _real_extract(self
, url
):
64 video_id
, display_id
= self
._match
_valid
_url
(url
).group('id', 'slug')
65 _is_article
= video_id
is None
66 webpage
= self
._download
_webpage
(url
, video_id
or display_id
)
68 video_id
= self
._search
_regex
(
69 r
'<article[^>]*\sid=["\']Article_(\d
+)["\']', webpage, 'article id')
70 player_attrs = self._extract_player_attrs(webpage)
71 title = player_attrs.get('label') or self._og_search_title(webpage)
72 description = get_element_by_class(
73 'article-wrapper' if _is_article else 'story_content',
75 description = clean_html(re.sub(r'<script[^>]*>[^<]+</script>', '', description))
77 description = self._og_search_description(webpage)
78 thumbnail = player_attrs.get('image') or self._og_search_thumbnail(webpage)
79 timestamp = unified_timestamp(self._html_search_meta(
80 'article:published_time', webpage))
81 source = player_attrs.get('source')
83 raise ExtractorError('No source found', video_id=video_id)
84 if determine_ext(source) == 'm3u8':
85 formats, subs = self._extract_m3u8_formats_and_subtitles(source, video_id, 'mp4')
87 formats, subs = [{'url': source}], {}
88 if player_attrs.get('subs'):
89 self._merge_subtitles({'und': [{'url': player_attrs['subs']}]}, target=subs)
90 self._sort_formats(formats)
93 'display_id': display_id,
95 'description': description,
96 'thumbnail': thumbnail,
97 'timestamp': timestamp,
103 class MegaTVComEmbedIE(MegaTVComBaseIE):
104 IE_NAME = 'megatvcom:embed'
105 IE_DESC = 'megatv.com embedded videos'
106 _VALID_URL = r'(?:https?:)?//(?:www\.)?megatv\.com/embed/?\?p=(?P<id>\d+)'
107 _EMBED_REGEX = [rf'''<iframe[^>]+?src=(?P<_q1>["'])(?P<url>{_VALID_URL})(?P=_q1)''']
110 'url
': 'https
://www
.megatv
.com
/embed
/?p
=2020520979',
111 'md5
': '6546a1a37fff0dd51c9dce5f490b7d7d
',
115 'title
': 'md5
:70eef71a9cd2c1ecff7ee428354dded2
',
116 'description
': 'md5
:0209fa8d318128569c0d256a5c404db1
',
117 'timestamp
': 1634975747,
118 'upload_date
': '20211023',
119 'display_id
': 'egkainia
-gia
-ti
-nea
-skini
-omega
-tou
-dimotikou
-theatrou
-peiraia
',
120 'thumbnail
': 'https
://www
.megatv
.com
/wp
-content
/uploads
/2021/10/ΠΕΙΡΑΙΑΣ
-1024x450
.jpg
',
123 'url
': 'https
://www
.megatv
.com
/embed
/?p
=2020534081',
124 'md5
': '6ac8b3ce4dc6120c802f780a1e6b3812
',
128 'title
': 'md5
:062e9d5976ef854d8bdc1f5724d9b2d0
',
129 'description
': 'md5
:36dbe4c3762d2ede9513eea8d07f6d52
',
130 'timestamp
': 1636376351,
131 'upload_date
': '20211108',
132 'display_id
': 'neo
-rekor
-stin
-timi
-tou
-ilektrikou
-reymatos
-pano
-apo
-ta
-200e
-i
-xondriki
-timi
-tou
-ilektrikou
',
133 'thumbnail
': 'https
://www
.megatv
.com
/wp
-content
/uploads
/2021/11/Capture
-266.jpg
',
137 def _match_canonical_url(self, webpage):
140 rel=(?P<_q1>["'])(?P
<canonical
>canonical
)(?P
=_q1
)|
141 href
=(?P
<_q2
>["'])(?P<href>(?:(?!(?P=_q2)).)+)(?P=_q2)|
145 for mobj in re.finditer(LINK_RE, webpage):
146 canonical, href = mobj.group('canonical', 'href')
147 if canonical and href:
148 return unescapeHTML(href)
150 def _real_extract(self, url):
151 video_id = self._match_id(url)
152 webpage = self._download_webpage(url, video_id)
153 player_attrs = self._extract_player_attrs(webpage)
154 canonical_url = player_attrs.get('share_url') or self._match_canonical_url(webpage)
155 if not canonical_url:
156 raise ExtractorError('canonical URL not found')
157 video_id = parse_qs(canonical_url)['p'][0]
159 # Defer to megatvcom as the metadata extracted from the embeddable page some
160 # times are slightly different, for the same video
161 canonical_url = self._request_webpage(
162 HEADRequest(canonical_url), video_id,
163 note='Resolve canonical URL',
164 errnote='Could not resolve canonical URL').geturl()
165 return self.url_result(canonical_url, MegaTVComIE.ie_key(), video_id)