1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 17:22:31 +01:00

[PromoDJ] Update radio extractor and add tests

This commit is contained in:
DmitryScaletta 2024-02-17 05:06:06 +03:00
parent e32ba3fc21
commit 49ac5d31a3
No known key found for this signature in database
GPG Key ID: 167A65222EDD4C2A

View File

@ -6,16 +6,17 @@
from .common import InfoExtractor from .common import InfoExtractor
from .youtube import YoutubeIE from .youtube import YoutubeIE
from ..utils import ( from ..utils import (
OnDemandPagedList,
clean_html, clean_html,
dict_get, dict_get,
extract_attributes, extract_attributes,
ExtractorError, ExtractorError,
get_element_by_class, get_element_by_class,
get_element_html_by_id,
get_elements_html_by_class, get_elements_html_by_class,
int_or_none, int_or_none,
js_to_json, js_to_json,
merge_dicts, merge_dicts,
OnDemandPagedList,
parse_duration, parse_duration,
str_or_none, str_or_none,
traverse_obj, traverse_obj,
@ -989,19 +990,53 @@ class PromoDJRadioIE(PromoDJBaseIE):
_VALID_URL = rf'{PromoDJBaseIE._BASE_URL_RE}/radio#(?P<id>\w+)' _VALID_URL = rf'{PromoDJBaseIE._BASE_URL_RE}/radio#(?P<id>\w+)'
_TESTS = [{ _TESTS = [{
'url': 'https://promodj.com/radio#dubstep', 'url': 'https://promodj.com/radio#dubstep',
'only_matching': True, 'info_dict': {
'id': 'dubstep',
'ext': 'mp3',
'title': r're:^Dubstep ',
'description': 'Всё лучше под дабстеп',
'thumbnail': r're:^https?://',
'live_status': 'is_live',
},
}, { }, {
'url': 'https://promodj.com/radio#oldschool', 'url': 'https://promodj.com/radio#oldschool',
'only_matching': True, 'info_dict': {
'id': 'oldschool',
'ext': 'mp3',
'title': r're:^Old-School ',
'description': 'То самое доброе, старое, вечное',
'thumbnail': r're:^https?://',
'live_status': 'is_live',
},
}] }]
def _real_extract(self, url): def _real_extract(self, url):
id = self._match_id(url) slug = self._match_id(url)
html = self._download_webpage(url, slug)
radio_span = get_element_html_by_id(f'radio_{slug}', html)
if not radio_span:
raise ExtractorError('Radio channel is offline or not exists', expected=True)
id = self._search_regex(r'amba="radio:(\d+)"', radio_span, 'id')
tooltip_html = self._download_webpage(
f'https://promodj.com/ajax/tooltip.html?wtf=radio:{id}', slug,
note='Downloading tooltip webpage')
title = clean_html(self._search_regex(
r'<h1[^>]*><b>([^<]+)</b></h1>', tooltip_html, 'title', default=None))
description = clean_html(self._search_regex(
r'<div>([^<]+)</div>', tooltip_html, 'description', default=None))
thumbnail = self._search_regex(
rf'#radio_{slug}:after {{ background-image: url\(([^)]+)\); }}',
html, 'thumbnail', default=None)
return { return {
'id': id, 'id': slug,
'title': title,
'description': description,
'thumbnail': url_or_none(thumbnail),
'formats': [{ 'formats': [{
'url': f'https://radio.promodj.com/{id}-192', 'url': f'https://radio.promodj.com/{slug}-192',
'abr': 192, 'abr': 192,
'ext': 'mp3',
}], }],
'is_live': True, 'is_live': True,
} }