o
    ix                     @   s^  d dl Z d dlZd dlZd dlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZmZmZ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!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eZ'dS )"    N   )InfoExtractorSearchInfoExtractor   )HEADRequest)	HTTPError)ImpersonateTarget)ExtractorErrorfloat_or_noneint_or_nonejoin_nonemptymimetype2extparse_qsstr_or_nonetry_callunified_timestampupdate_url_queryurl_or_noneurlhandle_detect_ext)traverse_objc                   @   s   e Zd ZdZdgZdddgZdi ddd	d
ddddgddddddgdddedddddddddd d!dd"d#d$d%d&d'id(d)d*d+d+d,gd-d.d,d/d0d1d2gZd3d4 Zd5S )6SoundcloudEmbedIEzDhttps?://(?:w|player|p)\.soundcloud\.com/player/?.*?\burl=(?P<id>.+)zQ<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?(?:w\.)?soundcloud\.com/player.+?)\1zhttps://w.soundcloud.com/player/?visual=true&url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F922213810&show_artwork=true&maxwidth=640&maxheight=960&dnt=1&secret_token=s-ziYeyTurlonly_matchingzehttps://news.sophos.com/en-us/2023/08/10/s3-ep147-what-if-you-type-in-your-password-during-a-meeting/id
1588847423extm4atitlez=S3 Ep147: What if you type in your password during a meeting?artistszNaked Securitydescriptionz$md5:6931a0630b920413c8c904407bf4b3b2durationgjtv@genres
Technologylicenseall-rights-reservedrepost_counttagscount:4	thumbnail.re:https?://[ai]1\.sndcdn\.com/.+\.(?:jpg|png)	timestampi#dtrackupload_date20230809uploaderuploader_id61390843uploader_urlz%https://soundcloud.com/sophossecurityskip_downloadm3u8r   	info_dictparamszMhttps://www.guitarplayer.com/lessons/november-2023-guitar-player-lesson-audio
1695754080u,   A Tribute to Brian Setzer’s Guitar MasteryzGuitar Playerplaylist 	489924156)r   r   albumalbum_artists
album_typer    r/   r0      r   r6   playlist_mincountc                 C   s>   t |}|d d }|d}|rt|d|d i}| |S )Nr   r   secret_token)r   getr   
url_result)selfr   queryapi_urlrB    rH   O/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/soundcloud.py_real_extractH   s   

zSoundcloudEmbedIE._real_extractN)	__name__
__module____qualname__
_VALID_URL_EMBED_REGEX_TESTSint_WEBPAGE_TESTSrJ   rH   rH   rH   rI   r      st    	

%r   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	i Z
dZed	Zd
dddddddddd
Zg dZejdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd.d*d+Zed,d- Zd(S )/SoundcloudBaseIE
soundcloudzhttps://api-v2.soundcloud.com/https://soundcloud.com/sMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36z?client_id=%sz;https://api-auth.soundcloud.com/web-auth/sign-in/password%sz1https://api-auth.soundcloud.com/connect/session%sz-[0-9a-z]+\.(?P<ext>jpg|png)z"([^"]+)"|([^ ]+)          /   C   d   i,  i  i  r   )
minitinysmallbadget67x67larget300x300cropt500x500original)http_aachls_aac	http_opushls_opushttp_mp3hls_mp3c                    s2   t dt fdd jddgtdD jS )N|c                 3   s>    | ]}|d krt |ddn	dtt j jV  qdS )defaultz\*z.*rm   N)reescapereplacejoinmap_DEFAULT_FORMATS).0patternrE   rH   rI   	<genexpr>p   s    
z1SoundcloudBaseIE._is_requested.<locals>.<genexpr>formatsrn   )ie_key)ro   compilerr   set_configuration_argSoundcloudIE	fullmatchrw   rH   rw   rI   _is_requestedn   s
   
