Repository: yt-dlp/yt-dlp

Issue:
raiplayradio.it moved to raiplaysound.it; website structure changed
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2021.12.01**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#video-url-contains-an-ampersand-and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [ ] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

Italy

### Description

raiplayradio.it has been renamed to [raiplaysound.it](https://www.raiplaysound.it) and the website structure changed.
The new website looks very similar to the already supported raiplay.it (every page has a corresponding json document), so probably the existing code could be adapted to support both.

@nixxo @frafra

### Verbose log

```shell
[debug] Command-line config: ['-Uv', 'https://www.raiplayradio.it/audio/2019/07/RADIO3---LEZIONI-DI-MUSICA-36b099ff-4123-4443-9bf9-38e43ef5e025.html']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8 (No ANSI), err utf-8 (No ANSI), pref UTF-8
[debug] yt-dlp version 2021.12.01 [91f071af6]
[debug] Python version 3.10.1 (CPython 64bit) - Linux-5.10.84_1-x86_64-with-glibc2.32
[debug] exe versions: ffmpeg present (setts,needs_adtstoasc), ffprobe present
[debug] Optional libraries: mutagen, sqlite
[debug] Proxy map: {}
Latest version: 2021.12.01, Current version: 2021.12.01
yt-dlp is up to date (2021.12.01)
[debug] [RaiPlayRadio] Extracting URL: https://www.raiplayradio.it/audio/2019/07/RADIO3---LEZIONI-DI-MUSICA-36b099ff-4123-4443-9bf9-38e43ef5e025.html
[RaiPlayRadio] 36b099ff-4123-4443-9bf9-38e43ef5e025: Downloading webpage
ERROR: [RaiPlayRadio] 36b099ff-4123-4443-9bf9-38e43ef5e025: Unable to download webpage: HTTP Error 404: Not Found (caused by <HTTPError 404: 'Not Found'>); please report this issue on  https://github.com/yt-dlp/yt-dlp . Make sure you are using the latest version; see  https://github.com/yt-dlp/yt-dlp  on how to update. Be sure to call yt-dlp with the --verbose flag and include its complete output. (caused by <HTTPError 404: 'Not Found'>); please report this issue on  https://github.com/yt-dlp/yt-dlp . Make sure you are using the latest version; see  https://github.com/yt-dlp/yt-dlp  on how to update. Be sure to call yt-dlp with the --verbose flag and include its complete output.
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 715, in _request_webpage
    return self._downloader.urlopen(url_or_request)
  File "/usr/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 3385, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.10/urllib/request.py", line 557, in error
    result = self._call_chain(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py
--- a/yt_dlp/extractor/extractors.py
+++ b/yt_dlp/extractor/extractors.py
@@ -1190,9 +1190,10 @@
     RaiPlayIE,
     RaiPlayLiveIE,
     RaiPlayPlaylistIE,
+    RaiPlaySoundIE,
+    RaiPlaySoundLiveIE,
+    RaiPlaySoundPlaylistIE,
     RaiIE,
-    RaiPlayRadioIE,
-    RaiPlayRadioPlaylistIE,
 )
 from .raywenderlich import (
     RayWenderlichIE,
diff --git a/yt_dlp/extractor/rai.py b/yt_dlp/extractor/rai.py
--- a/yt_dlp/extractor/rai.py
+++ b/yt_dlp/extractor/rai.py
@@ -14,16 +14,14 @@
     find_xpath_attr,
     fix_xml_ampersands,
     GeoRestrictedError,
-    get_element_by_class,
     HEADRequest,
     int_or_none,
     join_nonempty,
     parse_duration,
-    parse_list,
     remove_start,
     strip_or_none,
+    traverse_obj,
     try_get,
-    unescapeHTML,
     unified_strdate,
     unified_timestamp,
     update_url_query,
@@ -37,7 +35,7 @@ class RaiBaseIE(InfoExtractor):
     _GEO_COUNTRIES = ['IT']
     _GEO_BYPASS = False
 
-    def _extract_relinker_info(self, relinker_url, video_id):
+    def _extract_relinker_info(self, relinker_url, video_id, audio_only=False):
         if not re.match(r'https?://', relinker_url):
             return {'formats': [{'url': relinker_url}]}
 
@@ -80,7 +78,15 @@ def _extract_relinker_info(self, relinker_url, video_id):
             if (ext == 'm3u8' and platform != 'mon') or (ext == 'f4m' and platform != 'flash'):
                 continue
 
-            if ext == 'm3u8' or 'format=m3u8' in media_url or platform == 'mon':
+            if ext == 'mp3':
+                formats.append({
+                    'url': media_url,
+                    'vcodec': 'none',
+                    'acodec': 'mp3',
+                    'format_id': 'http-mp3',
+                })
+                break
+            elif ext == 'm3u8' or 'format=m3u8' in media_url or platform == 'mon':
                 formats.extend(self._extract_m3u8_formats(
                     media_url, video_id, 'mp4', 'm3u8_native',
                     m3u8_id='hls', fatal=False))
@@ -101,7 +107,8 @@ def _extract_relinker_info(self, relinker_url, video_id):
         if not formats and geoprotection is True:
             self.raise_geo_restricted(countries=self._GEO_COUNTRIES, metadata_available=True)
 
-        formats.extend(self._create_http_urls(relinker_url, formats))
+        if not audio_only:
+            formats.extend(self._create_http_urls(relinker_url, formats))
 
         return dict((k, v) for k, v in {
             'is_live': is_live,
@@ -360,26 +367,44 @@ class RaiPlayLiveIE(RaiPlayIE):
 
 
 class RaiPlayPlaylistIE(InfoExtractor):
-    _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/programmi/(?P<id>[^/?#&]+))'
+    _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/programmi/(?P<id>[^/?#&]+))(?:/(?P<extra_id>[^?#&]+))?'
     _TESTS = [{
-        'url': 'http://www.raiplay.it/programmi/nondirloalmiocapo/',
+        'url': 'https://www.raiplay.it/programmi/nondirloalmiocapo/',
         'info_dict': {
             'id': 'nondirloalmiocapo',
             'title': 'Non dirlo al mio capo',
             'description': 'md5:98ab6b98f7f44c2843fd7d6f045f153b',
         },
         'playlist_mincount': 12,
+    }, {
+        'url': 'https://www.raiplay.it/programmi/nondirloalmiocapo/episodi/stagione-2/',
+        'info_dict': {
+            'id': 'nondirloalmiocapo',
+            'title': 'Non dirlo al mio capo - Stagione 2',
+            'description': 'md5:98ab6b98f7f44c2843fd7d6f045f153b',
+        },
+        'playlist_mincount': 12,
     }]
 
     def _real_extract(self, url):
-        base, playlist_id = self._match_valid_url(url).groups()
+        base, playlist_id, extra_id = self._match_valid_url(url).groups()
 
         program = self._download_json(
             base + '.json', playlist_id, 'Downloading program JSON')
 
+        if extra_id:
+            extra_id = extra_id.upper().rstrip('/')
+
+        playlist_title = program.get('name')
         entries = []
         for b in (program.get('blocks') or []):
             for s in (b.get('sets') or []):
+                if extra_id:
+                    if extra_id != join_nonempty(
+                            b.get('name'), s.get('name'), delim='/').replace(' ', '-').upper():
+                        continue
+                    playlist_title = join_nonempty(playlist_title, s.get('name'), delim=' - ')
+
                 s_id = s.get('id')
                 if not s_id:
                     continue
@@ -398,10 +423,128 @@ def _real_extract(self, url):
                         video_id=RaiPlayIE._match_id(video_url)))
 
         return self.playlist_result(
-            entries, playlist_id, program.get('name'),
+            entries, playlist_id, playlist_title,
             try_get(program, lambda x: x['program_info']['description']))
 
 
+class RaiPlaySoundIE(RaiBaseIE):
+    _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplaysound\.it/.+?-(?P<id>%s))\.(?:html|json)' % RaiBaseIE._UUID_RE
+    _TESTS = [{
+        'url': 'https://www.raiplaysound.it/audio/2021/12/IL-RUGGITO-DEL-CONIGLIO-1ebae2a7-7cdb-42bb-842e-fe0d193e9707.html',
+        'md5': '8970abf8caf8aef4696e7b1f2adfc696',
+        'info_dict': {
+            'id': '1ebae2a7-7cdb-42bb-842e-fe0d193e9707',
+            'ext': 'mp3',
+            'title': 'Il Ruggito del Coniglio del 10/12/2021',
+            'description': 'md5:2a17d2107e59a4a8faa0e18334139ee2',
+            'thumbnail': r're:^https?://.*\.jpg$',
+            'uploader': 'rai radio 2',
+            'duration': 5685,
+            'series': 'Il Ruggito del Coniglio',
+        },
+        'params': {
+            'skip_download': True,
+        },
+    }]
+
+    def _real_extract(self, url):
+        base, audio_id = self._match_valid_url(url).group('base', 'id')
+        media = self._download_json(f'{base}.json', audio_id, 'Downloading audio JSON')
+        uid = try_get(media, lambda x: remove_start(remove_start(x['uniquename'], 'ContentItem-'), 'Page-'))
+
+        info = {}
+        formats = []
+        relinkers = set(traverse_obj(media, (('downloadable_audio', 'audio', ('live', 'cards', 0, 'audio')), 'url')))
+        for r in relinkers:
+            info = self._extract_relinker_info(r, audio_id, True)
+            formats.extend(info.get('formats'))
+
+        date_published = try_get(media, (lambda x: f'{x["create_date"]} {x.get("create_time") or ""}',
+                                         lambda x: x['live']['create_date']))
+
+        podcast_info = traverse_obj(media, 'podcast_info', ('live', 'cards', 0)) or {}
+        thumbnails = [{
+            'url': urljoin(url, thumb_url),
+        } for thumb_url in (podcast_info.get('images') or {}).values() if thumb_url]
+
+        return {
+            **info,
+            'id': uid or audio_id,
+            'display_id': audio_id,
+            'title': traverse_obj(media, 'title', 'episode_title'),
+            'alt_title': traverse_obj(media, ('track_info', 'media_name')),
+            'description': media.get('description'),
+            'uploader': traverse_obj(media, ('track_info', 'channel'), expected_type=strip_or_none),
+            'creator': traverse_obj(media, ('track_info', 'editor'), expected_type=strip_or_none),
+            'timestamp': unified_timestamp(date_published),
+            'thumbnails': thumbnails,
+            'series': podcast_info.get('title'),
+            'season_number': int_or_none(media.get('season')),
+            'episode': media.get('episode_title'),
+            'episode_number': int_or_none(media.get('episode')),
+            'formats': formats,
+        }
+
+
+class RaiPlaySoundLiveIE(RaiPlaySoundIE):
+    _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplaysound\.it/(?P<id>[^/?#&]+)$)'
+    _TESTS = [{
+        'url': 'https://www.raiplaysound.it/radio2',
+        'info_dict': {
+            'id': 'b00a50e6-f404-4af6-8f8c-ff3b9af73a44',
+            'display_id': 'radio2',
+            'ext': 'mp4',
+            'title': 'Rai Radio 2',
+            'uploader': 'rai radio 2',
+            'creator': 'raiplaysound',
+            'is_live': True,
+        },
+        'params': {
+            'skip_download': 'live',
+        },
+    }]
+
+
+class RaiPlaySoundPlaylistIE(InfoExtractor):
+    _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplaysound\.it/(?:programmi|playlist|audiolibri)/(?P<id>[^/?#&]+))(?:/(?P<extra_id>[^?#&]+))?'
+    _TESTS = [{
+        'url': 'https://www.raiplaysound.it/programmi/ilruggitodelconiglio',
+        'info_dict': {
+            'id': 'ilruggitodelconiglio',
+            'title': 'Il Ruggito del Coniglio',
+            'description': 'md5:1bbaf631245a7ab1ec4d9fbb3c7aa8f3',
+        },
+        'playlist_mincount': 65,
+    }, {
+        'url': 'https://www.raiplaysound.it/programmi/ilruggitodelconiglio/puntate/prima-stagione-1995',
+        'info_dict': {
+            'id': 'ilruggitodelconiglio_puntate_prima-stagione-1995',
+            'title': 'Prima Stagione 1995',
+        },
+        'playlist_count': 1,
+    }]
+
+    def _real_extract(self, url):
+        base, playlist_id, extra_id = self._match_valid_url(url).group('base', 'id', 'extra_id')
+        url = f'{base}.json'
+        program = self._download_json(url, playlist_id, 'Downloading program JSON')
+
+        if extra_id:
+            extra_id = extra_id.rstrip('/')
+            playlist_id += '_' + extra_id.replace('/', '_')
+            path = next(c['path_id'] for c in program.get('filters') or [] if extra_id in c.get('weblink'))
+            program = self._download_json(
+                urljoin('https://www.raiplaysound.it', path), playlist_id, 'Downloading program secondary JSON')
+
+        entries = [
+            self.url_result(urljoin(base, c['path_id']), ie=RaiPlaySoundIE.ie_key())
+            for c in traverse_obj(program, 'cards', ('block', 'cards')) or []
+            if c.get('path_id')]
+
+        return self.playlist_result(entries, playlist_id, program.get('title'),
+                                    traverse_obj(program, ('podcast_info', 'description')))
+
+
 class RaiIE(RaiBaseIE):
     _VALID_URL = r'https?://[^/]+\.(?:rai\.(?:it|tv)|rainews\.it)/.+?-(?P<id>%s)(?:-.+?)?\.html' % RaiBaseIE._UUID_RE
     _TESTS = [{
@@ -594,84 +737,3 @@ def _real_extract(self, url):
         info.update(relinker_info)
 
         return info
-
-
-class RaiPlayRadioBaseIE(InfoExtractor):
-    _BASE = 'https://www.raiplayradio.it'
-
-    def get_playlist_iter(self, url, uid):
-        webpage = self._download_webpage(url, uid)
-        for attrs in parse_list(webpage):
-            title = attrs['data-title'].strip()
-            audio_url = urljoin(url, attrs['data-mediapolis'])
-            entry = {
-                'url': audio_url,
-                'id': attrs['data-uniquename'].lstrip('ContentItem-'),
-                'title': title,
-                'ext': 'mp3',
-                'language': 'it',
-            }
-            if 'data-image' in attrs:
-                entry['thumbnail'] = urljoin(url, attrs['data-image'])
-            yield entry
-
-
-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': r're:^https?://.*\.jpg$',
-            'language': 'it',
-        }
-    }
-
-    def _real_extract(self, url):
-        audio_id = self._match_id(url)
-        list_url = url.replace('.html', '-list.html')
-        return next(entry for entry in self.get_playlist_iter(list_url, audio_id) if entry['id'] == audio_id)
-
-
-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 = list(self.get_playlist_iter(list_url, playlist_id))
-        for index, entry in enumerate(entries, start=1):
-            entry.update({
-                'track': entry['title'],
-                'track_number': index,
-                'artist': playlist_creator,
-                'album': playlist_title
-            })
-
-        return self.playlist_result(
-            entries, playlist_id, playlist_title, playlist_description,
-            creator=playlist_creator)


Test patch: