]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/rai.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / rai.py
index 39e57decd51a4ae626cb468935383c9e98bca07d..cab12cc214a0b64788cb4aeb9fc7b3e4d6056292 100644 (file)
@@ -1,6 +1,3 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import re
 
 from .common import InfoExtractor
@@ -9,21 +6,21 @@
     compat_urlparse,
 )
 from ..utils import (
+    clean_html,
     determine_ext,
     ExtractorError,
+    filter_dict,
     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 +34,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}]}
 
@@ -49,11 +46,14 @@ def _extract_relinker_info(self, relinker_url, video_id):
         for platform in ('mon', 'flash', 'native'):
             relinker = self._download_xml(
                 relinker_url, video_id,
-                note='Downloading XML metadata for platform %s' % platform,
+                note=f'Downloading XML metadata for platform {platform}',
                 transform_source=fix_xml_ampersands,
                 query={'output': 45, 'pl': platform},
                 headers=self.geo_verification_headers())
 
+            if xpath_text(relinker, './license_url', default='{}') != '{}':
+                self.report_drm(video_id)
+
             if not geoprotection:
                 geoprotection = xpath_text(
                     relinker, './geoprotection', default=None) == 'Y'
@@ -80,7 +80,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))
@@ -95,22 +103,23 @@ def _extract_relinker_info(self, relinker_url, video_id):
                 formats.append({
                     'url': media_url,
                     'tbr': bitrate if bitrate > 0 else None,
-                    'format_id': 'http-%d' % bitrate if bitrate > 0 else 'http',
+                    'format_id': f'http-{bitrate if bitrate > 0 else "http"}',
                 })
 
         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 {
+        return filter_dict({
             'is_live': is_live,
             'duration': duration,
             'formats': formats,
-        }.items() if v is not None)
+        })
 
     def _create_http_urls(self, relinker_url, fmts):
-        _RELINKER_REG = r'https?://(?P<host>[^/]+?)/(?:i/)?(?P<extra>[^/]+?)/(?P<path>.+?)/(?P<id>\d+)(?:_(?P<quality>[\d\,]+))?(?:\.mp4|/playlist\.m3u8).+?'
+        _RELINKER_REG = r'https?://(?P<host>[^/]+?)/(?:i/)?(?P<extra>[^/]+?)/(?P<path>.+?)/(?P<id>\w+)(?:_(?P<quality>[\d\,]+))?(?:\.mp4|/playlist\.m3u8).+?'
         _MP4_TMPL = '%s&overrideUserAgentRule=mp4-%s'
         _QUALITY = {
             # tbr: w, h
@@ -147,7 +156,7 @@ def get_format_info(tbr):
             br = int_or_none(tbr)
             if len(fmts) == 1 and not br:
                 br = fmts[0].get('tbr')
-            if br > 300:
+            if br and br > 300:
                 tbr = compat_str(math.floor(br / 100) * 100)
             else:
                 tbr = '250'
@@ -166,11 +175,11 @@ def get_format_info(tbr):
                 'vcodec': format_copy.get('vcodec'),
                 'acodec': format_copy.get('acodec'),
                 'fps': format_copy.get('fps'),
-                'format_id': 'https-%s' % tbr,
+                'format_id': f'https-{tbr}',
             } if format_copy else {
                 'width': _QUALITY[tbr][0],
                 'height': _QUALITY[tbr][1],
-                'format_id': 'https-%s' % tbr,
+                'format_id': f'https-{tbr}',
                 'tbr': int(tbr),
             }
 
@@ -193,8 +202,8 @@ def get_format_info(tbr):
                 'url': _MP4_TMPL % (relinker_url, q),
                 'protocol': 'https',
                 'ext': 'mp4',
+                **get_format_info(q)
             }
-            fmt.update(get_format_info(q))
             formats.append(fmt)
         return formats
 
@@ -225,7 +234,7 @@ def _extract_subtitles(url, video_data):
 
 
 class RaiPlayIE(RaiBaseIE):