zSoundcloudBaseIE._is_requestedc                 C   s   | j dd| d S NrT   	client_id)cachestore)rE   r   rH   rH   rI   _store_client_idv      z!SoundcloudBaseIE._store_client_idc                 C   sn   |  dd d}ttd|D ]#}| j |d ddd}|r2| jd|dd d	}|r2|| _| |  d S qtd
)NrU   zDownloading main pagez<script[^>]+src="([^"]+)"zDownloading JS assetFfatalz#client_id\s*:\s*"([0-9a-zA-Z]{32})"z	client idrn   zUnable to extract client id)_download_webpagereversedro   findall_search_regex
_CLIENT_IDr   r	   )rE   webpagesrcscriptr   rH   rH   rI   _update_client_idy   s   
z"SoundcloudBaseIE._update_client_idc                 O   s   | ddu }|r|d= | di  }dD ]Q}| j|d< ||d< z| j|i |W   S  tyg } z/|rQt|jtrQ|jjdv rQ| 	d  | 
  W Y d }~q|rb| t| W Y d }~ dS  d }~ww d S )Nr   FrF   )TFr   )    )rC   copyr   _download_jsonr	   
isinstancecauser   statusr   r   report_warningstr)rE   argskwargs	non_fatalrF   is_first_attempterH   rH   rI   	_call_api   s*   

zSoundcloudBaseIE._call_apic                 C   s&   | j dd| _| jrd S |   d S r   )r   loadr   r   rw   rH   rH   rI   _initialize_pre_login   s   z&SoundcloudBaseIE._initialize_pre_loginc              
   C   s^   | j | j| j| j  d ddtdd|ii dr(d| | jd< |   d S | 	d d S )	NzVerifying login token...Fsessionaccess_token)noter   datazOAuth Authorizationz<Provided authorization token is invalid. Continuing as guest)
_request_webpage_API_VERIFY_AUTH_TOKEN_API_AUTH_QUERY_TEMPLATEr   jsondumpsencode_HEADERSreport_loginr   rE   tokenrH   rH   rI   _verify_oauth_token   s   z$SoundcloudBaseIE._verify_oauth_tokenc                    s0    j rd S t fdd }r | d S d S )Nc                      s      jd jS )Noauth_token)_get_cookies	_BASE_URLvaluerH   rw   rH   rI   <lambda>   s    z3SoundcloudBaseIE._real_initialize.<locals>.<lambda>)r   r   r   r   rH   rw   rI   _real_initialize   s
   z!SoundcloudBaseIE._real_initializec                 C   s:   |dkrt d| jdd dd| jrd S | | d S )NoauthzLogin using username and password is not currently supported. Use "--username oauth --password <oauth_token>" to login using an oauth token, or else cookies)methodTexpected)r	   _login_hintr   r   )rE   usernamepasswordrH   rH   rI   _perform_login   s   

zSoundcloudBaseIE._perform_loginc                 C   s   d}d}d}d}d}d}	d}
d}d}d	}d
}d}|}|}d dd ||||||	|
|fD }|| | | | | | | }d}tt|D ]}|d? d|@ d>  }|t|| 7 }|dM }qF| d| d|dd| S )N!   r   i; u   i@w i  %       0763ed7314c69015fd4a0dc16bbf4b908rV   -c                 S   s   g | ]}t |qS rH   r   )ru   mIntrH   rH   rI   
<listcomp>       z)SoundcloudBaseIE.sign.<locals>.<listcomp>i>z    i :x)rr   rangelenord)rE   userpwclidaiswulbkcnyrr   tdhmfrH   rH   rI   sign   s,   $ 
zSoundcloudBaseIE.signNFc           $         sZ  t d }t  g }d}d| ji}|r||d< |sdrdrz| j| j d| d|d	|| jd
}	W nC ty{ }
 z7t|
