o
    i                     @   sT   d dl Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZ G dd deZdS )	    N   )InfoExtractor   )
clean_htmlextract_attributesint_or_nonestrip_or_noneunified_strdate)find_elementtraverse_objc                	   @   s>   e Zd ZdZddddddddgd	d
gZdd Zdd ZdS )MonstercatIEz1https?://www\.monstercat\.com/release/(?P<id>\d+)z/https://www.monstercat.com/release/742779548009   zThe Secret Language of Trees742779548009z5https://www.monstercat.com/release/742779548009/cover20230711BT)titleid	thumbnailrelease_datealbumalbum_artists)urlplaylist_count	info_dictc           	   
   c   s    t d|D ]q}t|tddhdd hdthf}t|tddd	hthfp(i }|d
}|d}t|tddhthf}|rC|sX| d| d | 	d|d| qi ||||t|tddhtht
fd| d| |ddV  qd S )Nz<tr[^<]*>((?:(?!</tr>)[\w\W])+)zd-inline-flex flex-columnclsc                 S   
   |  dS )Nz <span	partitionx r!   O/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/monstercat.py<lambda>!      
 z.MonstercatIE._extract_tracks.<locals>.<lambda>r   z btn-play cursor-pointer mr-smallT)r   htmlzdata-track-idzdata-release-idz	py-xsmallzSkipping track z, ID(s) not foundzrelease_id=z
 track_id=zd-block fs-xxsmallz'https://www.monstercat.com/api/release/z/track-stream/mp3)r   tracktrack_numberartistsr   r   ext)refindallr   r
   r   r   getr   report_warningwrite_debugall)	selftable
album_metatdr   idstrack_id
release_idr(   r!   r!   r"   _extract_tracks   s<   


zMonstercatIE._extract_tracksc                 C   s   |  |}| ||}t|tddhpd}t|tddhthf}||d| dt|tddhthtft|td	dhd
d hdththfd}| j| 	||fd|i|S )Nztable table-smallr    h1)tagz#https://www.monstercat.com/release/z/coverz5h-normal text-uppercase mb-desktop-medium mb-smallishz1font-italic mb-medium d-tablet-none d-phone-blockc                 S   r   )Nz	Released r   r   r!   r!   r"   r#   F   r$   z,MonstercatIE._real_extract.<locals>.<lambda>r   )r   r   r   r   r   playlist_id)
	_match_id_download_webpager   r
   r   r0   r   r	   playlist_resultr8   )r1   r   url_idr%   tracklist_tabler   r3   r!   r!   r"   _real_extract7   s,   



zMonstercatIE._real_extractN)__name__
__module____qualname__
_VALID_URL_TESTSr8   rB   r!   r!   r!   r"   r      s    r   )r+   commonr   utilsr   r   r   r   r	   utils.traversalr
   r   r   r!   r!   r!   r"   <module>   s
    