a
    h                     @   sR  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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)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ddd	d
gdddgdedddd	dd
dddddiddddddgddddd d!d"gZd#d$ Zd%S )&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urlZonly_matchingzehttps://news.sophos.com/en-us/2023/08/10/s3-ep147-what-if-you-type-in-your-password-during-a-meeting/Z
1588847423m4az=S3 Ep147: What if you type in your password during a meeting?zNaked Securityz$md5:6931a0630b920413c8c904407bf4b3b2gjtv@Z
Technologyall-rights-reservedcount:4.re:https?://[ai]1\.sndcdn\.com/.+\.(?:jpg|png)i#dZ20230809Z61390843z%https://soundcloud.com/sophossecurity)idexttitleartistsdescriptiondurationgenreslicenserepost_counttags	thumbnail	timestamptrackupload_dateuploaderuploader_iduploader_urlskip_downloadm3u8r   	info_dictparamszMhttps://www.guitarplayer.com/lessons/november-2023-guitar-player-lesson-audioZ
1695754080u,   A Tribute to Brian Setzer’s Guitar MasteryzGuitar Playerplaylist Z	489924156)r   r   albumalbum_artists
album_typer    r*   r+      r   r0   Zplaylist_mincountc                 C   s>   t |}|d d }|d}|r4t|d|d i}| |S )Nr   r   secret_token)r   getr   
url_result)selfr   queryZapi_urlr9    r>   P/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/extractor/soundcloud.py_real_extractG   s    
zSoundcloudEmbedIE._real_extractN)	__name__
__module____qualname__
_VALID_URLZ_EMBED_REGEX_TESTSintZ_WEBPAGE_TESTSr@   r>   r>   r>   r?   r      sP   
%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)Zhttp_aacZhls_aacZ	http_opusZhls_opusZhttp_mp3Zhls_mp3c                    s2   t dt fdd jddgtdD jS )N|c                 3   s<   | ]4}|d kr t |ddndtt j jV  qdS )defaultz\*z.*r[   N)reescapereplacejoinmap_DEFAULT_FORMATS).0patternr<   r>   r?   	<genexpr>o   s   z1SoundcloudBaseIE._is_requested.<locals>.<genexpr>formatsr\   )ie_key)r]   compiler`   setZ_configuration_argSoundcloudIE	fullmatchre   r>   re   r?   _is_requestedm   s    zSoundcloudBaseIE._is_requestedc                 C   s   | j dd| d S )NrH   	client_id)cachestore)r<   rn   r>   r>   r?   _store_client_idu   s    z!SoundcloudBaseIE._store_client_idc                 C   sn   |  dd }ttd|D ]D}| j |d dd}|r| jd|dd d}|r|| _| |  d S qtdd S )	NrI   z<script[^>]+src="([^"]+)"Ffatalz#client_id\s*:\s*"([0-9a-zA-Z]{32})"z	client idr\   zUnable to extract client id)Z_download_webpagereversedr]   findall_search_regex
_CLIENT_IDrq   r   )r<   Zwebpagesrcscriptrn   r>   r>   r?   _update_client_idx   s    
z"SoundcloudBaseIE._update_client_idc                 O   s   | ddu }|r|d= | di  }tdD ]}| j|d< ||d< z| j|i |W   S  ty } zht|jtr|jj	dv r| 
d  |   W Y d }~q0n"|r| t| W Y d }~ dS  W Y d }~q0d }~0 0 q0d S )Nrs   Fr=   r   rn   )    )r:   copyrangerx   _download_jsonr   
isinstancecauser   statusrq   r{   report_warningstr)r<   argskwargsZ	non_fatalr=   _er>   r>   r?   	_call_api   s$    

zSoundcloudBaseIE._call_apic                 C   s   | j ddpd| _d S )NrH   rn   Z a3e059563d7fd3372b49b37f00a00bcf)ro   loadrx   re   r>   r>   r?   _initialize_pre_login   s    z&SoundcloudBaseIE._initialize_pre_loginc              
   C   s\   | j | j| j| j  d ddtdd|ii drNd| | jd< |   n
| 	d d S )	NzVerifying login token...FsessionZaccess_token)noters   datazOAuth Authorizationz<Provided authorization token is invalid. Continuing as guest)
_request_webpage_API_VERIFY_AUTH_TOKEN_API_AUTH_QUERY_TEMPLATErx   jsondumpsencode_HEADERSZreport_loginr   r<   tokenr>   r>   r?   _verify_oauth_token   s    
z$SoundcloudBaseIE._verify_oauth_tokenc                    s,    j r
d S t fdd }r( | d S )Nc                      s      jd jS )NZoauth_token)Z_get_cookies	_BASE_URLvaluer>   re   r>   r?   <lambda>       z3SoundcloudBaseIE._real_initialize.<locals>.<lambda>)r   r   r   r   r>   re   r?   _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 )NZ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   )r<   usernamepasswordr>   r>   r?   _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 ]0}|d? d|@ d>  }|t|| 7 }|dM }q| d| d|dd| S )N!   r   i; u   i@w i  %      Z 0763ed7314c69015fd4a0dc16bbf4b908rJ   -c                 S   s   g | ]}t |qS r>   r   )rc   ZmIntr>   r>   r?   
<listcomp>   r   z)SoundcloudBaseIE.sign.<locals>.<listcomp>i>z    i :x)r`   r   lenord)r<   userpwZclidaiswulbkcnyrr   tdhmfr>   r>   r?   sign   s,    $ 
zSoundcloudBaseIE.signNFc           $         s,  t d }t  g }d}d| ji}|r0||d< |sldrldrlz(| j| j d| d|d	|| jd
}	W n ty }
 znt|