j	t
rW|
j	jdkrW| d|    nt|
j	t
ri|
j	jdkri| d n| |
j d }	W Y d }
~
nd }
~
ww t|	dthf }r| jt||dddd}|r|j} | |dt|t|jd|dddd  fdd}tdddd fD ]:}|r n4|d }|d  }|d!d" }t|d#d$t hfpd%}|d&rd'}q|d(krd%}|d)krd*|v rd)}|d+ksd,|v rd-}| d!| }|d.kr| d/| d0 q| |s-| d1| d2 qt| j||d3| d4|| jd
dthf}||rHq | t|d#d5t hf}| jd6|d7d d8}d9d:d;|rm|d d< nd pvt|d d8}|r|d=kr|}|d>d?k}t| jd@|d.d d8p| jdA|d.d d8p|rdB|v rdCnd }|dDpdE|v pt !dF|}|t"|||odGd!dH|||d||dIv rdJnd%|d9krdKnd |rdLn|r|dMkrd"ndN|rdOnd |rdPnd dQ q|s|r| #| dRdSkr| j$d'dT dUpi }g }dV}|p,|dW}t|rt !| j%| }r| j&' D ]F\} }!| dXkrO|(dYndZ}| t )| j%d[|  d\| |d]}"| d^krm|smd_}!n	| dXkrvd|"d`< |!r|"*|!|!da ||" qAnd|ig}fdbdc}#i d|dd|dedft+|dp|dgdh|didjt,dkdldldmdldndndo|dpt-dpdqdrdidsdsdt|#dudv|#dwp|#dxdy|#dzd{|#d|d}td~t ht.t/t.ftd| j0j1hddt.ftddt ht.t/t.f|s(|dS d dS )Nr   Fr   rB   downloadablehas_downloads_lefttracks/z	/downloadz.Downloading original download format info JSONrF   headersr   zAOriginal download format is only available for registered users. r   z9Original download format is not available for this clientredirectUriz.Checking original download format availabilityz)Original download format is not availabler   downloadzContent-Length
   Originalnone)	format_idr   filesizer   qualityformat_notevcodecc                    s   |  p|  v S NrH   )r   )format_urlsrH   rI   invalid_url%  s   z8SoundcloudBaseIE._extract_info_dict.<locals>.invalid_urlmediatranscodingsc                 S   s   t |d o	|d S )Nr   preset)r   )_vrH   rH   rI   r   )  r   z5SoundcloudBaseIE._extract_info_dict.<locals>.<lambda>r   r   r   r   formatprotocolhttp)zctr-zcbc-Tprogressivehlsz/hlszencrypted-hlsz/encrypted-hlshls-aesabrzSkipping broken "z" format"z%" is not a requested format, skippingzDownloading z format info JSON	mime_typezcodecs="([^"]+)"codecr   r   opus)mp4ar
     r4   r   hqz(\d+)k$z\.(\d+)\.(?:opus|mp3)[/?]aac   snippedz	/preview/z/(?:preview|playlist)/0/30/preview)delim)r  r  m3u8_nativem4a_dashr      Premiumi)r   r   r   acodecr   r  r  	containerr   r   
preferencepolicyBLOCK)metadata_availabler   artwork_url
avatar_urlrf   r   jpgr   .r   r   r^      r  )widthheightc                    s   t  |  dS )N_count)r   rC   key)inforH   rI   extract_count  r   z:SoundcloudBaseIE._extract_info_dict.<locals>.extract_countr/   r   r0   	permalinkr2   permalink_urlr+   
created_atr   r,   r    
thumbnailsr!   i  webpage_urlr$   
view_countplayback
like_countfavoritingslikescomment_countcommentr&   repostsr"   genretag_list.publisher_metadataartist)r'   r   ry   )2r   r|   r   rC   r   _API_V2_BASEr   r	   r   r   r   r   r   r   write_debugmsgr   r   r   r   r   addappendr   r   r   	partition
startswithr   r   r   r   ro   searchr   
report_drmraise_geo_restricted_IMAGE_REPL_RE_ARTWORK_MAPitemsgroupsubupdater   r   r
   filterall_TAGS_REr   )$rE   r)  
full_titlerB   extract_flattrack_idry   has_drmrF   download_datar   redirect_urlurlh
format_urlr   r   r   preset_baser  short_identifier
stream_urlr  r	  r   
is_premiumr  
is_previewr   r.  r  r)   mobjimage_idsizer   r*  rH   )r   r)  rI   _extract_info_dict   sl  










 










	


z#SoundcloudBaseIE._extract_info_dictc                 C   s   | j d | S )Nzresolve?url=)r<  )clsr   rH   rH   rI   _resolv_url  s   zSoundcloudBaseIE._resolv_url)NNF)rK   rL   rM   _NETRC_MACHINEr<  r   _USER_AGENTr   _API_AUTH_URL_PWr   r   rF  ro   r{   rN  rG  rt   	functoolscached_propertyr   r   r   r   r   r   r   r   r   r_  classmethodra  rH   rH   rH   rI   rS   Q   sJ    


