a
    h                     @   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 TreesZ742779548009z5https://www.monstercat.com/release/742779548009/coverZ20230711ZBT)titleid	thumbnailrelease_datealbumalbum_artists)urlZplaylist_countZ	info_dictc           	   
   c   s   t d|D ]}t|tddhdd hdthf}t|tddd	hthfpNi }|d
}|d}t|tddhthf}|r|s| 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   s
   |  dS )Nz <span	partitionx r   P/mnt/pikpak/tmp/myenv/lib/python3.9/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/Zmp3)r   tracktrack_numberZartistsr   r   ext)refindallr   r
   r   r   getr   Zreport_warningZwrite_debugall)	selftable
album_metatdr   idsZtrack_idZ
release_idr!   r   r   r   _extract_tracks   s8    


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   s
   |  dS )Nz	Released r   r   r   r   r   r   F   r   z,MonstercatIE._real_extract.<locals>.<lambda>r   )r   r   r   r   r   Zplaylist_id)
Z	_match_idZ_download_webpager   r
   r   r&   r   r	   Zplaylist_resultr,   )r'   r   Zurl_idr   Ztracklist_tabler   r)   r   r   r   _real_extract7   s,    



zMonstercatIE._real_extractN)__name__
__module____qualname__Z
_VALID_URLZ_TESTSr,   r0   r   r   r   r   r      s   r   )r#   commonr   utilsr   r   r   r   r	   Zutils.traversalr
   r   r   r   r   r   r   <module>   s   