o
    i-                     @   s   d dl mZ ddlmZmZmZ ddlmZ G dd deZG dd deZ	G d	d
 d
e	Z
G dd de	ZG dd de	ZG dd de	ZdS )   )InfoExtractor   )int_or_noneunified_timestampurl_or_none)traverse_objc                   @   sr   e Zd ZdZdddddddgd	d
gddgdddd
ddddddddgddgdddd	ddddgZdd  Zd!S )"IdagioTrackIEz`https?://(?:www\.)?app\.idagio\.com(?:/[a-z]{2})?/recordings/\d+\?(?:[^#]+&)?trackId=(?P<id>\d+)z;https://app.idagio.com/recordings/30576934?trackId=30576943 15148bd71804b2450a2508931a116b5630576943mp3zTheme. AndanteR   Edward ElgarVasily Petrenko&Royal Liverpool Philharmonic Orchestra
OrchestralOther Orchestral Musice\20190405)
idexttitleduration	composersartistsgenrestrack	timestampupload_date)urlmd5	info_dictzJhttps://app.idagio.com/recordings/20514467?trackId=20514478&utm_source=pcl 3acef2ea0feadf889123b70e5a1e7fa720514478zI. Adagio sostenutoi<  Ludwig van BeethovenKeyboardSonata (Keyboard)|Z20180208)	r   r   r   r   r   r   r   r   r   zMhttps://app.idagio.com/de/recordings/20514467?trackId=20514478&utm_source=pclTr   only_matchingc                 C   s   |  |}| jd| |ddd}t|ddkr|   | jd| |dd	d
dd}dd|t|dthfdt|dddthfddtddhfddthfdthfddthfdddthtfdddddthtttf	dddddthtfd fS )!Nz,https://api.idagio.com/v2.0/metadata/tracks/Fi  )fatalexpected_status
error_codezidagio.error.blocked.locationz*https://api.idagio.com/v1.8/content/track/02zweb-4)qualityformatclient_type)queryr   noner   )r   vcodecr   r   resultpiecer   	recording
created_at  scalelocationr   	conductor)	ensembles.)soloists.nameworkpartworkcomposergenresubgenre)r   r   r<   r   r   r   r   r   )		_match_id_download_jsonr   raise_geo_restrictedr   strr   filterall)selfr   track_id
track_infocontent_info rR   K/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/idagio.py_real_extract*   s<   

	


zIdagioTrackIE._real_extractN)__name__
__module____qualname__
_VALID_URL_TESTSrT   rR   rR   rR   rS   r      sD    "r   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )IdagioPlaylistBaseIEzESubclasses must set _API_URL_TMPL and define _parse_playlist_metadatar   c                 c   sP    t |ddd fD ]}|d }|d d }| jd| d| t|dV  q
d S )	Ntracksc                 S   s   |d o	|d d S )Nr   r7   rR   )_vrR   rR   rS   <lambda>Q   s    z/IdagioPlaylistBaseIE._entries.<locals>.<lambda>r   r7   z"https://app.idagio.com/recordings/z	?trackId=)ievideo_id)r   
url_resultr   )rN   playlist_info
track_datarO   recording_idrR   rR   rS   _entriesP   s   
zIdagioPlaylistBaseIE._entriesc                 C   sD   |  |}| | j||d }dd| j|d| |i| |S )Nr5   _typeplaylistentries)rH   rI   _API_URL_TMPLr0   _PLAYLIST_ID_KEYre   _parse_playlist_metadata)rN   r   playlist_idrb   rR   rR   rS   rT   X   s   

z"IdagioPlaylistBaseIE._real_extractN)rU   rV   rW   __doc__rj   re   rT   rR   rR   rR   rS   rZ   L   s
    rZ   c                   @   sj   e Zd ZdZddddgddgdd	gd