j	t
r|
j	jdkr| d|    n0t|
j	t
r|
j	jdkr| d n| |
j d }	W Y d }
~
n
d }
~
0 0 t|	dthf }rl| jt||dddd}|rl|j} | |dt|t|jd|dddd  fdd}tdddd fD ]}|r q|d }|d  }|d!d" }t|d#d$t hfpd%}|d&rd'}q|d(krd%}|d)krd*|v rd)}|d+ks"d,|v r&d-}| d!| }|d.krT| d/| d0 q| |sv| d1| d2 qt| j||d3| d4|| jd
dthf}||rq | t|d#d5t hf}| jd6|d7d d8}d9d:d;|r|d d< nd p
t|d d8}|r|d=kr |}|d>d?k}t| jd@|d.d d8pn| jdA|d.d d8pn|rldB|v rldCnd }|dDpdE|v pt !dF|}|t"|||odGd!dH|||d||dIv rdJnd%|d9krdKnd |rdLn|r|dMkrd"ndN|r dOnd |rdPnd dQ q|sL|r0| #| dRdSkrL| j$d'dT dUpZi }g }dV}|px|dW}t|r<t !| j%| }r2| j&' D ]\} }!| dXkr|(dYndZ}| t )| j%d[|  d\| |d]}"| d^kr|sd_}!n| dXkrd|"d`< |!r"|"*|!|!da ||" qn
d|ig}fdbdc}#||ddt+|dpj|de|dft,dgdhdhdi|t-djdkdfdl|#dm|#dnp|#do|#dp|#dqtdrt ht.t/t.ftds| j0j1hdtdtt.ftdudvt ht.t/t.f|s$|nd dwS )xNr   Frn   r9   ZdownloadableZhas_downloads_lefttracks/z	/downloadz.Downloading original download format info JSONr=   headersr|   zAOriginal download format is only available for registered users. r}   z9Original download format is not available for this clientZredirectUriz.Checking original download format availabilityz)Original download format is not availablerr   downloadzContent-Length
   ZOriginalnone)	format_idr   filesizer   qualityformat_notevcodecc                    s   |  p|  v S )Nr>   )r   )format_urlsr>   r?   invalid_url!  s    z8SoundcloudBaseIE._extract_info_dict.<locals>.invalid_urlZmediaZtranscodingsc                 S   s   t |d o|d S )Nr   preset)r   )r   vr>   r>   r?   r   %  r   z5SoundcloudBaseIE._extract_info_dict.<locals>.<lambda>r   r   r   r   formatprotocolhttp)zctr-zcbc-TZ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="([^"]+)"codecrt   r   opus)Zmp4ar      r.   r   Zhqz(\d+)k$z\.(\d+)\.(?:opus|mp3)[/?]Zaac   Zsnippedz	/preview/z/(?:preview|playlist)/0/30/preview)delim)r   r   Zm3u8_nativeZm4a_dashr      ZPremiumi)r   r   r   Zacodecr   r   r   	containerr   r   
preferencepolicyZBLOCK)Zmetadata_availabler   artwork_urlZ
avatar_urlrZ   r   Zjpgr   .r   r   rR      r   )widthheightc                    s   t  |  dS )N_count)r
   r:   )key)infor>   r?   extract_count  s    z:SoundcloudBaseIE._extract_info_dict.<locals>.extract_countr   Z	permalinkpermalink_urlZ
