5 from .common
import InfoExtractor
9 get_elements_html_by_class
,
17 class TV24UAVideoIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://24tv\.ua/news/showPlayer\.do.*?(?:\?|&)objectId=(?P<id>\d+)'
19 _EMBED_REGEX
= [rf
'<iframe[^>]+?src=["\']?(?P<url>{_VALID_URL})["\']?']
22 'url': 'https://24tv.ua/news/showPlayer.do?objectId=2074790&videoUrl=2022/07/2074790&w=640&h=360',
26 'title': 'У Харкові ворожа ракета прилетіла в будинок, де слухали пісні про "офіцерів-росіян"',
27 'thumbnail': r
're:^https?://.*\.jpe?g',
30 'url': 'https://24tv.ua/news/showPlayer.do?videoUrl=2022/07/2074790&objectId=2074790&w=640&h=360',
31 'only_matching': True,
36 # iframe embed created from share menu.
37 'url': 'data:text/html,%3Ciframe%20src=%22https://24tv.ua/news/showPlayer.do?objectId=1886193&videoUrl'
38 '=2022/03/1886193&w=640&h=360%22%20width=%22640%22%20height=%22360%22%20frameborder=%220%22'
39 '%20scrolling=%22no%22%3E%3C/iframe%3E',
43 'title': 'Росіяни руйнують Бородянку на Київщині та стріляють з літаків по мешканцях: шокуючі фото',
44 'thumbnail': r
're:^https?://.*\.jpe?g',
48 'url': 'https://24tv.ua/vipalyuyut-nashi-mista-sela-dsns-pokazali-motoroshni-naslidki_n1883966',
52 'title': 'Випалюють наші міста та села, – моторошні наслідки обстрілів на Чернігівщині',
53 'thumbnail': r
're:^https?://.*\.jpe?g',
55 'params': {'allowed_extractors': ['Generic', '24tv.ua']}
,
59 def _real_extract(self
, url
):
60 video_id
= self
._match
_id
(url
)
61 webpage
= self
._download
_webpage
(url
, video_id
)
65 for j
in re
.findall(r
'vPlayConfig\.sources\s*=\s*(?P<json>\[{\s*(?s:.+?)\s*}])', webpage
):
66 sources
= self
._parse
_json
(j
, video_id
, fatal
=False, ignore_extra
=True, transform_source
=js_to_json
, errnote
='') or []
67 for source
in sources
:
68 if mimetype2ext(traverse_obj(source
, 'type')) == 'm3u8':
69 f
, s
= self
._extract
_m
3u8_formats
_and
_subtitles
(source
['src'], video_id
)
71 self
._merge
_subtitles
(subtitles
, s
)
75 'ext': determine_ext(source
['src']),
77 thumbnail
= traverse_obj(
79 r
'var\s*vPlayConfig\s*=\s*', webpage
, 'thumbnail',
80 video_id
, default
=None, transform_source
=js_to_json
), 'poster')
81 self
._sort
_formats
(formats
)
85 'subtitles': subtitles
,
86 'thumbnail': thumbnail
or self
._og
_search
_thumbnail
(webpage
),
87 'title': self
._html
_extract
_title
(webpage
) or self
._og
_search
_title
(webpage
),
88 'description': self
._og
_search
_description
(webpage
, default
=None),
92 class TV24UAGenericPassthroughIE(InfoExtractor
):
93 _VALID_URL
= r
'https?://(?:[a-zA-Z0-9]+?\.)?24tv\.ua/(?P<id>[^/]+?_n\d+)'
96 # Generic iframe, not within media_embed
97 'url': 'https://24tv.ua/vipalyuyut-nashi-mista-sela-dsns-pokazali-motoroshni-naslidki_n1883966',
101 'title': 'Випалюють наші міста та села, – моторошні наслідки обстрілів на Чернігівщині',
102 'thumbnail': r
're:^https?://.*\.jpe?g',
105 # Generic iframe embed of TV24UAPlayerIE, within media_embed
106 'url': 'https://24tv.ua/harkivyani-zgaduyut-misto-do-viyni-shhemlive-video_n1887584',
108 'id': 'harkivyani-zgaduyut-misto-do-viyni-shhemlive-video_n1887584',
109 'title': 'Харків\'яни згадують місто до війни: щемливе відео'
115 'title': 'Харків\'яни згадують місто до війни: щемливе відео',
116 'thumbnail': r
're:^https?://.*\.jpe?g',
120 # 2 media_embeds with YouTube iframes
121 'url': 'https://24tv.ua/bronetransporteri-ozbroyenni-zsu-shho-vidomo-pro-bronovik-wolfhound_n2167966',
123 'id': 'bronetransporteri-ozbroyenni-zsu-shho-vidomo-pro-bronovik-wolfhound_n2167966',
124 'title': 'Броньовик Wolfhound: гігант, який допомагає ЗСУ знищувати окупантів на фронті',
128 'url': 'https://men.24tv.ua/fitnes-bloger-sprobuvav-vikonati-trenuvannya-naysilnishoyi-lyudini_n2164538',
129 'only_matching': True,
132 def _real_extract(self
, url
):
133 display_id
= self
._match
_id
(url
)
134 webpage
= self
._download
_webpage
(url
, display_id
)
136 # The site contains escaped iframe embeds within an attribute.
137 # Once escaped, generic can handle them, so we use a data url to pass the escaped html back.
138 for html
in get_elements_html_by_class('media_embed', webpage
):
139 data
= urllib
.parse
.unquote(extract_attributes(html
).get('data-html'))
140 data_urls
.append(f
'data:text/html;base64,{base64.b64encode(data.encode("utf-8")).decode("utf-8")}')
143 return self
.url_result(url
, 'Generic')
144 return self
.playlist_from_matches(
145 [smuggle_url(url
, {'to_generic': True}
) for url
in data_urls
], display_id
, ie
='Generic',
146 playlist_title
=self
._og
_search
_title
(webpage
) or self
._html
_extract
_title
(webpage
))