o
    i K                     @   sx   d dl mZ ddlmZmZmZmZmZmZm	Z	m
Z
 ddlmZmZ G dd deZG dd deZG d	d
 d
eZdS )   )InfoExtractor   )ExtractorErrorfloat_or_noneformat_fieldint_or_noneparse_iso8601parse_qstruncate_stringurl_or_none)traverse_objvaluec                   @   s2   e Zd Zdd Zd
ddZd
ddZd
dd	ZdS )BandlabBaseIEc                 K   sB   | dd pi }| jd| d| |fdddddd|i|S )	Nheadersz!https://www.bandlab.com/api/v1.3//zapplication/jsonzhttps://www.bandlab.com/zBandLab-Webz10.1.124)acceptrefererzx-client-idzx-client-version)pop_download_json)selfendpointasset_idkwargsr    r   L/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/bandlab.py	_call_api   s   zBandlabBaseIE._call_apiNc                 C   s   ddt  t jdt|dt|htddhfttfdthtfdd	thfdd	thfd
dt	hfdddt	hfdthfdd	thfddthfdt
hfd
dthfddthfddthfddthfddd	thfdS )Nnonerevisionvcodec
media_typeextractor_key	extractoridz#https://www.bandlab.com/revision/%stemplate
revisionIdr#   songnamemixdownfilepictureurldescriptioncreatorusername	createdOndurationcountersplayslikescommentsgenres.)webpage_urlr#   titletrackr-   	thumbnailr.   uploaderuploader_id	timestampr2   
view_count
like_countcomment_countr7   )	BandlabIEie_keyIE_NAMEr   r   r   filteranystrr   r   r   r   )r   revision_datar-   r   r   r   _parse_revision   s0   









zBandlabBaseIE._parse_revisionc                 C   s   ddt  t jdt|dt|htddhfttfdthtfddd	t	hfdd
thfdd
thfdthfdddt	htfddt
hfddt
hfddt
hfdddthfdd
thfddthfdthfdS )Nr   r:   r   r#   https://www.bandlab.com/post/%sr$   r&   sampleaudioUrlr)   captionr,   originalr-   r3   r4   r5   r6   r2   r/   r0   r1   )r8   r#   r-   r9   r:   r.   r;   r?   r@   rA   r2   r<   r=   r>   )rB   rC   rD   r   r   r   rE   rF   rG   r   r   r   r   )r   
track_datar-   r   r   r   _parse_track6   s.   







zBandlabBaseIE._parse_trackc                 C   s   dt  t jdt|dthfdt|htddhfttfddt	hfddd	 ht
d
dhfdthfdddt	hfdddthfdddthfddthfddthfddthfddthfdS )Nvideo)r    r!   r"   r#   rJ   r$   r-   rM   c                 S      |  ddS )N
 replacexr   r   r   <lambda>Y       z,BandlabBaseIE._parse_video.<locals>.<lambda>H   )leftr,   r3   r4   r5   r6   r2   r/   r)   r0   )r#   r8   r-   r9   r.   r;   r?   r@   rA   r2   r<   r=   )rB   rC   rD   r   rG   r   r   rE   rF   r   r
   r   r   )r   
video_datar-   r   r   r   _parse_videoO   s(   




zBandlabBaseIE._parse_video)N)__name__
__module____qualname__r   rI   rQ   r_   r   r   r   r   r      s
    

