Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/matchitv.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import unified_strdate


class MatchiTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?matchi\.tv/watch\?s=(?P<id>[A-Za-z0-9_-]+)'
    _TESTS = [{
        'url': 'https://matchi.tv/watch?s=pNOyrdC8Bmu',
        'info_dict': {
            'id': 'pNOyrdC8Bmu',
            'ext': 'mp4',
            'title': str,
            'thumbnail': 'https://thumbnails.padelgo.tv/pNOyrdC8Bmu.jpg',
            'upload_date': str,
        },
        'params': {
            'skip_download': True,
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)

        # The stream ID can be generated without needing any further information,
        # however it does not contain any of the video metadata such as title and date.
        m3u8_url = f'https://streams.padelgo.tv/v2/streams/m3u8/{video_id}/anonymous/playlist.m3u8'
        thumbnail = f'https://thumbnails.padelgo.tv/{video_id}.jpg'

        # There is JSON metadata embedded in the webpage that is used for
        # rendering later. Rather than extracting the JSON object and parsing
        # we can just do a simple regex on the webpage to get the key attributes.
        webpage = self._download_webpage(url, video_id)

        court_description = self._search_regex(
            r'"courtDescription"\s*:\s*"([^"]+)"',
            webpage, 'court description')
        start_date_time = self._search_regex(
            r'"startDateTime"\s*:\s*"([^"]+)"',
            webpage, 'start date time')

        title = f'{court_description} {start_date_time}'

        # Parse upload_date from startDateTime (format: YYYYMMDD)
        upload_date = unified_strdate(start_date_time)

        formats = self._extract_m3u8_formats(
            m3u8_url, video_id, 'mp4',
            entry_protocol='m3u8_native',
            m3u8_id='hls', fatal=False)

        return {

Review comment (refactor):
This is fine to do, but the comment is unnecessary and you can/should inline the f-string in the `_extract_m3u8_formats` call

Code after:
from .common import InfoExtractor
from ..utils import join_nonempty, unified_strdate
from ..utils.traversal import traverse_obj


class MatchiTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?matchi\.tv/watch/?\?(?:[^#]+&)?s=(?P<id>[0-9a-zA-Z]+)'
    _TESTS = [{
        'url': 'https://matchi.tv/watch?s=0euhjzrxsjm',
        'info_dict': {
            'id': '0euhjzrxsjm',
            'ext': 'mp4',
            'title': 'Court 2 at Stratford Padel Club 2024-07-13T18:32:24',
            'thumbnail': 'https://thumbnails.padelgo.tv/0euhjzrxsjm.jpg',
            'upload_date': '20240713',
        },
    }, {
        'url': 'https://matchi.tv/watch?s=FkKDJ9SvAx1',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        loaded_media = traverse_obj(
            self._search_nextjs_data(webpage, video_id, fatal=False),
            ('props', 'pageProps', 'loadedMedia', {dict})) or {}
        start_date_time = traverse_obj(loaded_media, ('startDateTime', {str}))

        return {
            'id': video_id,
            'title': join_nonempty(loaded_media.get('courtDescription'), start_date_time, delim=' '),
            'thumbnail': f'https://thumbnails.padelgo.tv/{video_id}.jpg',
            'upload_date': unified_strdate(start_date_time),
            'formats': self._extract_m3u8_formats(
                f'https://streams.padelgo.tv/v2/streams/m3u8/{video_id}/anonymous/playlist.m3u8',
                video_id, 'mp4', m3u8_id='hls'),
        }