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

Code before:
        'md5': '6aca68be71112314738dd17cced7f8bf',
        'info_dict': {
            'id': '17',
            'ext': 'mp4',
            'title': 'Episode 14',
            'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
            'description': 'md5:4719b418e058c209def41d48b601276e',
            'upload_date': '20100916',
            'timestamp': 1284661800,
            'series': 'Ühikarotid',
            'series_id': 17,
            'season': 'Season 2',
            'season_number': 2,
            'episode_id': 14,
        },
    }]

    def _real_extract(self, url):
        def decode_quot(s: str):
            return s.replace("&quot;", '"')

        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        manifest_url = self._search_regex(r'<video-player[^>]+manifest-url="([^"]+)"', webpage, 'video-player')
        episode_attr = self._search_regex(r'<video-player[^>]+:episode="([^"]+)"', webpage, 'episode data')
        ep = self._parse_json(episode_attr, video_id, decode_quot)

        return {
            'id': video_id,
            # fallback to absolute "episode_id" value
            'title': traverse_obj(ep, 'subtitle') or f"Episode {traverse_obj(ep, 'episode_id')}",
            'description': strip_or_none(traverse_obj(ep, 'synopsis')),
            'thumbnail': traverse_obj(ep, ('images', 'original')),
            'formats': self._extract_m3u8_formats(manifest_url, video_id, 'mp4'),
            'timestamp': unified_timestamp(traverse_obj(ep, 'airtime') + ' +0200'),
            'series': traverse_obj(ep, 'title'),
            'series_id': traverse_obj(ep, 'telecast_id'),
            'season_number': traverse_obj(ep, 'season_id'),
            'episode': traverse_obj(ep, 'subtitle'),
            # fallback to absolute "episode_id" value
            'episode_number': traverse_obj(ep, 'episode_nr') or traverse_obj(ep, 'episode_id'),
            'episode_id': traverse_obj(ep, 'episode_id'),
        }


Review comment (refactor):
We can use the `get_element_text_and_html_by_tag` and `extract_attributes` functions from `..utils` to more easily retrieve the data. The `episode_attr` extraction can also be non-fatal, since it only contains metadata.
```suggestion
        telecast_id, episode = self._match_valid_url(url).groups('id', 'ep')
        video_id = join_nonempty(telecast_id, episode, delim='_')
        webpage = self._download_webpage(url, video_id)
        video_player = try_call(lambda: extract_attributes(
            get_element_text_and_html_by_tag('video-player', webpage)[1]))
        if not video_player or not video_player.get('manifest-url'):
            self.raise_no_formats('No video found', expected=True)

        episode_attr = self._parse_json(video_player.get(':episode') or '', video_id, fatal=False) or {}
```
The manifest_url can be in-lined. I've also changed `video_id`, see the comment on `_VALID_URL`.

Code after:
            'episode_number': 12,
            'episode_id': 24,
        },
    }, {
        'note': 'Empty title',
        'url': 'https://duoplay.ee/17/uhikarotid?ep=14',
        'md5': '6aca68be71112314738dd17cced7f8bf',
        'info_dict': {
            'id': '17_14',
            'ext': 'mp4',
            'title': 'Ühikarotid',
            'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
            'description': 'md5:4719b418e058c209def41d48b601276e',
            'upload_date': '20100916',
            'timestamp': 1284661800,
            'series': 'Ühikarotid',
            'series_id': '17',
            'season': 'Season 2',
            'season_number': 2,
            'episode_id': 14,
            'release_year': 2010,
        },
    }, {
        'note': 'Movie',
        'url': 'https://duoplay.ee/4325/naljamangud',
        'md5': '2b0bcac4159a08b1844c2bfde06b1199',
        'info_dict': {
            'id': '4325',
            'ext': 'mp4',
            'title': 'Näljamängud',
            'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
            'description': 'md5:fb35f5eb2ff46cdb82e4d5fbe7b49a13',
            'cast': ['Jennifer Lawrence', 'Josh Hutcherson', 'Liam Hemsworth'],
            'upload_date': '20231109',
            'timestamp': 1699552800,
            'release_year': 2012,
        },
    }, {
        'note': 'Movie without expiry',
        'url': 'https://duoplay.ee/5501/pilvede-all.-neljas-ode',
        'md5': '7abf63d773a49ef7c39f2c127842b8fd',
        'info_dict': {
            'id': '5501',
            'ext': 'mp4',
            'title': 'Pilvede all. Neljas õde',
            'thumbnail': r're:https://.+\.jpg(?:\?c=\d+)?$',
            'description': 'md5:d86a70f8f31e82c369d4d4f4c79b1279',
            'cast': 'count:9',
            'upload_date': '20221214',
            'timestamp': 1671054000,
            'release_year': 2018,