+
 /rS   c                   @   s
  e Zd ZdZdZdZddi dddd	d
ddddddddddddddddddededededd d!d"d#d$id%d&i dd'dd	d
d(dd(dd)dd*dd+dd,dd-dd.dddedededed!d/dd d0gd*gg d1d2d3d4i dd5dd6d
d7dd7dd8dd9dd:dd;dd<dd=dddedededed!d>dd d?gg d@d%dAd4i dd5dd6d
d7dd7dd8dd9dd:dd;dd<dd=dddedededed!d>dd d?gg d@d%dBdCi ddDdd	d
dEddEddFddGddHd!dIddJddKddLdd dddededededMgdGgdNd1dOgdPdQdRi ddSdd	d
dTddTddUddVddWddXddYddZdddededededd d!d[d\gd]gd^d1dOgdPd_d`i ddadd6d
dbddbddcdddddeddfddgddhdd dddedededed!didjgg dkdldmidndodpi ddqddrd
dsddsddtdduddvddwddxddydd dddededededzd{gd|d}d~dldmidndi ddddrd
dddFddddd!ddededededdd#g ddgdddddddd ddddddddddddddddddddddddddddddg
ddmddddddddddddgZdd ZdS )r~   a]  Information extractor for soundcloud.com
       To access the media, the uid of the song and a stream token
       must be extracted from the page source and the script must make
       a request to media.soundcloud.com/crossdomain.xml. Then
       the media can be grabbed by requesting from an url composed
       of the stream token and uid
     a  (?x)^(?:https?://)?
                    (?:(?:(?:www\.|m\.)?soundcloud\.com/
                            (?!stations/track)
                            (?P<uploader>[\w\d-]+)/
                            (?!(?:tracks|albums|sets(?:/.+?)?|reposts|likes|spotlight|comments)/?(?:$|[?#]))
                            (?P<title>[\w\d-]+)
                            (?:/(?P<token>(?!(?:albums|sets|recommended))[^?]+?))?
                            (?:[?].*)?$)
                       |(?:api(?:-v2)?\.soundcloud\.com/tracks/(?:soundcloud%3Atracks%3A)?(?P<track_id>\d+)
                          (?:/?\?secret_token=(?P<secret_token>[^&]+))?)
                    )
                    rT   z9http://soundcloud.com/ethmusic/lostin-powers-she-so-heavy de9bac153e7427a7333b4b0c1b6a18d2r   62986583r   r
  r   zELostin Powers - She so Heavy (SneakPreview) Adrian Ackers Blueprint 1r,   r    z$md5:7b6074e00887ad79f59b647c8fb6d5aer/   zE.T. ExTerrestrial Musicr0   1571244r+   iV'vPr-   20121011r!   gxa@r$   r%   r0  r2  r5  r&   r)   r*   r2   zhttps://soundcloud.com/ethmusicr'   zcount:14)r   md5r6   zihttps://soundcloud.com/the-concept-band/goldrushed-mastered?in=the-concept-band/sets/the-royal-concept-ep47127627
Goldrushedz$md5:c0080b79a3710811d60234f94f391a40The Royal Concept9615865iO20120521gKcl@z'https://soundcloud.com/the-concept-bandAlternative)r"   r   r'   )r   r6   zDhttps://soundcloud.com/jaimemf/youtube-dl-test-video-a-y-baw/s-8Pjrp aa0dd32bfea9b0c5ef4f02aacd080604	123998367mp3u!   Youtube - Dl Test Video '' Ä↭z$md5:610b729ee06ac4cedaa28607212948f3jaimeMF69767071ixR20131209gv#@zhttps://soundcloud.com/jaimemf	youtubedl)r"   r'   z@https://api.soundcloud.com/tracks/123998367?secret_token=s-8Pjrpz+https://soundcloud.com/the80m/the-following ecb87d7705d5f53e6c02a63760573c75	343609555zThe Followingr:   80M	312384765zhttps://soundcloud.com/the80m20170922iYgSx@zDance & EDMr(   z?Original download format is only available for registered users)r   rl  r6   expected_warningszBhttps://soundcloud.com/oriuplift/uponly-238-no-talking-wav/s-AyZUd 2e1530d0e9986a833a67cb34fc90ece0	340344461zOUplifting Only 238 [No Talking] (incl. Alex Feed Guestmix) (Aug 31, 2017) [wav]z$md5:fa20ee0fca76a3d6df8c7e57f3715366zOri Uplift Music12563093i]Y20170831gjt@z https://soundcloud.com/oriupliftTrancez
Ori Upliftzcount:6z5https://soundcloud.com/garyvee/sideways-prod-mad-real 59c7872bc44e5d99b7211891664760c2	309699954zSideways (Prod. Mad Real)z$md5:d41d8cd98f00b204e9800998ecf8427egaryvee2366352iYgX20170226gMbi@zhttps://soundcloud.com/garyveeMadReal)r   r'   r3   r4   )r   rl  r6   r7   z2https://soundcloud.com/giovannisarani/mezzo-valzer 8227c3473a4264df6b02ad7e5b7527ac	583011102r   zMezzo Valzerz$md5:f4d5f39d52e0ccc2b4f665326428901azGiovanni Sarani3352531i{ex\20190228g?5^If@r"   Pianoz%https://soundcloud.com/giovannisaranizcount:10)r2   r'   z*https://soundcloud.com/skorxh/audio-dealer
2011421339zaudio dealerz$KORCH	150292288zhttps://soundcloud.com/skorxhg^Ij@r   z$KORXHig20250117r]   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-mini.jpgr"  r^   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-tiny.jpgr_   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-small.jpgr`   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-badge.jpgra   zAhttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t67x67.jpgrb   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-large.jpgrc   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t300x300.jpgrd   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-crop.jpgre   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t500x500.jpgrf   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-original.png)r$   r)   r.  hls_aac_160k)r3   r   r5   zQhttps://soundcloud.com/wandw/the-chainsmokers-ft-daya-dont-let-me-down-ww-remix-1Tr   zChttps://soundcloud.com/taylorswiftofficial/look-what-you-made-me-dozBhttps://api.soundcloud.com/tracks/soundcloud%3Atracks%3A1083788353c                 C   s  |  |}|d}i }|r#| jd | }|}|d}|r"||d< n!dj|dd  }}|d}|r<|d| 7 }| | j| }| j||d	|| jd
}	|  D ]6}
z
| 	|	||W   S  t
y } zt|jtrs|jjdkrt | jddd |j|
_W Y d }~qSd }~ww d S )NrQ  r   rB   z{}/{}r/   r   r   /zDownloading info JSONr   i  zYou have reached the API rate limit, which is ~600 requests per 10 minutes. Use the --extractor-retries and --retry-sleep options to configure an appropriate retry count and wait timeT)	only_once)_match_valid_urlrI  r<  r   ra  r   r   r   RetryManagerr_  r	   r   r   r   r   r   error)rE   r   r\  rQ  rF   info_json_urlrO  r   resolve_titler)  retryr   rH   rH   rI   rJ     s@   