-    _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/.+?-(?P<id>%s))\.(?:html|json)' % RaiBaseIE._UUID_RE
+    _VALID_URL = rf'(?P<base>https?://(?:www\.)?raiplay\.it/.+?-(?P<id>{RaiBaseIE._UUID_RE}))\.(?:html|json)'
     _TESTS = [{
         'url': 'http://www.raiplay.it/video/2014/04/Report-del-07042014-cb27157f-9dd0-4aee-b788-b1f67643a391.html',
         'md5': '8970abf8caf8aef4696e7b1f2adfc696',
@@ -243,6 +252,10 @@ class RaiPlayIE(RaiBaseIE):
             'subtitles': {
                 'it': 'count:4',
             },
+            'release_year': 2022,
+            'episode': 'Espresso nel caffè - 07/04/2014',
+            'timestamp': 1396919880,
+            'upload_date': '20140408',
         },
         'params': {
             'skip_download': True,
@@ -262,6 +275,12 @@ class RaiPlayIE(RaiBaseIE):
             'duration': 6493,
             'series': 'Blanca',
             'season': 'Season 1',
+            'episode_number': 1,
+            'release_year': 2021,
+            'season_number': 1,
+            'episode': 'Senza occhi',
+            'timestamp': 1637318940,
+            'upload_date': '20211119',
         },
     }, {
         'url': 'http://www.raiplay.it/video/2016/11/gazebotraindesi-efebe701-969c-4593-92f3-285f0d1ce750.html?',
@@ -272,7 +291,7 @@ class RaiPlayIE(RaiBaseIE):
         'only_matching': True,
     }, {
         # DRM protected
-        'url': 'https://www.raiplay.it/video/2020/09/Lo-straordinario-mondo-di-Zoey-S1E1-Lo-straordinario-potere-di-Zoey-ed493918-1d32-44b7-8454-862e473d00ff.html',
+        'url': 'https://www.raiplay.it/video/2021/06/Lo-straordinario-mondo-di-Zoey-S2E1-Lo-straordinario-ritorno-di-Zoey-3ba992de-2332-41ad-9214-73e32ab209f4.html',
         'only_matching': True,
     }]
 
@@ -294,7 +313,6 @@ def _real_extract(self, url):
         video = media['video']
 
         relinker_info = self._extract_relinker_info(video['content_url'], video_id)
-        self._sort_formats(relinker_info['formats'])
 
         thumbnails = []
         for _, value in media.get('images', {}).items():
@@ -315,13 +333,13 @@ def _real_extract(self, url):
 
         alt_title = join_nonempty(media.get('subtitle'), media.get('toptitle'), delim=' - ')
 