d
ddd	ddddddgddgdddddddgZdZdd ZdS )IdagioRecordingIEz`https?://(?:www\.)?app\.idagio\.com(?:/[a-z]{2})?/recordings/(?P<id>\d+)(?![^#]*[&?]trackId=\d+)z*https://app.idagio.com/recordings/3057693430576934z&Variations on an Original Theme op. 36r   r   r   r   r   r   r   )	r   r   r   r   r   r   modified_timestampmodified_dater      r   r    playlist_countz-https://app.idagio.com/de/recordings/2051446720514467z1Sonata for Piano No. 14 in C sharp minor op. 27/2r#   r$   r%   r&   r'   )r   r   r   r   r   r   rp   rq      z2https://api.idagio.com/v2.0/metadata/recordings/{}c                 C   sh   t |ddthfdtddhfdtddhfdthfddthfdd	dthtfdd
dthfddthfdS )NrC   r   r8   r9   r:   r<   r=   rA   rD   rE   tags.)r   r   rp   r<   r   r   r   rw   )r   rK   r   rM   rN   rb   rR   rR   rS   rk      s   


z*IdagioRecordingIE._parse_playlist_metadataNrU   rV   rW   rX   rY   ri   rk   rR   rR   rR   rS   rn   e   s<    
rn   c                   @   sr   e Zd ZdZddddddg dd	d
ddd
ddddddddg dddddddgdddgZdZd Zd!d" Zd#S )$IdagioAlbumIEzGhttps?://(?:www\.)?app\.idagio\.com(?:/[a-z]{2})?/albums/(?P<id>[\w-]+)zWhttps://app.idagio.com/albums/elgar-enigma-variations-in-the-south-serenade-for-stringsz$a9f139b8-f70d-4b8a-a9a4-5fe8d35eaf9cz9elgar-enigma-variations-in-the-south-serenade-for-stringsz<Elgar: Enigma Variations, In the South, Serenade for Strings z+re:https://.+/albums/880040420521/main\.jpg)r   r   r   i `\20190329g  HA20190708)
r   
display_idr   description	thumbnailr   r   r   rp   rq      rs   zbhttps://app.idagio.com/de/albums/brahms-ein-deutsches-requiem-3B403DF6-62D7-4A42-807B-47173F3E0192z$2862ad4e-4a61-45ad-9ce4-7fcf0c2626fezAbrahms-ein-deutsches-requiem-3B403DF6-62D7-4A42-807B-47173F3E0192zBrahms: Ein deutsches RequiemzEGRAMOPHONE CLASSICAL MUSIC AWARDS 2025 Recording of the Year & Choralz,re:https://.+/albums/3149020954522/main\.jpg)zSabine Devieilheu   Stéphane Degoutu   Raphaël Pichon	PygmalionzJohannes BrahmsiLh20251010i h20251016recommendedzrecent-release)r   r~   r   r   r   r   r   r   rp   rq   rw      z.https://api.idagio.com/v2.0/metadata/albums/{}r~   c                 C   sR   t |dthfdthfdthfdthfdthfdthfddd	thfd
dthfdS )Nr   r   publishDatelastModifiedimageUrlr   participants.rA   rw   )r   r   r   rp   r   r   r   rw   )r   rK   r   r   rx   rR   rR   rS   rk      s   
z&IdagioAlbumIE._parse_playlist_metadataNrU   rV   rW   rX   rY   ri   rj   rk   rR   rR   rR   rS   rz      sF     rz   c                	   @   sX   e Zd ZdZdddddddgd	d
ddddddddgd	ddgZdZdZdd ZdS )IdagioPlaylistIEzWhttps?://(?:www\.)?app\.idagio\.com(?:/[a-z]{2})?/playlists/(?!personal/)(?P<id>[\w-]+)zIhttps://app.idagio.com/playlists/beethoven-the-most-beautiful-piano-musicz$31652bec-8c5b-460e-a3f0-cf1f69817f53z(beethoven-the-most-beautiful-piano-musicz)Beethoven: the most beautiful piano musicz$md5:d41bb04b8896bb69377f5c2cd9345ad1zFre:https://.+/playlists/31652bec-8c5b-460e-a3f0-cf1f69817f53/main\.jpgIDAGIO)r   r~   r   r   r   creators   )r   r    playlist_mincountzAhttps://app.idagio.com/de/playlists/piano-music-for-an-autumn-dayz$d70e9c7f-7080-4308-ae0f-f890dddeda82zpiano-music-for-an-autumn-dayzPiano Music for an Autumn DayzZGet ready to snuggle up and enjoy all the musical colours of this cosy, autumnal playlist.zFre:https://.+/playlists/d70e9c7f-7080-4308-ae0f-f890dddeda82/main\.jpg#   rs   z(https://api.idagio.com/v2.0/playlists/{}r~   c              
   C   s8   t |dthfdthfdthfdthfddthtfdS )Nr   r   r   r   curatorrA   )r   r   r   r   r   )r   rK   r   rM   rx   rR   rR   rS   rk      s   z)IdagioPlaylistIE._parse_playlist_metadataNr   rR   rR   rR   rS   r      s4    r   c                
   @   sF   e Zd ZdZddddgdddd	d
ddddddgZdZdd ZdS )IdagioPersonalPlaylistIEzVhttps?://(?:www\.)?app\.idagio\.com(?:/[a-z]{2})?/playlists/personal/(?P<id>[\da-f-]+)zNhttps://app.idagio.com/playlists/personal/99dad72e-7b3a-45a4-b216-867c08046ed8z$99dad72e-7b3a-45a4-b216-867c08046ed8Testz$1a6f16a6-4514-4d0c-b481-3a9877835626z%re:https://.+/artists/86371/main\.jpgi_ih2020101620250819)r   r   r   r   r   rp   r   rq   d   rs   zQhttps://app.idagio.com/de/playlists/personal/99dad72e-7b3a-45a4-b216-867c08046ed8Tr(   z1https://api.idagio.com/v1.0/personal-playlists/{}c              
   C   sB   t |dthfdthfdthtfdtddhfdtddhfdS )	Nr   	image_urluser_idr8   r9   r:   
updated_at)r   r   r   r   rp   )r   rK   r   rM   r   rx   rR   rR   rS   rk      s   
z1IdagioPersonalPlaylistIE._parse_playlist_metadataNry   rR   rR   rR   rS   r      s(    
r   N)commonr   utilsr   r   r   utils.traversalr   r   rZ   rn   rz   r   r   rR   rR   rR   rS   <module>   s    F-2&