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

Code before:
            'timestamp': 1284661800,
            'series': 'Ühikarotid',
            'series_id': '17',
            'season': 'Season 2',
            'season_number': 2,
            'episode': 'Episode 14',
            'episode_number': 14,
        },
    }]

    def _real_extract(self, url):
        telecast_id, episode = self._match_valid_url(url).groups()
        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 {}

        return {
            'id': video_id,
            'formats': self._extract_m3u8_formats(video_player['manifest-url'], video_id, 'mp4'),
            **traverse_obj(episode_attr, {
                'title': (None, ('subtitle', ('episode_id', {lambda x: f'Episode {x}'}))),
                'description': 'synopsis',
                'thumbnail': ('images', 'original'),
                'timestamp': ('airtime', {lambda x: unified_timestamp(x + ' +0200')}),
                'series': 'title',
                'series_id': ('telecast_id', {str_or_none}),
                'season_number': ('season_id', {int_or_none}),
                'episode': 'subtitle',
                'episode_number': (None, ('episode_nr', 'episode_id'), {int_or_none}),
            }, get_all=False),
        }


Review comment (bug):
This now brings up the problem of the title. This is the best I came up with, tell me if you think this makes sense:
For movies, always use the title. For shows/series, first try the subtitle, then try to name it after the episode number and if all else fails also use the title.
```suggestion
            'title': episode_attr.get('title') if episode_attr.get('category') == 'movies' else (
                traverse_obj(episode_attr, 'subtitle', ('episode_nr', {lambda x: f'Episode {x}' if x else None}), 'title')),
            'formats': self._extract_m3u8_formats(video_player['manifest-url'], video_id, 'mp4'),
            **traverse_obj(episode_attr, {
```
This means the tests will need to be updated. But I think it would be unexpected to have for example `https://duoplay.ee/17/uhikarotid?ep=14` be named `Episode 14` even though it is the 2nd episode of the 2nd season.

Code after:
            '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,
        },
    }]

    def _real_extract(self, url):
        telecast_id, episode = self._match_valid_url(url).group('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'):
            raise ExtractorError('No video found', expected=True)