r   c                   @   s  e Zd ZddgZded  dgZddi dd	d
ddddddddddededdddddddddgdd d!ed"d#d$d%di dd	d
ddddddddd&dededdddddddddgdd d!ed"d#d$d'd(i dd)d
dd!edd*gdd+dd,dd-dd.dd/dedd0dedd1dd2dd.d"d#d$d3d4i dd5d
ddd6dd7dd8dd9dd:dd;ded!edd9dd<gdd=dedd>d"d#d$d?d@dAdBdCdDedEdFdGedEdHdId$dJdKi ddLd
dd!eddMgddNddOddPdeddQddRddSddTddUddQded"d#d$dVdWdXddYedZdYeed[d\d]d^d_dd`d$dadbdcgZddi dded
ddeddfddgddhddid!eddjgddkddldeddmddmddnd"d#dogZdpdq ZdrS )srB   zShttps?://(?:www\.)?bandlab.com/(?P<url_type>track|post|revision)/(?P<id>[\da-f_-]+)zThttps?://(?:www\.)?bandlab.com/(?P<url_type>embed)/\?(?:[^#]*&)?id=(?P<id>[\da-f-]+)<iframe[^>]+src=[\'"](?P<url>r   )[\'"]z_https://www.bandlab.com/track/04b37e88dba24967b9dac8eb8567ff39_07d7f906fc96ee11b75e000d3a428fff 46f7b43367dd268bbcf0bbe466753b2cr#   z$02d7f906-fc96-ee11-b75e-000d3a428fffextm4ar=   ender_milzer:   zsweet blackr.   zcomposed by juanjn3737r>   i;uer?   r@   r2   gp=
ףPK@r9   upload_date20231210r;   zUhttps://bl-prod-images.azureedge.net/v1.0/songs/fa082beb-b856-4730-9170-a57e4e32cc2c/r7   Lofir<   zender milzerA   r    r   )r-   md5	info_dictzAhttps://www.bandlab.com/post/07d7f906-fc96-ee11-b75e-000d3a428fffiEuezchttps://www.bandlab.com/track/048916c2-c6da-ee11-85f9-6045bd2e11f9?sharedKey=0NNWX8qYAEmI38lWAzCNDA 15174b57c44440e2a2008be9cae00250z$038916c2-c6da-ee11-85f9-6045bd2e11f9Otheruser8353034818103753zUhttps://bl-prod-images.azureedge.net/v1.0/songs/51b18363-da23-4b9b-a29c-2933a3e561ca/iePodcastMaerchen4bg
ףp=B}@u#   Podcast: Neues aus der Märchenwelt20240305zErna Wagenederzmhttps://www.bandlab.com/track/130343fc-148b-ea11-96d2-0003ffd1fc09?revId=110343fc-148b-ea11-96d2-0003ffd1fc09 74e055ef9325d63f37088772fbfe4454z$110343fc-148b-ea11-96d2-0003ffd1fc09i ^zUhttps://bl-prod-images.azureedge.net/v1.0/users/b612e533-e4f7-4542-9f50-3fcfd8dd822c/zFinal Revision.zReplay ( Instrumental)David R Sparksdavesnothome69Rock20200430g{Gvq@zAhttps://www.bandlab.com/post/5cdf9036-3857-ef11-991a-6045bd36e0d9 8caa2ef28e86c1dacf167293cfdbeba9z$5cdf9036-3857-ef11-991a-6045bd36e0d9mp4g
ףp=ZF@zVhttps://bl-prod-images.azureedge.net/v1.0/videos/67c6cef1-cef6-40d3-831e-a55bc1dcb972/zbacking vocals
marliashyaauraarR   )r#   rf   r2   r;   rA   r9   r=   r<   r@   r.   r    zQhttps://www.bandlab.com/embed/?blur=false&id=014de0a4-7d82-ea11-a94c-0003ffd19c0f a4ad05cb68c54faaed9b0a8453a8cf4az$014de0a4-7d82-ea11-a94c-0003ffd19c0f
ElectroniczCharlie Hensoni^20200419zPositronic Meltdowngs@zUhttps://bl-prod-images.azureedge.net/v1.0/songs/87165bc3-5439-496e-b1f7-a9f13b541ff2/z1Checkout my tracks at AOMX http://aomxsounds.com/microfreaksz_https://www.bandlab.com/track/55767ac51789ea11a94c0003ffd1fc09_2f007b0a37b94ec7a69bc25ae15108a5 f05d68a3769952c2d9257c473e14c15fA55767ac51789ea11a94c0003ffd1fc09_2f007b0a37b94ec7a69bc25ae15108a5insamegRU@SorakimesorakimezUhttps://bl-prod-images.azureedge.net/v1.0/users/572a351a-0f3a-4c6a-ac39-1a5defdeeb1c/id20230804)r#   rf   r:   r@   r2   r9   r?   rA   r<   r=   r;   r>   ri   r    zEhttps://www.bandlab.com/revision/014de0a4-7d82-ea11-a94c-0003ffd19c0fTr-   only_matchingzhttps://phantomluigi.github.io/z$e14223c3-7871-ef11-bdfd-000d3a980db320240913phantommusicofficialiѤfPhantomzProgresive Rockz$md5:a38cd668f7a2843295ef284114f18429g(\'l@zVermilion Pt. 2 (Cover)zThttps://bandlabimages.azureedge.net/v1.0/songs/62b10750-7aef-4f42-ad08-1af52f577e97/)r-   rm   c           	      C   s   |  |dd\}}t|}t|ddtf}|dkr|}d }|sf| jd|dt|dd	id
}t|dthtf}t|dthf}|sf|sf|d}|dkrT| j	||dS |dkr_| j
||dS td||ss| jd|dddid
}| j||dS )Nr#   url_type)revIdr#       r   postszDownloading post data	sharedKey)r   r   )notequery)r'   )r   r#   typeVideo)r-   Trackz%Could not extract data for post type 	revisionszDownloading revision dataeditfalse)_match_valid_urlgroupr	   r   rF   r   rG   dictgetr_   rQ   r   rI   )	r   r-   
display_idr   qsrevision_idrH   	post_data	post_typer   r   r   _real_extract  s2   
zBandlabIE._real_extractN)	r`   ra   rb   
_VALID_URL_EMBED_REGEXint_TESTS_WEBPAGE_TESTSr   r   r   r   r   rB   f   s   	
	
	
	
	
  	
rB   c                   @   s   e Zd ZddgZded  dgZdddd	d	ed
deedddddddddeddddedd	dddddded d!ed"ed#d d
d$d%dd&ed'ed(ed)d*d+d+d,d-d.d/d0dd1d2d3gZd4d5 Zd6d7 Zd8S )9BandlabPlaylistIEzXhttps?://(?:www\.)?bandlab.com/(?:[\w]+/)?(?P<type>albums|collections)/(?P<id>[\da-f-]+)z[https?://(?:www\.)?bandlab.com/(?P<type>embed)/collection/\?(?:[^#]*&)?id=(?P<id>[\da-f-]+)rc   r   rd   zRhttps://www.bandlab.com/davesnothome69/albums/89b79ea6-de42-ed11-b495-00224845aac7zVhttps://bl-prod-images.azureedge.net/v1.3/albums/69507ff3-579a-45be-afca-9e87eddec944/20221003RemnantsLPz*A collection of some feel good, rock hits.z$89b79ea6-de42-ed11-b495-00224845aac7rt   ru   )r;   release_dater9   albumr@   
album_typer.   rA   r?   r#   r<   r=   
   )r-   rm   playlist_countzShttps://www.bandlab.com/slytheband/collections/955102d4-1040-ef11-86c3-000d3a42581bz$955102d4-1040-ef11-86c3-000d3a42581bi#fu   My Shit 🖤
slythebandu   𝓢𝓛𝓨20240712zZhttps://bandlabimages.azureedge.net/v1.0/collections/2c64ca12-b180-4b76-8587-7a8da76bddc8/)	r#   r>   r?   r9   r=   r<   ri   r@   r;      zQhttps://www.bandlab.com/embed/collection/?id=12cc6f7f-951b-ee11-907c-00224844f303z$12cc6f7f-951b-ee11-907c-00224844f30320230706zEThis is a collection of songs I created when I had an Amiga computer.zMark Salud The Amiga Collectionmssirmooth1962zVhttps://bl-prod-images.azureedge.net/v1.3/albums/d618bd7b-0537-40d5-bdd8-61b066e77d59/z
Mark Salud)r#   r   r.   r?   r9   r=   rA   r;   r@   r<   r   r      zQhttps://www.bandlab.com/embed/collection/?id=e98aafb5-d932-ee11-b8f0-00224844c719r   r   z$md5:4ec31c568a5f5a5a2b17572ea64c382520230812ArtAlbumz$e98aafb5-d932-ee11-b8f0-00224844c719zVhttps://bl-prod-images.azureedge.net/v1.3/albums/20c890de-e94a-4422-828a-2da6377a13c8/)r@   r=   rA   r<   r?   r.   r   r9   r   r   r#   r;      zChttps://www.bandlab.com/albums/89b79ea6-de42-ed11-b495-00224845aac7Tr   c                 c   s    t |ddd fD ]3}|d }|dkr| |dV  q
|dkr)| |V  q
|dkr4| |V  q
| d	| d
 q
d S )Nr   c                 S   s   |d S )Nr   r   )_vr   r   r   rZ     s    z,BandlabPlaylistIE._entries.<locals>.<lambda>r   Revisionr   r   r   zSkipping unknown post type: "")r   rI   r   rQ   r_   report_warning)r   
album_datapostr   r   r   r   _entries  s   zBandlabPlaylistIE._entriesc                 C   s@  |  |dd\}}dgdgddgd|}|D ]}| j||d|d d  dd	d
d}|ds7|} nq|d }rGtd| d| j| ||fi t|dthfdthfddthfddthfdt	hfddd ht
fddthtfddthfddthfddthfd
|dkrt|dthfdthfdS i S )Nr#   r   albumscollections)r   r   embedzDownloading z dataFi  )r   fatalexpected_status	errorCodez+Could not find playlist data. Error code: "r   r)   r.   r/   r0   r1   releaseDatec                 S   rS   )N- rV   rX   r   r   r   rZ     r[   z1BandlabPlaylistIE._real_extract.<locals>.<lambda>r,   rN   r3   r5   r6   r4   )
r9   r.   r<   r=   r>   r   r;   r@   rA   r?   )r   r   )r   r   r   r   r   playlist_resultr   r   rG   r   rE   r   rF   r   )r   r-   playlist_idplaylist_type	endpointsr   playlist_data
error_coder   r   r   r     sT   






zBandlabPlaylistIE._real_extractN)	r`   ra   rb   r   r   r   r   r   r   r   r   r   r   r   8  s    Hr   N)commonr   utilsr   r   r   r   r   r	   r
   r   utils.traversalr   r   r   rB   r   r   r   r   r   <module>   s    (
W S