created_atr   r    r!   i  r#   ZplaybackZfavoritingslikescommentrepostsZgenreZtag_list.Zpublisher_metadataZartist)r   r*   r+   r,   r'   r   r(   r    
thumbnailsr!   Zwebpage_urlr#   
view_count
like_countcomment_countr$   r"   r%   r   rg   )2r   rj   rx   r:   r   _API_V2_BASEr   r   r   r   r   r   r   r   Zwrite_debugmsgr   r   r   r   r   addappendr   r
   r   	partition
startswithrm   r   rw   r   r]   searchr   Z
report_drmZraise_geo_restricted_IMAGE_REPL_RE_ARTWORK_MAPitemsgroupsubupdater   r   r	   filterall_TAGS_RErv   )$r<   r   
full_titler9   extract_flattrack_idrg   Zhas_drmr=   Zdownload_datar   Zredirect_urlZurlhZ
format_urlr   r   r   Zpreset_baser   Zshort_identifierZ
stream_urlr   r   r   Z
is_premiumr   Z
is_previewr   r   r   r&   mobjZimage_idsizer   r   r>   )r   r   r?   _extract_info_dict   s>   










 




z#SoundcloudBaseIE._extract_info_dictc                 C   s   | j d | S )Nzresolve?url=)r   )clsr   r>   r>   r?   _resolv_url  s    zSoundcloudBaseIE._resolv_url)NNF)rA   rB   rC   Z_NETRC_MACHINEr   r   Z_USER_AGENTr   Z_API_AUTH_URL_PWr   r   r  r]   ri   r  r  rb   	functoolscached_propertyrm   rq   r{   r   r   r   r   r   r   r  classmethodr  r>   r>   r>   r?   rG   P   sH   


+
 /rG   c                (   @   sz  e Zd ZdZdZdZddddddd	d
dddddeeeedddddddddddddddddeeeedddgdgg d d!d"d#d$d%d&d&d'd(d)d*d+d,deeeed-dd.gg d/dd0d#d$d%d&d&d'd(d)d*d+d,deeeed-dd.gg d/dd1d2d3dd4d4d5d6d7d8d9d:d;ddeeeed<gd6gd=d>d?gd@dAdBdCddDdDdEdFdGdHdIdJdeeeeddKdLgdMgdNdOd?gd@dPdQdRd%dSdSdTdUdVdWdXdYddeeeedZd[gg d\d]d^id_d`dadbdcdddddedfdgdhdidjddeeeedkgdldmdnd]d^id_dodpdcdqd5drdsdteeeedug dvgdqdwdxdddydzd{d|d}d{d~dd{ddd{ddd{ddd{ddd{ddd{ddd{ddd{g
dd^dddddddddgZdd ZdS )rk   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/(?P<track_id>\d+)
                          (?:/?\?secret_token=(?P<secret_token>[^&]+))?)
                    )
                    rH   z9http://soundcloud.com/ethmusic/lostin-powers-she-so-heavyZ de9bac153e7427a7333b4b0c1b6a18d2Z62986583r   zELostin Powers - She so Heavy (SneakPreview) Adrian Ackers Blueprint 1z$md5:7b6074e00887ad79f59b647c8fb6d5aezE.T. ExTerrestrial MusicZ1571244iV'vPZ20121011gxa@r   r   zhttps://soundcloud.com/ethmusiczcount:14)r   r   r   r(   r    r*   r+   r'   r)   r!   r#   r   r   r   r$   r&   r,   r%   )r   md5r0   zihttps://soundcloud.com/the-concept-band/goldrushed-mastered?in=the-concept-band/sets/the-royal-concept-epZ47127627Z