-        info = {
+        return {
             'id': remove_start(media.get('id'), 'ContentItem-') or video_id,
             'display_id': video_id,
             'title': title,
-            'alt_title': strip_or_none(alt_title),
+            'alt_title': strip_or_none(alt_title or None),
             'description': media.get('description'),
-            'uploader': strip_or_none(media.get('channel')),
+            'uploader': strip_or_none(media.get('channel') or None),
             'creator': strip_or_none(media.get('editor') or None),
             'duration': parse_duration(video.get('duration')),
             'timestamp': unified_timestamp(date_published),
@@ -332,13 +350,12 @@ def _real_extract(self, url):
             'episode': media.get('episode_title'),
             'episode_number': int_or_none(media.get('episode')),
             'subtitles': subtitles,
+            'release_year': int_or_none(traverse_obj(media, ('track_info', 'edit_year'))),
+            **relinker_info
         }
 
-        info.update(relinker_info)
-        return info
-
 
-class RaiPlayLiveIE(RaiPlayIE):
+class RaiPlayLiveIE(RaiPlayIE):  # XXX: Do not subclass from concrete IE
     _VALID_URL = r'(?P<base>https?://(?:www\.)?raiplay\.it/dirette/(?P<id>[^/?#&]+))'
     _TESTS = [{
         'url': 'http://www.raiplay.it/dirette/rainews24',
@@ -351,6 +368,9 @@ class RaiPlayLiveIE(RaiPlayIE):
             'uploader': 'Rai News 24',
             'creator': 'Rai News 24',
             'is_live': True,
+            'live_status': 'is_live',
+            'upload_date': '20090502',
+            'timestamp': 1241276220,
         },
         'params': {
             'skip_download': True,
@@ -359,31 +379,49 @@ 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
                 medias = self._download_json(
-                    '%s/%s.json' % (base, s_id), s_id,
+                    f'{base}/{s_id}.json', s_id,
                     'Downloading content set JSON', fatal=False)
                 if not medias:
                     continue
@@ -397,16 +435,142 @@ 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 = rf'(?P<base>https?://(?:www\.)?raiplaysound\.it/.+?-(?P<id>{RaiBaseIE._UUID_RE}))\.(?:html|json)'
+    _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',
+            'alt_title': 'md5:0e6476cd57858bb0f3fcc835d305b455',
+            'description': 'md5:2a17d2107e59a4a8faa0e18334139ee2',
+            'thumbnail': r're:^https?://.*\.jpg$',
+            'uploader': 'rai radio 2',
+            'duration': 5685,
+            'series': 'Il Ruggito del Coniglio',
+            'episode': 'Il Ruggito del Coniglio del 10/12/2021',
+            'creator': 'rai radio 2',
+            'timestamp': 1638346620,
+            'upload_date': '20211201',
+        },
+        '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'), expected_type=strip_or_none),
+            '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):  # XXX: Do not subclass from concrete IE
+    _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': r're:Rai Radio 2 \d+-\d+-\d+ \d+:\d+',
+            'thumbnail': r're:https://www.raiplaysound.it/dl/img/.+?png',
+            'uploader': 'rai radio 2',
+            'series': 'Rai Radio 2',
+            'creator': 'raiplaysound',
+            'is_live': True,
+            'live_status': 'is_live',
+        },
+        '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
+    _VALID_URL = rf'https?://[^/]+\.(?:rai\.(?:it|tv))/.+?-(?P<id>{RaiBaseIE._UUID_RE})(?:-.+?)?\.html'
     _TESTS = [{
         # var uniquename = "ContentItem-..."
         # data-id="ContentItem-..."
-        'url': 'http://www.raisport.rai.it/dl/raiSport/media/rassegna-stampa-04a9f4bd-b563-40cf-82a6-aad3529cb4a9.html',
+        'url': 'https://www.raisport.rai.it/dl/raiSport/media/rassegna-stampa-04a9f4bd-b563-40cf-82a6-aad3529cb4a9.html',
         'info_dict': {
             'id': '04a9f4bd-b563-40cf-82a6-aad3529cb4a9',
             'ext': 'mp4',
@@ -416,21 +580,9 @@ class RaiIE(RaiBaseIE):
             'upload_date': '20140612',
         },
         'skip': 'This content is available only in Italy',
-    }, {
-        # with ContentItem in many metas
-        'url': 'http://www.rainews.it/dl/rainews/media/Weekend-al-cinema-da-Hollywood-arriva-il-thriller-di-Tate-Taylor-La-ragazza-del-treno-1632c009-c843-4836-bb65-80c33084a64b.html',
-        'info_dict': {
-            'id': '1632c009-c843-4836-bb65-80c33084a64b',
-            'ext': 'mp4',
-            'title': 'Weekend al cinema, da Hollywood arriva il thriller di Tate Taylor "La ragazza del treno"',
-            'description': 'I film in uscita questa settimana.',
-            'thumbnail': r're:^https?://.*\.png$',
-            'duration': 833,
-            'upload_date': '20161103',
-        }
     }, {
         # with ContentItem in og:url
-        'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-efb17665-691c-45d5-a60c-5301333cbb0c.html',
+        'url': 'https://www.rai.it/dl/RaiTV/programmi/media/ContentItem-efb17665-691c-45d5-a60c-5301333cbb0c.html',
         'md5': '06345bd97c932f19ffb129973d07a020',
         'info_dict': {
             'id': 'efb17665-691c-45d5-a60c-5301333cbb0c',
@@ -439,42 +591,17 @@ class RaiIE(RaiBaseIE):
             'description': 'TG1 edizione integrale ore 20:00 del giorno 03/11/2016',
             'thumbnail': r're:^https?://.*\.jpg$',
             'duration': 2214,
-            'upload_date': '20161103',
+            'upload_date': '20161103'
         }
-    }, {
-        # initEdizione('ContentItem-...'
-        'url': 'http://www.tg1.rai.it/dl/tg1/2010/edizioni/ContentSet-9b6e0cba-4bef-4aef-8cf0-9f7f665b7dfb-tg1.html?item=undefined',
-        'info_dict': {
-            'id': 'c2187016-8484-4e3a-8ac8-35e475b07303',
-            'ext': 'mp4',
-            'title': r're:TG1 ore \d{2}:\d{2} del \d{2}/\d{2}/\d{4}',
-            'duration': 2274,
-            'upload_date': '20170401',
-        },
-        'skip': 'Changes daily',
-    }, {
-        # HLS live stream with ContentItem in og:url
-        'url': 'http://www.rainews.it/dl/rainews/live/ContentItem-3156f2f2-dc70-4953-8e2f-70d7489d4ce9.html',
-        'info_dict': {
-            'id': '3156f2f2-dc70-4953-8e2f-70d7489d4ce9',
-            'ext': 'mp4',
-            'title': 'La diretta di Rainews24',
-        },
-        'params': {
-            'skip_download': True,
-        },
     }, {
         # Direct MMS URL
         'url': 'http://www.rai.it/dl/RaiTV/programmi/media/ContentItem-b63a4089-ac28-48cf-bca5-9f5b5bc46df5.html',
         'only_matching': True,
-    }, {
-        'url': 'https://www.rainews.it/tgr/marche/notiziari/video/2019/02/ContentItem-6ba945a2-889c-4a80-bdeb-8489c70a8db9.html',
-        'only_matching': True,
     }]
 
     def _extract_from_content_id(self, content_id, url):
         media = self._download_json(
-            'http://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-%s.html?json' % content_id,
+            f'https://www.rai.tv/dl/RaiTV/programmi/media/ContentItem-{content_id}.html?json',
             content_id, 'Downloading video JSON')
 
         title = media['name'].strip()