zSoundcloudIE._real_extractN)	rK   rL   rM   __doc__rN   IE_NAMErQ   rP   rJ   rH   rH   rH   rI   r~     s$   	
	
	
	
	
	
	
	
	
!'  r~   c                   @   s   e Zd ZdddZdS )SoundcloudPlaylistBaseIENc           
   	   C   sH  t |d }|dpg }tdd |D s2|r2| j| jd |dddd |D ||d	| jd
}t|dt hfddt hfdt hdd hfd}g }|D ]4}t|d}|d}	|	so|s`qM| jd | }	|ro|	d| 7 }	|	| j
|	t |fddi| qM| j|||d|dfi |t|ddt hfddthfdS )Nr   tracksc                 s   s    | ]}| d V  qdS )r,  N)rC   ru   r   rH   rH   rI   rx     s    z8SoundcloudPlaylistBaseIE._extract_set.<locals>.<genexpr>zDownloading tracks,c                 S   s   g | ]}t |d  qS )r   r   r  rH   rH   rI   r     s    z9SoundcloudPlaylistBaseIE._extract_set.<locals>.<listcomp>)ids
playlistIdplaylistSecretTokenr   r   r   r   set_typec                 S   s   | pdS )Nr9   rH   r   rH   rH   rI   r     s    z7SoundcloudPlaylistBaseIE._extract_set.<locals>.<lambda>)r<   album_artistr>   r,  r   z?secret_token=url_transparentTr    )r/   r0   )r   rC   rM  r   r<  rr   r   r   r   r@  rD   r~   rz   playlist_result)
rE   r9   r   playlist_idr  
album_infoentriesr,   rQ  r   rH   rH   rI   _extract_set  s\   






z%SoundcloudPlaylistBaseIE._extract_setr   )rK   rL   rM   r  rH   rH   rH   rI   r    s    r  c                
   @   s^   e Zd ZdZdZddddddddgd	d
ddddddddddddddgZdd ZdS )SoundcloudSetIEzuhttps?://(?:(?:www|m)\.)?soundcloud\.com/(?P<uploader>[\w\d-]+)/sets/(?P<slug_title>[:\w\d-]+)(?:/(?P<token>[^?/]+))?zsoundcloud:setzAhttps://soundcloud.com/the-concept-band/sets/the-royal-concept-ep2284613zThe Royal Concept EPz$md5:71d07087c7a449e8941a70a29e34671ero  rp  ep)r   r   r    r/   r0   r<   r=   r>   r   r@   zGhttps://soundcloud.com/the-concept-band/sets/the-royal-concept-ep/tokenTr   z6https://soundcloud.com/discover/sets/weekly::flacmaticz<https://soundcloud.com/discover/sets/charts-top:all-music:dez<https://soundcloud.com/discover/sets/charts-top:hiphoprap:krc                 C   s   |  |}dj|dd }|d}|r|d| 7 }| j| | j| || jd}d|v rAdd	 |d D }td
d|| 	||S )Nz
{}/sets/{}r/   
slug_titler   r  r   errorsc                 s       | ]	}t |d  V  qdS error_messageNr   ru   errrH   rH   rI   rx   6  s    z0SoundcloudSetIE._real_extract.<locals>.<genexpr>z$unable to download video webpage: {}r  )
r  r   rI  r   ra  r   r   r	   rr   r  )rE   r   r\  rO  r   r)  msgsrH   rH   rI   rJ   *  s   

zSoundcloudSetIE._real_extractNrK   rL   rM   rN   r  rP   rJ   rH   rH   rH   rI   r    s:    
r  c                   @   s*   e Zd Zdd Zejdd Zdd ZdS )SoundcloudPagedPlaylistBaseIEc                 C   s   d|||  ||dS )Nr9   )_typer   r   r  )_entries)rE   base_urlr  playlist_titlerH   rH   rI   _extract_playlist=  s
   
z/SoundcloudPagedPlaylistBaseIE._extract_playlistc                 C   sb   | j  }|s	dS tdddd}dd }tdd	 |D |d
}|r+||d ||k r-|S |d S )NTchrome116windows10c                 S   s   | j rt| j S dS )Nr   )versionfloatr  rH   rH   rI   r   N  r   zKSoundcloudPagedPlaylistBaseIE._browser_impersonate_target.<locals>.<lambda>c                 S   s0   g | ]}|d  j dkr|d  jdv r|d  qS )r   r  )r  macos)clientos)ru   targetrH   rH   rI   r   Q  s
    zMSoundcloudPagedPlaylistBaseIE._browser_impersonate_target.<locals>.<listcomp>r'  r  )_downloader"_get_available_impersonate_targetsr   sorted)rE   available_targetsMIN_SUPPORTED_TARGETversion_as_floatfilteredrH   rH   rI   _browser_impersonate_targetE  s   
z9SoundcloudPagedPlaylistBaseIE._browser_impersonate_targetc           	      #   s    dddd}t  D ]l}  D ]9}z j||| jd|d   jd}W  n" tyJ } zt|jt	r<|jj
dkr= ||_W Y d }~qd }~ww  fd	d
}|d pVg D ]}|||d|dV  qW|d}|sq d S |dd  qd S )N   1r   limitlinked_partitioningoffsetzDownloading track page r   )rF   r   r   impersonatei  c               	      sb   | D ],}t |ts
qt|d}|r. |t|rt nd t|d|d  S qd S )Nr,  r   r   )	r   dictr   rC   rD   r~   suitablerz   r   )
candidatescandr,  rw   rH   rI   resolve_entryw  s   
z=SoundcloudPagedPlaylistBaseIE._entries.<locals>.resolve_entry
collectionr,   r9   	next_hrefr  )	itertoolscountr  r   r   r  r	   r   r   r   r   r  rC   pop)	rE   r   r  rF   r   r  responser   r  rH   rw   rI   r  ]  s:   

z&SoundcloudPagedPlaylistBaseIE._entriesN)rK   rL   rM   r  re  rf  r  r  rH   rH   rH   rI   r  <  s
    
r  c                   @   s   e Zd ZdZdZddddddd	dd
dddddddddddddddddddddddddddddddddddd dddgZd!d"d#d$d%d&d'd(d)Zd*d+ Zd,S )-SoundcloudUserIEam  (?x)
                        https?://
                            (?:(?:www|m)\.)?soundcloud\.com/
                            (?P<user>[^/]+)
                            (?:/
                                (?P<rsrc>tracks|albums|sets|reposts|likes|spotlight|comments)
                            )?
                            /?(?:[?#].*)?$
                    zsoundcloud:userz)https://soundcloud.com/soft-cell-official	207965082zSoft Cell (All)r   r      r@   z0https://soundcloud.com/soft-cell-official/trackszSoft Cell (Tracks)   z0https://soundcloud.com/soft-cell-official/albumszSoft Cell (Albums)r   z"https://soundcloud.com/jcv246/sets12982173zJordi / cv (Sets)r   z%https://soundcloud.com/jcv246/repostszJordi / cv (Reposts)   z%https://soundcloud.com/clalberg/likes11817582zclalberg (Likes)r   z*https://soundcloud.com/grynpyret/spotlight7098329zGrynpyret (Spotlight)r   z4https://soundcloud.com/one-thousand-and-one/comments	992430331z7x11x13-testing (Comments)zstream/users/%szusers/%s/trackszusers/%s/albumszusers/%s/playlistszstream/users/%s/repostszusers/%s/likeszusers/%s/spotlightzusers/%s/comments)rM  r  albumssetsr7  r4  	spotlightcommentsc              	   C   s~   |  |}|d}| j| | j| |d| jd}|dp d}| | j| j| |d   t	|
dd|d | S )	Nr   Downloading user infor  rsrcrM  r   {} ({})r   )r  rI  r   ra  r   r   r  r<  _BASE_URL_MAPr   rC   r   
capitalize)rE   r   r\  r/   r   resourcerH   rH   rI   rJ     s   

zSoundcloudUserIE._real_extractNrK   rL   rM   rN   r  rP   r  rJ   rH   rH   rH   rI   r    s|    	;r  c                   @   0   e Zd ZdZdZddddddgZd	d
 ZdS )SoundcloudUserPermalinkIEz/https?://api\.soundcloud\.com/users/(?P<id>\d+)zsoundcloud:user:permalinkz)https://api.soundcloud.com/users/3090986930909869neilcicr     r@   c                 C   sR   |  |}| j| ||d| jd}| | j d|d  dt|d |dS )Nr  r  zusers/r   z/tracksr   )	_match_idr   ra  r   r  r<  r   rC   )rE   r   user_idr   rH   rH   rI   rJ     s   
&z'SoundcloudUserPermalinkIE._real_extractNr  rH   rH   rH   rI   r        	r  c                   @   r  )SoundcloudTrackStationIEzNhttps?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)zsoundcloud:trackstationz?https://soundcloud.com/stations/track/officialsundial/your-text	286017854zTrack station: your textr  rZ   r@   c                 C   s\   |  |}| j| ||| jd}| d|d d}| | jd|d  |d|d S )Nr  zsoundcloud:track-stations:(\d+)r   ztrack idzstations/{}/trackszTrack station: {}r   )r  r   ra  r   r   r  r<  r   )rE   r   
track_namer,   rQ  rH   rH   rI   rJ     s   

z&SoundcloudTrackStationIE._real_extractNr  rH   rH   rH   rI   r     r  r  c                   @   s\   e Zd ZdZdZddddddd	dd
dddddddddgZddddZdd ZdS )SoundcloudRelatedIEzjhttps?://(?:(?:www|m)\.)?soundcloud\.com/(?P<slug>[\w\d-]+/[\w\d-]+)/(?P<relation>albums|sets|recommended)zsoundcloud:relatedz;https://soundcloud.com/wajang/sexapil-pingers-5/recommended
1084577272z!Sexapil - Pingers 5 (Recommended)r  1   r@   z6https://soundcloud.com/wajang/sexapil-pingers-5/albumszSexapil - Pingers 5 (Albums)r   z4https://soundcloud.com/wajang/sexapil-pingers-5/setszSexapil - Pingers 5 (Sets)r  ztracks/%s/albumsz"tracks/%s/playlists_without_albumsztracks/%s/related)r  r  recommendedc              	   C   s   |  |dd\}}| j| | j| |d| jd}|dr6t| j dd	dd	 |d D  d
d| 
| j| j| |d   t|d d|dpP|| S )NslugrelationzDownloading track infor  r  z	 said: %sr  c                 s   r  r  r   r  rH   rH   rI   rx   @  s    
z4SoundcloudRelatedIE._real_extract.<locals>.<genexpr>Tr   r   r  r   )r  rI  r   ra  r   r   rC   r	   r  rr   r  r<  r  r   r   r  )rE   r   r	  r
  r,   rH   rH   rI   rJ   8  s   
 z!SoundcloudRelatedIE._real_extractNr  rH   rH   rH   rI   r    s6    r  c                
   @   sN   e Zd ZdZdZdddddddgd	dd
ddddddddgZdd ZdS )SoundcloudPlaylistIEzhttps?://api(?:-v2)?\.soundcloud\.com/playlists/(?:soundcloud(?:%3A|:)playlists(?:%3A|:))?(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$zsoundcloud:playlistz,https://api.soundcloud.com/playlists/41103094110309z=TILT Brass - Bowery Poetry Club, August '03 [Non-Site SCR 02]z$md5:e4373f7177fe3db292a8552b4ec41bc6zNon-Site Records33660914r9   )r   r   r    r/   r0   r=   r>   r<   r  r   r6   playlist_countzHhttps://api.soundcloud.com/playlists/soundcloud%3Aplaylists%3A1759227795Tr   z_https://api.soundcloud.com/playlists/soundcloud:playlists:2104769627?secret_token=s-wmpCLuExeYXc                 C   sZ   |  |}|d}i }|d}|r||d< | j| jd | |d|| jd}| ||S )Nr   r   rB   z
playlists/zDownloading playlistr   )r  rI  r   r<  r   r  )rE   r   r\  r  rF   r   r   rH   rH   rI   rJ   `  s   