Goldrushedz$md5:c0080b79a3710811d60234f94f391a40The Royal Concept9615865iOZ20120521gKcl@z'https://soundcloud.com/the-concept-bandZAlternative)r   r   r   r(   r    r*   r+   r'   r)   r!   r#   r   r   r   r$   r,   r&   r"   r   r%   )r   r0   zDhttps://soundcloud.com/jaimemf/youtube-dl-test-video-a-y-baw/s-8PjrpZ aa0dd32bfea9b0c5ef4f02aacd080604Z	123998367Zmp3u!   Youtube - Dl Test Video '' Ä↭z$md5:610b729ee06ac4cedaa28607212948f3ZjaimeMFZ69767071ixRZ20131209gv#@zhttps://soundcloud.com/jaimemfZ	youtubedl)r   r   r   r(   r    r*   r+   r'   r)   r!   r#   r   r   r   r$   r,   r&   r"   r%   z@https://api.soundcloud.com/tracks/123998367?secret_token=s-8Pjrpz+https://soundcloud.com/the80m/the-followingZ ecb87d7705d5f53e6c02a63760573c75Z	343609555zThe Followingr3   Z80MZ	312384765zhttps://soundcloud.com/the80mZ20170922iYgSx@zDance & EDMr   )r   r   r   r(   r    r*   r+   r,   r)   r'   r!   r&   r#   r   r   r$   r   r"   r   r%   z?Original download format is only available for registered users)r   r  r0   Zexpected_warningszBhttps://soundcloud.com/oriuplift/uponly-238-no-talking-wav/s-AyZUdZ 2e1530d0e9986a833a67cb34fc90ece0Z	340344461zOUplifting Only 238 [No Talking] (incl. Alex Feed Guestmix) (Aug 31, 2017) [wav]z$md5:fa20ee0fca76a3d6df8c7e57f3715366zOri Uplift MusicZ12563093i]YZ20170831gjt@z https://soundcloud.com/oriupliftZTrancez
Ori Upliftzcount:6)r   r   r   r(   r    r*   r+   r'   r)   r!   r#   r   r   r   r$   r&   r,   r"   r   r%   z5https://soundcloud.com/garyvee/sideways-prod-mad-realZ 59c7872bc44e5d99b7211891664760c2Z	309699954zSideways (Prod. Mad Real)z$md5:d41d8cd98f00b204e9800998ecf8427eZgaryveeZ2366352iYgXZ20170226gMbi@zhttps://soundcloud.com/garyveeZMadReal)r   r   r   r(   r    r*   r+   r'   r)   r!   r&   r#   r   r   r   r$   r,   r   r%   r-   r.   )r   r  r0   r1   z2https://soundcloud.com/giovannisarani/mezzo-valzerZ 8227c3473a4264df6b02ad7e5b7527acZ	583011102r   zMezzo Valzerz$md5:f4d5f39d52e0ccc2b4f665326428901azGiovanni SaraniZ3352531i{ex\Z20190228g?5^If@ZPianoz%https://soundcloud.com/giovannisaranizcount:10)r   r   r   r(   r    r*   r+   r'   r)   r!   r&   r#   r   r   r   r$   r"   r,   r%   z*https://soundcloud.com/skorxh/audio-dealerZ
2011421339zaudio dealerz$KORCHZ	150292288zhttps://soundcloud.com/skorxhg^Ij@z$KORXHigZ20250117rQ   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-mini.jpgr   rR   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-tiny.jpgrS   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-small.jpgrT   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-badge.jpgrU   zAhttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t67x67.jpgrV   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-large.jpgrW   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t300x300.jpgrX   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-crop.jpgrY   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t500x500.jpgrZ   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-original.png)r   r   r   r    r*   r+   r,   r   r   r   r$   r!   r%   r   r(   r'   r)   r#   r&   r   Zhls_aac_160k)r-   r   r/   zQhttps://soundcloud.com/wandw/the-chainsmokers-ft-daya-dont-let-me-down-ww-remix-1Tr   zChttps://soundcloud.com/taylorswiftofficial/look-what-you-made-me-doc                 C   s  |  |}|d}i }|rF| jd | }|}|d}|r||d< nBdj|dd  }}|d}|rx|d| 7 }| | j| }| j||d	|| jd
}	|  D ]p}
z| 	|	||W   S  t
y } z<t|jtr|jjdkr | jddd |j|
_W Y d }~qd }~0 0 qd S )Nr  r   r9   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)Z	only_once)_match_valid_urlr  r   r   r  r   r   r   RetryManagerr  r   r   r   r   r   r   error)r<   r   r  r  r=   Zinfo_json_urlr  r   Zresolve_titler   retryr   r>   r>   r?   r@     s8    




zSoundcloudIE._real_extractN)	rA   rB   rC   __doc__rD   IE_NAMErF   rE   r@   r>   r>   r>   r?   rk     s  !'  |rk   c                   @   s   e Zd ZdddZdS )SoundcloudPlaylistBaseIENc           
   	   C   sH  t |d }|dpg }tdd |D sd|rd| 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 ]h}t|d}|d}	|	s|sq| jd | }	|r|	d| 7 }	|	| j