@@ -493,8 +620,6 @@ def _extract_from_content_id(self, content_id, url):
         else:
             raise ExtractorError('not a media file')
 
-        self._sort_formats(relinker_info['formats'])
-
         thumbnails = []
         for image_type in ('image', 'image_medium', 'image_300'):
             thumbnail_url = media.get(image_type)
@@ -505,21 +630,18 @@ def _extract_from_content_id(self, content_id, url):
 
         subtitles = self._extract_subtitles(url, media)
 
-        info = {
+        return {
             'id': content_id,
             'title': title,
-            'description': strip_or_none(media.get('desc')),
+            'description': strip_or_none(media.get('desc') or None),
             'thumbnails': thumbnails,
-            'uploader': media.get('author'),
+            'uploader': strip_or_none(media.get('author') or None),
             'upload_date': unified_strdate(media.get('date')),
             'duration': parse_duration(media.get('length')),
             'subtitles': subtitles,
+            **relinker_info
         }
 
-        info.update(relinker_info)
-
-        return info
-
     def _real_extract(self, url):
         video_id = self._match_id(url)
 
@@ -532,20 +654,20 @@ def _real_extract(self, url):
              'twitter:player', 'jsonlink'), webpage, default=None)
         if content_item_url:
             content_item_id = self._search_regex(
-                r'ContentItem-(%s)' % self._UUID_RE, content_item_url,
+                rf'ContentItem-({self._UUID_RE})', content_item_url,
                 'content item id', default=None)
 
         if not content_item_id:
             content_item_id = self._search_regex(
-                r'''(?x)
+                rf'''(?x)
                     (?:
                         (?:initEdizione|drawMediaRaiTV)\(|
                         <(?:[^>]+\bdata-id|var\s+uniquename)=|
                         <iframe[^>]+\bsrc=
                     )
                     (["\'])
-                    (?:(?!\1).)*\bContentItem-(?P<id>%s)
-                ''' % self._UUID_RE,
+                    (?:(?!\1).)*\bContentItem-(?P<id>{self._UUID_RE})
+                ''',
                 webpage, 'content item id', default=None, group='id')
 
         content_item_ids = set()
@@ -578,99 +700,121 @@ def _real_extract(self, url):
 
         relinker_info = self._extract_relinker_info(
             urljoin(url, relinker_url), video_id)
-        self._sort_formats(relinker_info['formats'])
 
         title = self._search_regex(
             r'var\s+videoTitolo\s*=\s*([\'"])(?P<title>[^\'"]+)\1',
             webpage, 'title', group='title',
             default=None) or self._og_search_title(webpage)
 
-        info = {
+        return {
             'id': video_id,
             'title': title,
+            **relinker_info
         }
 
-        info.update(relinker_info)
 
-        return info
+class RaiNewsIE(RaiIE):  # XXX: Do not subclass from concrete IE
+    _VALID_URL = rf'https?://(www\.)?rainews\.it/(?!articoli)[^?#]+-(?P<id>{RaiBaseIE._UUID_RE})(?:-[^/?#]+)?\.html'
+    _EMBED_REGEX = [rf'<iframe[^>]+data-src="(?P<url>/iframe/[^?#]+?{RaiBaseIE._UUID_RE}\.html)']
+    _TESTS = [{
+        # new rainews player (#3911)
+        'url': 'https://www.rainews.it/rubriche/24mm/video/2022/05/24mm-del-29052022-12cf645d-1ffd-4220-b27c-07c226dbdecf.html',
+        'info_dict': {
+            'id': '12cf645d-1ffd-4220-b27c-07c226dbdecf',
+            'ext': 'mp4',
+            'title': 'Puntata del 29/05/2022',
+            'duration': 1589,
+            'upload_date': '20220529',
+            'uploader': 'rainews',
+        }
+    }, {
+        # old content with fallback method to extract media urls
+        'url': 'https://www.rainews.it/dl/rainews/media/Weekend-al-cinema-da-Hollywood-arriva-il-thriller-di-Tate-Taylor-La-ragazza-del-treno-1632c009-c843-4836-bb65-80c33084a64b.html',
+        'info_dict': {
+            'id': '1632c009-c843-4836-bb65-80c33084a64b',
+            'ext': 'mp4',
+            'title': 'Weekend al cinema, da Hollywood arriva il thriller di Tate Taylor "La ragazza del treno"',
+            'description': 'I film in uscita questa settimana.',
+            'thumbnail': r're:^https?://.*\.png$',
+            'duration': 833,
+            'upload_date': '20161103'
+        },
+        'expected_warnings': ['unable to extract player_data'],
+    }, {
+        # iframe + drm
+        'url': 'https://www.rainews.it/iframe/video/2022/07/euro2022-europei-calcio-femminile-italia-belgio-gol-0-1-video-4de06a69-de75-4e32-a657-02f0885f8118.html',
+        'only_matching': True,
+    }]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
 
+        webpage = self._download_webpage(url, video_id)
 
-class RaiPlayRadioBaseIE(InfoExtractor):
-    _BASE = 'https://www.raiplayradio.it'
+        player_data = self._search_json(
+            r'<rainews-player\s*data=\'', webpage, 'player_data', video_id,
+            transform_source=clean_html, fatal=False)
+        track_info = player_data.get('track_info')
+        relinker_url = traverse_obj(player_data, 'mediapolis', 'content_url')
 
-    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
+        if not relinker_url:
+            # fallback on old implementation for some old content
+            try:
+                return self._extract_from_content_id(video_id, url)
+            except GeoRestrictedError:
+                raise
+            except ExtractorError as e:
+                raise ExtractorError('Relinker URL not found', cause=e)
 
+        relinker_info = self._extract_relinker_info(urljoin(url, relinker_url), video_id)
 
-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',
+        return {
+            'id': video_id,
+            'title': track_info.get('title') or self._og_search_title(webpage),
+            'upload_date': unified_strdate(track_info.get('date')),
+            'uploader': strip_or_none(track_info.get('editor') or None),
+            **relinker_info
         }
-    }
-
-    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',
+class RaiSudtirolIE(RaiBaseIE):
+    _VALID_URL = r'https?://raisudtirol\.rai\.it/.+?media=(?P<id>[TP]tv\d+)'
+    _TESTS = [{
+        'url': 'https://raisudtirol.rai.it/la/index.php?media=Ptv1619729460',
         '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,
-    }
+            'id': 'Ptv1619729460',
+            'ext': 'mp4',
+            'title': 'Euro: trasmisciun d\'economia - 29-04-2021 20:51',
+            'series': 'Euro: trasmisciun d\'economia',
+            'upload_date': '20210429',
+            'thumbnail': r're:https://raisudtirol\.rai\.it/img/.+?\.jpg',
+            'uploader': 'raisudtirol',
+        }
+    }]
 
     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
-            })
+        video_id = self._match_id(url)
+        webpage = self._download_webpage(url, video_id)
 
-        return self.playlist_result(
-            entries, playlist_id, playlist_title, playlist_description,
-            creator=playlist_creator)
+        video_date = self._html_search_regex(r'<span class="med_data">(.+?)</span>', webpage, 'video_date', fatal=False)
+        video_title = self._html_search_regex(r'<span class="med_title">(.+?)</span>', webpage, 'video_title', fatal=False)
+        video_url = self._html_search_regex(r'sources:\s*\[\{file:\s*"(.+?)"\}\]', webpage, 'video_url')
+        video_thumb = self._html_search_regex(r'image: \'(.+?)\'', webpage, 'video_thumb', fatal=False)
+
+        return {
+            'id': video_id,
+            'title': join_nonempty(video_title, video_date, delim=' - '),
+            'series': video_title,
+            'upload_date': unified_strdate(video_date),
+            'thumbnail': urljoin('https://raisudtirol.rai.it/', video_thumb),
+            'uploader': 'raisudtirol',
+            'formats': [{
+                'format_id': 'https-mp4',
+                'url': self._proto_relative_url(video_url),
+                'width': 1024,
+                'height': 576,
+                'fps': 25,
+                'vcodec': 'h264',
+                'acodec': 'aac',
+            }],
+        }