1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2025-01-05 20:57:54 +01:00

Add support for raiplayradio.it

This commit is contained in:
Francesco Frassinelli 2019-07-21 00:24:01 +02:00
parent 5e1c39ac85
commit 3d10b1b8a6
3 changed files with 103 additions and 0 deletions

View File

@ -718,6 +718,8 @@
- **RaiPlay**
- **RaiPlayLive**
- **RaiPlayPlaylist**
- **RaiPlayRadio**
- **RaiPlayRadioPlaylist**
- **RayWenderlich**
- **RayWenderlichCourse**
- **RBMARadio**

View File

@ -919,6 +919,8 @@ from .rai import (
RaiPlayLiveIE,
RaiPlayPlaylistIE,
RaiIE,
RaiPlayRadioIE,
RaiPlayRadioPlaylistIE,
)
from .raywenderlich import (
RayWenderlichIE,

View File

@ -4,6 +4,7 @@ import re
from .common import InfoExtractor
from ..compat import (
compat_HTMLParser,
compat_urlparse,
compat_str,
)
@ -13,6 +14,7 @@ from ..utils import (
find_xpath_attr,
fix_xml_ampersands,
GeoRestrictedError,
get_element_by_class,
int_or_none,
parse_duration,
strip_or_none,
@ -500,3 +502,100 @@ class RaiIE(RaiBaseIE):
info.update(relinker_info)
return info
class HTMLListAttrsParser(compat_HTMLParser):
def __init__(self):
compat_HTMLParser.__init__(self)
self.items = []
self._level = 0
def handle_starttag(self, tag, attrs):
if tag == 'li' and self._level == 0:
self.items.append(dict(attrs))
self._level += 1
def handle_endtag(self, tag):
self._level -= 1
class RaiPlayRadioBaseIE(InfoExtractor):
_BASE = 'https://www.raiplayradio.it'
def parse_list(self, webpage):
parser = HTMLListAttrsParser()
parser.feed(webpage)
parser.close()
return parser.items
def get_playlist_iter(self, url):
webpage = self._download_webpage(url, url)
for attrs in self.parse_list(webpage):
title = attrs['data-title'].strip()
webpage = urljoin(url, attrs['data-mediapolis'])
audio_url = compat_str(self._request_webpage(webpage, title).geturl())
yield {
'url': audio_url,
'id': attrs['data-uniquename'].lstrip('ContentItem-'),
'title': title,
'ext': determine_ext(audio_url),
'thumbnail': urljoin(url, attrs['data-image']),
'language': 'it',
}
def get_playlist(self, *args, **kwargs):
return list(self.get_playlist_iter(*args, **kwargs))
class RaiPlayRadioIE(RaiPlayRadioBaseIE):
_VALID_URL = r'%s/audio/.+?-(?P<id>%s)\.html' % (RaiPlayRadioBaseIE._BASE, RaiBaseIE._UUID_RE)
_TEST = {
'url': 'https://www.raiplayradio.it/audio/2019/07/RADIO3---LEZIONI-DI-MUSICA-36b099ff-4123-4443-9bf9-38e43ef5e025.html',
'info_dict': {
'id': '36b099ff-4123-4443-9bf9-38e43ef5e025',
'ext': 'mp3',
'title': 'Dal "Chiaro di luna" al "Clair de lune", prima parte con Giovanni Bietti',
'thumbnail': 'https://www.raiplayradio.it/cropgd/400x400/dl/img/2019/07/08/1562590329054_luna.jpg',
'language': 'it',
}
}
def _real_extract(self, url):
list_url = url.replace('.html', '-list.html')
for entry in self.get_playlist_iter(list_url):
if entry['id'] == self._match_id(url):
return entry
class RaiPlayRadioPlaylistIE(RaiPlayRadioBaseIE):
_VALID_URL = r'%s/playlist/.+?-(?P<id>%s)\.html' % (RaiPlayRadioBaseIE._BASE, RaiBaseIE._UUID_RE)
_TEST = {
'url': 'https://www.raiplayradio.it/playlist/2017/12/Alice-nel-paese-delle-meraviglie-72371d3c-d998-49f3-8860-d168cfdf4966.html',
'info_dict': {
'id': '72371d3c-d998-49f3-8860-d168cfdf4966',
'title': "Alice nel paese delle meraviglie",
'description': "di Lewis Carrol letto da Aldo Busi",
},
'playlist_count': 11,
}
def _real_extract(self, url):
playlist_id = self._match_id(url)
playlist_webpage = self._download_webpage(url, playlist_id)
playlist_title = unescapeHTML(self._html_search_regex(r'data-playlist-title="(.+?)"', playlist_webpage, 'title'))
playlist_creator = self._html_search_meta('nomeProgramma', playlist_webpage)
playlist_description = get_element_by_class('textDescriptionProgramma', playlist_webpage)
player_href = self._html_search_regex(r'data-player-href="(.+?)"', playlist_webpage, 'href')
list_url = urljoin(url, player_href)
entries = self.get_playlist(list_url)
for index, entry in enumerate(entries, start=1):
entry.update({
'track': entry['title'],
'track_number': index,
'album': playlist_title,
'artist': playlist_creator,
})
return self.playlist_result(entries, playlist_id, playlist_title, playlist_description)