|	t |fddi| q| 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)r:   rc   r   r>   r>   r?   rf     r   z8SoundcloudPlaylistBaseIE._extract_set.<locals>.<genexpr>zDownloading tracks,c                 S   s   g | ]}t |d  qS )r   r   r$  r>   r>   r?   r     r   z9SoundcloudPlaylistBaseIE._extract_set.<locals>.<listcomp>)idsZ
playlistIdZplaylistSecretTokenr   r   r   r   set_typec                 S   s   | pdS )Nr2   r>   )r   r>   r>   r?   r     r   z7SoundcloudPlaylistBaseIE._extract_set.<locals>.<lambda>)r4   Zalbum_artistr6   r   r   z?secret_token=Zurl_transparentTr    )r*   r+   )r   r:   r  r   r   r`   r   r   r   r   r;   rk   rh   playlist_result)
r<   r2   r   playlist_idr#  Z
album_infoentriesr(   r  r   r>   r>   r?   _extract_set  s\    






z%SoundcloudPlaylistBaseIE._extract_set)N)rA   rB   rC   r+  r>   r>   r>   r?   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-epZ2284613zThe Royal Concept EPz$md5:71d07087c7a449e8941a70a29e34671er  r  ep)r   r   r    r*   r+   r4   r5   r6   r   r8   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}|r6|d| 7 }| j| | j| || jd}d|v rdd	 |d D }td
d|| 	||S )Nz
{}/sets/{}r*   Z
slug_titler   r  r   errorsc                 s   s   | ]}t |d  V  qdS error_messageNr   rc   errr>   r>   r?   rf   /  r   z0SoundcloudSetIE._real_extract.<locals>.<genexpr>z$unable to download video webpage: {}r%  )
r  r   r  r   r  r   r   r   r`   r+  )r<   r   r  r  r   r   Zmsgsr>   r>   r?   r@   #  s    

zSoundcloudSetIE._real_extractNrA   rB   rC   rD   r!  rE   r@   r>   r>   r>   r?   r,    s8   
r,  c                   @   s   e Zd Zdd Zdd ZdS )SoundcloudPagedPlaylistBaseIEc                 C   s   d|||  ||dS )Nr2   )_typer   r   r*  )_entries)r<   base_urlr)  Zplaylist_titler>   r>   r?   _extract_playlist6  s
    
z/SoundcloudPagedPlaylistBaseIE._extract_playlistc           	      #   s   dddd}t  D ]}  D ]}z* j||| jd|d  d}W  qW q  ty } z8t|jtrv|jj	dkrx ||_
W Y d }~q W Y d }~q d }~0 0 q  fd	d
}|d pg D ]}|||d|dV  q|d}|s q|dd  qd S )N   1r   limitZlinked_partitioningoffsetzDownloading track page r   )r=   r   r   i  c               	      sb   | D ]X}t |tsqt|d}|r |t|r>t nd t|d|d  S qd S )Nr   r   r   )	r   dictr   r:   r;   rk   Zsuitablerh   r   )
candidatescandr   re   r>   r?   resolve_entryV  s    
z=SoundcloudPagedPlaylistBaseIE._entries.<locals>.resolve_entry
collectionr(   r2   	next_hrefr>  )	itertoolscountr  r   r   r   r   r   r   r   r  r:   pop)	r<   r   r)  r=   r   r  responser   rB  r>   re   r?   r7  >  s0    

$
z&SoundcloudPagedPlaylistBaseIE._entriesN)rA   rB   rC   r9  r7  r>   r>   r>   r?   r5  5  s   r5  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-officialZ	207965082zSoft Cell (All)r   r      r8   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/setsZ12982173zJordi / cv (Sets)r   z%https://soundcloud.com/jcv246/repostszJordi / cv (Reposts)   z%https://soundcloud.com/clalberg/likesZ11817582zclalberg (Likes)r   z*https://soundcloud.com/grynpyret/spotlightZ7098329zGrynpyret (Spotlight)r   z4https://soundcloud.com/one-thousand-and-one/commentsZ	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)r  r#  albumssetsr   r   Z	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.  Zrsrcr  r   {} ({})r   )r  r  r   r  r   r   r9  r   _BASE_URL_MAPr   r:   r   
capitalize)r<   r   r  r*   r   resourcer>   r>   r?   r@     s    