z"SoundcloudPlaylistIE._real_extractNr  rH   rH   rH   rI   r  H  s.    
r  c                   @   sD   e Zd ZdZdZdZddddddgZd	Zd
Zdd Z	dd Z
dS )SoundcloudSearchIEzsoundcloud:searchzSoundcloud searchscsearchzscsearch15:post-avant jazzcorezpost-avant jazzcorer     r  r  2   c           	   	   k   s    t |d| j| j}||ddd t| j| |}tdD ]:}| j	||d| d| j
d}|dp8g D ]}|rQ| j|d	 t fi | j|d
dV  q9|d}|s\ d S q"d S )Nr  r   r   r  zDownloading page zUnable to download API pager  r  uriT)rP  r  )minrC   _DEFAULT_RESULTS_PER_PAGE_MAX_RESULTS_PER_PAGErK  r   r<  r  r  r   r   rD   r~   rz   r_  )	rE   endpointcollection_idrF   r  next_urlr   r  itemrH   rH   rI   _get_collection  s:   
z"SoundcloudSearchIE._get_collectionc              
   C   s6   |  t| jd|||dd|tdkrd n|||S )Nzsearch/tracks)r  qr   inf)r  r  islicer  r  )rE   rF   r   rH   rH   rI   _get_n_results  s   z!SoundcloudSearchIE._get_n_resultsN)rK   rL   rM   r  IE_DESC_SEARCH_KEYrP   r  r  r  r   rH   rH   rH   rI   r  p  s    	r  )(re  r  r   ro   commonr   r   
networkingr   networking.exceptionsr   networking.impersonater   utilsr	   r
   r   r   r   r   r   r   r   r   r   r   utils.traversalr   r   rS   r~   r  r  r  r  r  r  r  r  r  rH   rH   rH   rI   <module>   s4    86  ]  9)0O`0(