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

Code before:
            'composers': ['Edward Elgar'],
            'artists': ['Vasily Petrenko', 'Royal Liverpool Philharmonic Orchestra'],
            'genres': ['Orchestral', 'Other Orchestral Music'],
            'timestamp': 1554474370,
            'modified_timestamp': 1554474370,
            'modified_date': '20190405',
            'upload_date': '20190405',
        },
        'playlist_count': 15,
    }]

    def _real_extract(self, url):
        recording_id: str = self._match_id(url)
        recording_info: dict = self._download_json(f'https://api.idagio.com/v2.0/metadata/recordings/{recording_id}',
                                                   recording_id).get('result')

        track_ids: list[int] = traverse_obj(recording_info, ('tracks', ..., 'id'))

        return {
            '_type': 'multi_video',
            'ext': 'mp3',
            'id': recording_id,
            'entries': [self.url_result(f'https://app.idagio.com/recordings/{recording_id}?trackId={track_id}',
                                        ie='IdagioTrack', video_id=track_id, track_number=i)
                        for i, track_id in enumerate(track_ids, start=1)],
            **traverse_obj(recording_info, {
                'title': ('work', 'title', {str}),
                'timestamp': ('created_at', {int_or_none(scale=1000)}),
                'modified_timestamp': ('created_at', {int_or_none(scale=1000)}),
                'location': ('location', {str}),
                'artists': (('conductor', ('ensembles', ...), ('soloists', ...)), 'name', {str}, all),
                'composers': ('work', 'composer', 'name', {str}, all),
                'genres': ('work', ('genre', 'subgenre'), 'title', {str}, all),
                'tags': ('tags', ..., {str}),
            }),
        }


class IdagioAlbumIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?app\.idagio\.com/albums/(?P<id>[a-zA-Z0-9\-]+)'
    _TESTS = [{
        'url': 'https://app.idagio.com/albums/elgar-enigma-variations-in-the-south-serenade-for-strings',
        'info_dict': {
            'id': 'a9f139b8-f70d-4b8a-a9a4-5fe8d35eaf9c',
            'display_id': 'elgar-enigma-variations-in-the-south-serenade-for-strings',
            'title': 'Elgar: Enigma Variations, In the South, Serenade for Strings',
            'description': '',
            'thumbnail': 'https://idagio-images.global.ssl.fastly.net/albums/880040420521/main.jpg',
            'artists': ['Vasily Petrenko', 'Royal Liverpool Philharmonic Orchestra', 'Edward Elgar'],
            'timestamp': 1553817600,
            'upload_date': '20190329',

Review comment (refactor):
If we just enumerate, I would leave this info out and instead rely on `playlist_index`. With that, we could simplify to:
```suggestion
            **traverse_obj(recording_info, {
                'entries': ('tracks', ..., 'id', {int}, {construct_track_url}),
```

Code after:
    _PLAYLIST_ID_KEY = 'id'  # vs. 'display_id'

    def _entries(self, playlist_info):
        for track_data in traverse_obj(playlist_info, ('tracks', lambda _, v: v['id'] and v['recording']['id'])):
            track_id = track_data['id']
            recording_id = track_data['recording']['id']
            yield self.url_result(
                f'https://app.idagio.com/recordings/{recording_id}?trackId={track_id}',
                ie=IdagioTrackIE, video_id=track_id)

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        playlist_info = self._download_json(
            self._API_URL_TMPL.format(playlist_id), playlist_id)['result']

        return {
            '_type': 'playlist',
            self._PLAYLIST_ID_KEY: playlist_id,
            'entries': self._entries(playlist_info),
            **self._parse_playlist_metadata(playlist_info),
        }


class IdagioRecordingIE(IdagioPlaylistBaseIE):
    _VALID_URL = r'https?://(?:www\.)?app\.idagio\.com/recordings/(?P<id>\d+)(?![^#]*[&?]trackId=\d+)'
    _TESTS = [{
        'url': 'https://app.idagio.com/recordings/30576934',
        'info_dict': {
            'id': '30576934',
            'title': 'Variations on an Original Theme op. 36',
            'composers': ['Edward Elgar'],
            'artists': ['Vasily Petrenko', 'Royal Liverpool Philharmonic Orchestra'],
            'genres': ['Orchestral', 'Other Orchestral Music'],
            'timestamp': 1554474370,
            'modified_timestamp': 1554474370,
            'modified_date': '20190405',
            'upload_date': '20190405',
        },
        'playlist_count': 15,
    }]
    _API_URL_TMPL = 'https://api.idagio.com/v2.0/metadata/recordings/{}'

    def _parse_playlist_metadata(self, playlist_info):
        return traverse_obj(playlist_info, {
            'title': ('work', 'title', {str}),
            'timestamp': ('created_at', {int_or_none(scale=1000)}),
            'modified_timestamp': ('created_at', {int_or_none(scale=1000)}),
            'location': ('location', {str}),
            'artists': (('conductor', ('ensembles', ...), ('soloists', ...)), 'name', {str}),
            'composers': ('work', 'composer', 'name', {str}, all),
            'genres': ('work', ('genre', 'subgenre'), 'title', {str}),