zSoundcloudUserIE._real_extractNrA   rB   rC   rD   r!  rE   rS  r@   r>   r>   r>   r?   rI  j  sz   	;rI  c                   @   s0   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/30909869Z30909869ZneilcicrJ     r8   c                 C   sR   |  |}| j| ||d| jd}| | j d|d  dt|d |dS )NrQ  r.  zusers/r   z/tracksr   )	_match_idr   r  r   r9  r   r   r:   )r<   r   Zuser_idr   r>   r>   r?   r@     s    
&z'SoundcloudUserPermalinkIE._real_extractNr4  r>   r>   r>   r?   rW    s   	rW  c                   @   s0   e Zd ZdZdZddddddgZd	d
 ZdS )SoundcloudTrackStationIEzNhttps?://(?:(?:www|m)\.)?soundcloud\.com/stations/track/[^/]+/(?P<id>[^/?#&]+)zsoundcloud:trackstationz?https://soundcloud.com/stations/track/officialsundial/your-textZ	286017854zTrack station: your textrJ  rN   r8   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   )rY  r   r  r   rw   r9  r   r   )r<   r   Z
track_namer(   r  r>   r>   r?   r@     s    

z&SoundcloudTrackStationIE._real_extractNr4  r>   r>   r>   r?   rZ    s   	rZ  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/recommendedZ
1084577272z!Sexapil - Pingers 5 (Recommended)rJ  1   r8   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)rN  rO  Zrecommendedc              	   C   s   |  |dd\}}| j| | j| |d| jd}|drlt| j dd	dd	 |d D  d
d| 
| j| j| |d   t|d d|dp|| S )NslugrelationzDownloading track infor.  r/  z	 said: %sr%  c                 s   s   | ]}t |d  V  qdS r0  r   r2  r>   r>   r?   rf     s   z4SoundcloudRelatedIE._real_extract.<locals>.<genexpr>Tr   r   rR  r   )r  r  r   r  r   r   r:   r   r!  r`   r9  r   rS  r   r   rT  )r<   r   r]  r^  r(   r>   r>   r?   r@     s    
 z!SoundcloudRelatedIE._real_extractNrV  r>   r>   r>   r?   r[    s4   r[  c                
   @   s>   e Zd ZdZdZdddddddgd	dd
ddgZdd ZdS )SoundcloudPlaylistIEzfhttps?://api(?:-v2)?\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$zsoundcloud:playlistz,https://api.soundcloud.com/playlists/4110309Z4110309z=TILT Brass - Bowery Poetry Club, August '03 [Non-Site SCR 02]z$md5:e4373f7177fe3db292a8552b4ec41bc6zNon-Site RecordsZ33660914r2   )r   r   r    r*   r+   r5   r6   r4   rM  r   r0   Zplaylist_countc                 C   sZ   |  |}|d}i }|d}|r.||d< | j| jd | |d|| jd}| ||S )Nr   r   r9   z
playlists/zDownloading playlistr   )r  r  r   r   r   r+  )r<   r   r  r)  r=   r   r   r>   r>   r?   r@   9  s    



z"SoundcloudPlaylistIE._real_extractNr4  r>   r>   r>   r?   r_  '  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 searchZscsearchzscsearch15:post-avant jazzcorezpost-avant jazzcorerJ     r`  r:  2   c           	   	   k   s   t |d| j| j}||ddd t| j| |}tdD ]r}| j	||d| d| j
d}|dpng D ]0}|rp| j|d	 t fi | j|d
dV  qp|d}|sB qqBd S )Nr=  r   r   r<  zDownloading page zUnable to download API pager.  rC  uriT)r  rD  )minr:   _DEFAULT_RESULTS_PER_PAGE_MAX_RESULTS_PER_PAGEr	  r   r   rE  rF  r   r   r;   rk   rh   r  )	r<   ZendpointZcollection_idr=   r=  Znext_urlr   rH  itemr>   r>   r?   _get_collectionY  s2    

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(  rE  isliceri  float)r<   r=   r   r>   r>   r?   _get_n_resultsr  s    z!SoundcloudSearchIE._get_n_resultsN)rA   rB   rC   r!  ZIE_DESCZ_SEARCH_KEYrE   rg  rf  ri  rn  r>   r>   r>   r?   ra  I  s   	ra  )&r  rE  r   r]   commonr   r   Z
networkingr   Znetworking.exceptionsr   utilsr   r	   r
   r   r   r   r   r   r   r   r   r   Zutils.traversalr   r   rG   rk   r"  r,  r5  rI  rW  rZ  r[  r_  ra  r>   r>   r>   r?   <module>   s0   86  Z  6)05`0"