
    uki                        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
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d de      Z$ G d d ee      Z%y)!    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                       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d3 Zy4)5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!   r0   r1      r   r7   playlist_mincountc                     t        |      }|d   d   }|j                  d      }|rt        |d|d   i      }| j                  |      S )Nr   r   secret_token)r   getr   
url_result)selfr   queryapi_urlrD   s        V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/yt_dlp/extractor/soundcloud.py_real_extractzSoundcloudEmbedIE._real_extractG   sM    ,q/yy0&wa0QRGw''    N)	__name__
__module____qualname__
_VALID_URL_EMBED_REGEX_TESTSint_WEBPAGE_TESTSrK    rL   rJ   r   r      sP   XJhiL C F w
,
5
 T
 ()	

 A
 
 |n
 ,
 C
 I
 J
 
 T
 :
 (
  :!
" C#
& #F++. _CC-.$'&	
 -#NJ(rL   r   c                       e Zd ZdZdZdZdZdZdZdZ	i Z
dZ ej                  d	      Zd
dddddddddd
Zg dZej$                  d        Zd Zd Zd Zd Zd Zd Zd Zd Zd"d Zed!        Zy)#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                      t        j                  dj                  t         fd j	                  ddgt
              D                          j                  S )N|c              3      K   | ]a  }|d k7  r%t        j                  |      j                  dd      n2dj                  t	        t         j                  j
                               c yw)defaultz\*z.*rr   N)reescapereplacejoinmap_DEFAULT_FORMATS).0patternrG   s     rJ   	<genexpr>z1SoundcloudBaseIE._is_requested.<locals>.<genexpr>o   s\      (
  9@98LBIIg&&ue4#bii)>)>?@A(
s   A'A*formatsrt   )ie_key)ru   compilerx   set_configuration_argSoundcloudIE	fullmatchrG   s   `rJ   _is_requestedzSoundcloudBaseIE._is_requestedm   sQ    zz$))C (
  229ykR^2_(
 %
   I		rL   c                 >    | j                   j                  dd|       y )NrX   	client_id)cachestore)rG   r   s     rJ   _store_client_idz!SoundcloudBaseIE._store_client_idu   s    

{I>rL   c                    | j                  dd       }t        t        j                  d|            D ]J  }| j                  |d d      }|s| j	                  d|dd       }|s2|| _        | j                  |        y  t        d      )	NrY   z<script[^>]+src="([^"]+)"Ffatalz#client_id\s*:\s*"([0-9a-zA-Z]{32})"z	client idrt   zUnable to extract client id)_download_webpagereversedru   findall_search_regex
_CLIENT_IDr   r	   )rG   webpagesrcscriptr   s        rJ   _update_client_idz"SoundcloudBaseIE._update_client_idx   s    (()BDIBJJ'CWMN 		C++CU+CF ..:K / 7	 &/DO)))4		 :;;rL   c                    |j                  d      du }|r|d= |j                  di       j                         }t        d      D ]*  }| j                  |d<   ||d<   	  | j                  |i |c S  y # t
        $ r}t        |j                  t              r>|j                  j                  dv r&| j                  d        | j                          Y d }~|r | j                  t        |             Y d }~ y d }~ww xY w)Nr   FrH   r   r   )    )rE   copyranger   _download_jsonr	   
isinstancecauser   statusr   r   report_warningstr)rG   argskwargs	non_fatalrH   _es          rJ   	_call_apizSoundcloudBaseIE._call_api   s    JJw'50	w

7B',,.q 	A!%E+#F7O
*t**D;F;;		
 " aggy1aggnn
6R))$/**,''A/ s%   A22	C;;AC6C65C66C;c                 N    | j                   j                  dd      xs d| _        y )NrX   r    a3e059563d7fd3372b49b37f00a00bcf)r   loadr   r   s    rJ   _initialize_pre_loginz&SoundcloudBaseIE._initialize_pre_login   s    **//,DjHjrL   c                 *   | j                  | j                  | j                  | j                  z  z  d ddt	        j
                  dd|ii      j                               r#d| | j                  d<   | j                          y | j                  d       y )	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   rG   tokens     rJ   _verify_oauth_tokenz$SoundcloudBaseIE._verify_oauth_token   s      ++t/L/Lt/^_5UZZ^U,C DELLN ! P 06eW-=DMM/* ^_rL   c                 d      j                   ry t         fd      x}r j                  |       y y )Nc                  T     j                   j                        d   j                  S )Noauth_token)_get_cookies	_BASE_URLvaluer   s   rJ   <lambda>z3SoundcloudBaseIE._real_initialize.<locals>.<lambda>   s!    T%6%6t~~%F}%U%[%[ rL   )r   r   r   r   s   ` rJ   _real_initializez!SoundcloudBaseIE._real_initialize   s2    ==[\\5\$$U+ ]rL   c                     |dk7  r t        d| j                  d       d      | j                  ry | j                  |       y )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   )rG   usernamepasswords      rJ   _perform_loginzSoundcloudBaseIE._perform_login   sZ    w ++9+=>@JNP P ==  *	rL   c           
      l   d}d}d}d}d}d}	d}
d}d}d	}d
}d}|}|}dj                  ||||||	|
|fD cg c]  }t        |       c}      }||z   |z   |z   |z   |z   |z   |z   }d}t        t        |            D ]&  }|dz	  d|z  dz  z   }|t	        ||         z  }|dz  }( | d| d|dd| S c c}w )N!   r   i; u   i@w i  %       0763ed7314c69015fd4a0dc16bbf4b908rZ   -i>z    i :x)rx   r   r   lenord)rG   userpwclidaiswulbkcnyrr   tmIntdhmfs                          rJ   signzSoundcloudBaseIE.sign   s   . BHHQ1aAq!,DEDc$iEFEAIMA!A%)s1v 	AaQUrM*AQqTNAMA	 AaS!Aas## Fs   B1Nc                 @  $ t        d         }t               $g }d}d| j                  i}|r||d<   |sj                  d      rىj                  d      r	 | j	                  | j
                   d| d|d	|| j                  
      }	t!        |	dt"        hf      x}r| j%                  t'        |      |ddd      }|ra|j(                  }$j+                  |       |j-                  dt/        |      t1        |j2                  j                  d            |dddd       $fd}t!        ddd f      D ]7  }|r n2|d   }|d   }|j5                  d      d    }t!        |d!d"t         hf      xs d#}|j7                  d$      rd%}S|d&k(  rd#}|d'k7  rd(|v rd'}|d)k(  sd*|v rd+}| d| }|d,k(  r| j                  d-| d.       | j9                  |      s| j                  d/| d0       t!        | j;                  ||d1| d2|| j                  
      dt"        hf      } ||      r$j+                  |       t!        |d!d3t         hf      }| j=                  d4|d5d 6      }d7d8d9j                  |r|d d: nd       xs t?        |d 6      }|r|d;k(  r|}|j                  d<      d=k(  }t1        | j=                  d>|d,d 6      xs! | j=                  d?|d,d 6      xs
 |rd@|v rdAnd       }|j                  dB      xs dC|v xs tA        jB                  dD|      }|j-                  tE        |||xr dEdF      |||d||dGv rdHnd#|d7k(  rdInd |rdJn
|r|dKk\  rd ndL|rdMnd |rdNnd dO       : |s9|r| jG                  |       j                  dP      dQk(  r| jI                  d%R       j                  dS      xs i }g }j                  dT      }|xs |j                  dU      }t#        |      rtA        jB                  | jJ                  |      x}r| jL                  jO                         D ]  \  } }!| dVk(  r|jQ                  dW      ndX}| tA        jR                  | jJ                  dY|  dZ| |      d[}"| d\k(  r|sd]}!n
| dVk(  rd|"d^<   |!r|"jU                  |!|!d_       |j-                  |"        nd|ig}fd`}#i d|da|j                  db      dctW        |j                  d            xs |j                  dd      de|j                  df      dgtY        j                  dh            dij                  di      djj                  di      dkj                  dk      dl|dmt[        j                  dm      dn      doj                  df      dpj                  dp      dq |#dr      ds |#dt      xs  |#du      dv |#dw      dx |#dy      dzt!        d{t         ht\        t^        t\        f      t!        d|| j`                  jb                  hd}d}t\        f      t!        d~dt         ht\        t^        t\        f      |s|dS d dS # t        $ r}
t        |
j                  t              r<|
j                  j                  dk(  r#| j                  d| j                                 n`t        |
j                  t              r+|
j                  j                  dk(  r| j                  d       n| j                  |
j                         d }	Y d }
~
d }
~
ww xY w)Nr   Fr   rD   downloadablehas_downloads_lefttracks/z	/downloadz.Downloading original download format info JSONrH   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                     |  xs | v S NrU   )r   format_urlss    rJ   invalid_urlz8SoundcloudBaseIE._extract_info_dict.<locals>.invalid_url!  s    70c[00rL   mediatranscodingsc                 ,    t        |d         xr |d   S )Nr   preset)r   )r   vs     rJ   r   z5SoundcloudBaseIE._extract_info_dict.<locals>.<lambda>%  s    ;WXY^W_K`Kpefgoep rL   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     r5   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_urlrj   r   jpgr   .r   r   rb      r'  )widthheightc                 >    t        j                  |  d            S )N_count)r   rE   )keyinfos    rJ   extract_countz:SoundcloudBaseIE._extract_info_dict.<locals>.extract_count  s    txx3%v788rL   r0   r   r1   	permalinkr3   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    r~   )2r   r   r   rE   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   ru   searchr   
report_drmraise_geo_restricted_IMAGE_REPL_RE_ARTWORK_MAPitemsgroupsubupdater   r   r
   filterall_TAGS_REr   )%rG   r6  
full_titlerD   extract_flattrack_idr~   has_drmrH   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   r7  r  s%    `                                  @rJ   _extract_info_dictz#SoundcloudBaseIE._extract_info_dict   s   tDz?edoo.$0E.! 8TXXFZ=[% $ 3 3(()
)DhDE[_[h[h !4 !j  ,MMK=;YZZ|Z,,-x9i?u - N !%JOOJ/NN%/3D9$/0@0@AQ0R$S)#%'1"($ 	1 dWn>p$qr A	A5Jx[F **3/2K#A*se'DEOH""#34=(!5 Vz%9 ?*.>*.L$"*1[M:e#  #45E4Fh!OP%%&67  1%5$66[!\] &dnnH5E4FFW&XT]] '5 '46;k]5KMJ :&OOJ'$Q;(FGI&&':IwX\&]E cu%)$/Y 4@	SW3X  #-!y)T1J"":vud"K G%%&BJPU_c%dG&5F?CHC
 %%	* S(J6SYY'EzR  NN*8VZ=UI]`a! -59K-KMQW+.%<ZT *1ccSjr,6yD%/cT kA	F )xx!W,))T)Bxx%2
hh}-9488L#9	y!yy!4!4i@@t@&*&7&7&=&=&? )NHd/7:/E$**U+5C&!vvd&9&9Qxj#;OQZ[A  6)+!!Z/*,,%)&*"  %%a(!)$  %i01
	9
(
,
 ;txx~6O$((;:O
 DHH_5	

 *488L+AB
 TXXg&
 TXXg&
 488M2
 *
 dhhz&:DA
 488O4
 txx	*
 -
3
 -6P-:P
 ]95
  M)4!
" l4'C5&#v)NO#
$ !
T]]5J5J4KSRUW]'^_#D+?C5RXZ]_e*fg&2w)
 	
( 9=)
 	
O " 	%aggy1aggnn6K''1151A1A1C0DFG  3#8M$$%`a''. $	%s   0Y 	\B8\\c                 &    | j                   dz   |z   S )Nzresolve?url=)rI  )clsr   s     rJ   _resolv_urlzSoundcloudBaseIE._resolv_url  s    .0366rL   )NNF)rM   rN   rO   _NETRC_MACHINErI  r   _USER_AGENTr   _API_AUTH_URL_PWr   r   rS  ru   r   r[  rT  rz   	functoolscached_propertyr   r   r   r   r   r   r   r   r   rl  classmethodro  rU   rL   rJ   rW   rW   P   s    !N3L)I HK.TPH4Nrzz./H L _ ?<(k`,(V$:l
\ 7 7rL   rW   c                      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d Zy)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>[^&]+))?)
                    )
                    rX   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:7b6074e00887ad79f59b647c8fb6d5aer0   zE.T. ExTerrestrial Musicr1   1571244r,   iV'vPr.   20121011r"   gxa@r%   r&   r=  r?  rB  r'   r*   r+   r3   zhttps://soundcloud.com/ethmusicr(   zcount:14)r   md5r7   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   r7   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   r{  r7   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(   r4   r5   )r   r{  r7   r8   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)r3   r(   z*https://soundcloud.com/skorxh/audio-dealer
2011421339zaudio dealerz$KORCH	150292288zhttps://soundcloud.com/skorxhg^Ij@r    z$KORXHig20250117ra   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-mini.jpgr/  rb   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-tiny.jpgrc   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-small.jpgrd   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-badge.jpgre   zAhttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t67x67.jpgrf   z@https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-large.jpgrg   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t300x300.jpgrh   z?https://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-crop.jpgri   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-t500x500.jpgrj   zChttps://i1.sndcdn.com/artworks-a1wKGMYNreDLTMrT-fGjRiw-original.png)r%   r*   r;  hls_aac_160k)r4   r  r6   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                    | j                  |      }|j                  d      }i }|r-| j                  dz   |z   }|}|j                  d      }|r`||d<   nZ dj                  |j                  dd       x}}|j                  d      }|r|d| z  }| j	                  | j
                  |z         }| j                  ||d	|| j                  
      }	| j                         D ]  }
	 | j                  |	||      c S  y # t        $ rb}t        |j                  t              r|j                  j                  dk7  r | j                  dd       |j                  |
_        Y d }~d }~ww xY w)Nr^  r   rD   z{}/{}r0   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_urlrV  rI  r  ro  r   r   r   RetryManagerrl  r	   r   r   r   r   r   error)rG   r   ri  r^  rH   info_json_urlr\  r   resolve_titler6  retryr   s               rJ   rK   zSoundcloudIE._real_extract  sq   $$S)::j) --	9HDM!JJJ~.E(-n%)7JPW9X)YYJJJw'E1UG, ,,T^^m-KLM~~:'>eUYUbUb  d &&( 
	&E	&..tZGG
	& " &!!''9539N##LW[ $ ]  gg&s   "C99	E$AEE$N)	rM   rN   rO   __doc__rP   IE_NAMErS   rR   rK   rU   rL   rJ   r   r     sJ	   	J GJ1
*
6
 \
 \	

 A
 2
 9
 
 :
 
 ,
 #
 #
 S
 C
  J!
" =#
$ J%
2 {
*
6
 \
 \	

 A
 +
 9
 
 :
 
 ,
 #
 #
 S
 C
  E!
" J#
$ %o+,)
6 V1
+
5
 :
 :	

 A
 	
 :
 
 :
 
 ,
 #
 #
 S
 C
  <!
" J#
$ #m'
	6 R1
+
5
 :
 :	

 A
 	
 :
 
 :
 
 ,
 #
 #
 S
 C
  <!
" J#
$ #m'
	6 =1
+
6
 _
 _	

 2
 
 ;
 ;
 :
 
 
 J
 ,
 #
 S
  C!
" ##
$ %ow)
, ``5< T1
+
6
 f
 f	

 A
 *
 :
 
 :
 
 ,
 #
 #
 S
 C
  J!
" >#
$  j$~)
, ``7< G1
+
5
 0
 0	

 A
 	
 9
 
 :
 
 J
 ,
 #
 #
 S
  C!
" <#
$ "{'
* #F+36 D1
+
5
 ^
 ^	

 A
 )
 9
 
 :
 
 J
 ,
 #
 #
 S
  C!
" wi#
$ D'
* #F+16 < 
, 
5 
 ^ 
 2	 

  
 ; 
 ; 
 S 
 # 
 # 
 C 
  
 B 
 z 
 ^ 
  ! 
" :# 
$ -J&gh&gh'ij'ij(kl'ij!*op&gh!*op!*op) 
B %+nEI%N c U
 Ts|F| &rL   r   c                       e Zd ZddZy)SoundcloudPlaylistBaseIENc                 @   t        |d         }|j                  d      xs g }t        d |D              s\|rZ| j                  | j                  dz   |ddj                  |D cg c]  }t        |d          c}      ||d| j                        }t        |dt         hfd	d
t         hfdt         hd hfd      }g }|D ]  }t        |j                  d            }	|j                  d      }
|
s|	s3| j                  dz   |	z   }
|r|
d|z   z  }
|j                   | j                  |
t        j                         |	fddi|         | j                  |||j                  d      |j                  d      fi |t        |d	d
t         hfd	dt        hfd      S c c}w )Nr   tracksc              3   >   K   | ]  }|j                  d         yw)r9  N)rE   )r{   r   s     rJ   r}   z8SoundcloudPlaylistBaseIE._extract_set.<locals>.<genexpr>  s     :a155):s   zDownloading tracks,)ids
playlistIdplaylistSecretTokenr   r   r   r   set_typec                     | xs dS )Nr:   rU   )r   s    rJ   r   z7SoundcloudPlaylistBaseIE._extract_set.<locals>.<lambda>  s
    j rL   )r=   album_artistr?   r9  r   z?secret_token=url_transparentTr!   )r0   r1   )r   rE   rZ  r   rI  rx   r   r   r   rM  rF   r   r   playlist_result)rG   r:   r   playlist_idr  r   
album_infoentriesr-   r^  r   s              rJ   _extract_setz%SoundcloudPlaylistBaseIE._extract_set  s   (4.)h'-2:6::u^^!!H,k$886$BaS4\$BC"-+0-  == $ *F "(u%#Z#7%u/H.IJ-
 

  
	[E"599T?3H))O,C'')3h>+e33CNN?4??\((*HZFJZNXZ [
	[ $t##[LL!LL'	
 		

 8#Z#7 &{m<& 	
 		
+ %Cs   "Fr  )rM   rN   rO   r  rU   rL   rJ   r  r    s    %
rL   r  c            
       \    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 Zy)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:71d07087c7a449e8941a70a29e34671er~  r  ep)r   r   r!   r0   r1   r=   r>   r?   r   rA   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                    | j                  |      } dj                  |j                  dd       }|j                  d      }|r|d|z   z  }| j                  | j	                  | j
                  |z         || j                        }d|v r5d |d   D        }t        d	j                  d
j                  |                  | j                  ||      S )Nz
{}/sets/{}r0   
slug_titler   r  r   errorsc              3   8   K   | ]  }t        |d            ywerror_messageNr   r{   errs     rJ   r}   z0SoundcloudSetIE._real_extract.<locals>.<genexpr>2  s     H#CO,-H   z$unable to download video webpage: {}r  )
r  r  rV  r   ro  r   r   r	   rx   r  )rG   r   ri  r\  r   r6  msgss          rJ   rK   zSoundcloudSetIE._real_extract&  s    $$S)(\(($**Z*NO


7##+%J~~d..NNZ')*4dmm  M tHhHD !G!N!NsxxX\~!^__  u--rL   NrM   rN   rO   rP   r  rR   rK   rU   rL   rJ   r  r    s     JJGR+A+$+12	
  Y H N N-F6.rL   r  c                       e Zd Zd Zd Zy)SoundcloudPagedPlaylistBaseIEc                 0    d||| j                  ||      dS )Nr:   )_typer   r   r  )_entries)rG   base_urlr  playlist_titles       rJ   _extract_playlistz/SoundcloudPagedPlaylistBaseIE._extract_playlist9  s#    #}}X{;	
 	
rL   c              #   0   K   dddd}t        j                         D ]  } j                         D ]*  }	  j                  ||| j                  d|dz          } n  fd	}d
   xs g D ],  } |||j                  d      |j                  d             . |j                  d      }|s y |j                  dd         y # t
        $ rE}t        |j                  t              r|j                  j                  dk7  r ||_
        Y d }~d }~ww xY ww)N   1r   limitlinked_partitioningoffsetzDownloading track page r   )rH   r   r   i  c            
      :   | D ]  }t        |t              st        |j                  d            }|s1j	                  |t
        j                  |      rt
        j                         nd t        |j                  d            |j                  d            c S  y )Nr9  r   r   )	r   dictr   rE   rF   r   suitabler   r   )
candidatescandr9  rG   s      rJ   resolve_entryz=SoundcloudPagedPlaylistBaseIE._entries.<locals>.resolve_entryY  s    & LD%dD1 $/0I$JM$#)5A5J5J=5YL//1_c'7'9J L LLrL   
collectionr-   r:   	next_hrefr  )	itertoolscountr  r   r   r	   r   r   r   r   r  rE   pop)	rG   r   r  rH   r   r  responser   r  s	   `        rJ   r  z&SoundcloudPagedPlaylistBaseIE._entriesA  s'     #&
 "  	&A**, #~~[t}}6q1ug>  .  @H 	L l+1r J#AquuW~quuZ7HIIJ ,,{+CIIh%A 	& &  &aggy9QWW^^s=R"#EKs/   1D&CA*D	D;D	DDDN)rM   rN   rO   r  r  rU   rL   rJ   r  r  8  s    
)&rL   r  c                       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* Zy+),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      rA   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)rZ  r  albumssetsrD  rA  	spotlightcommentsc           	         | j                  |      }|j                  d      }| j                  | j                  | j                  |z         |d| j
                        }|j                  d      xs d}| j                  | j                  | j                  |   |d   z  z   t        |j                  d            dj                  |d   |j                                     S )	Nr   Downloading user infor  rsrcrZ  r   {} ({})r   )r  rV  r   ro  r   r   r  rI  _BASE_URL_MAPr   rE   r  
capitalize)rG   r   ri  r0   r   resources         rJ   rK   zSoundcloudUserIE._real_extract  s    $$S)::f%~~T^^h67-t}}  F ::f%.%% 2 28 <tDz II'T*-x/B/B/DEG 	GrL   NrM   rN   rO   rP   r  rR   r  rK   rU   rL   rJ   r  r  m  s   J  G:&
   B)
   B)
  4(
  7+
  7'
  <,
  F1
 c8Fv !##$,!)'	MGrL   r  c                   .    e Zd ZdZdZddddddgZd	 Zy
)SoundcloudUserPermalinkIEz/https?://api\.soundcloud\.com/users/(?P<id>\d+)zsoundcloud:user:permalinkz)https://api.soundcloud.com/users/3090986930909869neilcicr     rA   c                    | j                  |      }| j                  | j                  |      |d| j                        }| j	                  | j
                   d|d    dt        |d         |j                  d            S )Nr  r  zusers/r   z/tracksr   )	_match_idr   ro  r   r  rI  r   rE   )rG   r   user_idr   s       rJ   rK   z'SoundcloudUserPermalinkIE._real_extract  s    ..%~~S!7,CT]]  \ %%  !T
|7;Sd_dhhWaNbd 	drL   Nr  rU   rL   rJ   r  r    s1    CJ)G:
   FdrL   r  c                   .    e Zd ZdZdZddddddgZd	 Zy
)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  r^   rA   c                 2   | j                  |      }| j                  | j                  |      || j                        }| j	                  d|d   d      }| j                  | j                  dj                  |d         z   |dj                  |d               S )Nr  zsoundcloud:track-stations:(\d+)r   ztrack idzstations/{}/trackszTrack station: {}r   )r	  r   ro  r   r   r  rI  r  )rG   r   
track_namer-   r^  s        rJ   rK   z&SoundcloudTrackStationIE._real_extract  s    ^^C(
t//4j$--X%%.dZI %% 4 ; ;E$K HH)00w@B 	BrL   Nr  rU   rL   rJ   r  r    s1    bJ'GP/
   F	BrL   r  c                   Z    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 Zy)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   rA   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           	      .   | j                  |      j                  dd      \  }}| j                  | j                  | j                  |z         |d| j
                        }|j                  d      r6t        | j                   ddj                  d |d   D              z  d	
      | j                  | j                  | j                  |   |d   z  z   t        |d         dj                  |j                  d      xs ||j                                     S )NslugrelationzDownloading track infor  r  z	 said: %sr  c              3   8   K   | ]  }t        |d            ywr  r  r  s     rJ   r}   z4SoundcloudRelatedIE._real_extract.<locals>.<genexpr>"  s#      GF.1C()GFr  Tr   r   r  r   )r  rV  r   ro  r   r   rE   r	   r  rx   r  rI  r  r   r  r   )rG   r   r  r  r-   s        rJ   rK   z!SoundcloudRelatedIE._real_extract  s   ..s399&*MhT^^d23*DMM  C 99X DLL>!;chh GF5:8_GF ?F "FPTV V %% 2 28 <uT{ JJCPUVZP[L\UYYw/749L9L9NOQ 	QrL   Nr  rU   rL   rJ   r  r    sy    ~J"GL8
   H3
  F1
 F0 %4*MQrL   r  c            
       L    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 Zy)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33660914r:   )r   r   r!   r0   r1   r>   r?   r=   r  r   r7   playlist_countzHhttps://api.soundcloud.com/playlists/soundcloud%3Aplaylists%3A1759227795Tr   z_https://api.soundcloud.com/playlists/soundcloud:playlists:2104769627?secret_token=s-wmpCLuExeYXc                     | j                  |      }|j                  d      }i }|j                  d      }|r||d<   | j                  | j                  dz   |z   |d|| j                        }| j                  ||      S )Nr   r   rD   z
playlists/zDownloading playlistr   )r  rV  r   rI  r   r  )rG   r   ri  r  rH   r   r   s          rJ   rK   z"SoundcloudPlaylistIE._real_extractB  s    $$S)jj&

7#$)E.!~~,{:/udmm  U   u--rL   Nr  rU   rL   rJ   r  r  *  sd     eJ#G=UA*%01$U	
  Z q!F*.rL   r  c                   @    e Zd ZdZdZdZddddddgZd	Zd
Zd Z	d Z
y)SoundcloudSearchIEzsoundcloud:searchzSoundcloud searchscsearchzscsearch15:post-avant jazzcorezpost-avant jazzcorer     r  r  2   c           
   +     K   t        |j                  d| j                        | j                        }|j	                  |ddd       t        | j                  |z   |      }t        j                  d      D ]  }| j                  ||d| d| j                        }|j                  d      xs g D ]A  }|s | j                  |d	   t        j                         fi | j                  |d
       C |j                  d      }|r y  y w)Nr  r   r   r  zDownloading page zUnable to download API pager  r  uriT)r]  r  )minrE   _DEFAULT_RESULTS_PER_PAGE_MAX_RESULTS_PER_PAGErX  r   rI  r  r  r   r   rF   r   r   rl  )	rG   endpointcollection_idrH   r  next_urlr   r  items	            rJ   _get_collectionz"SoundcloudSearchIE._get_collectionb  s"    IIgt==>&&( 	#$
 	
 $D$5$5$@%H# 	A~~-+<QC)@-t}} & FH !\28b p)$//U\%8%8%:p>B>U>UVZim>U>np pp
  ||K0H	s   B4D7AD	Dc           
          | j                  t        j                  | j                  d|||      d|t	        d      k(  rd n|      ||      S )Nzsearch/tracks)r  qr   inf)r  r  islicer.  float)rG   rH   r   s      rJ   _get_n_resultsz!SoundcloudSearchIE._get_n_results{  sR    ##I$4$4  %qE JqE%L(ta%127@ 	@rL   N)rM   rN   rO   r  IE_DESC_SEARCH_KEYrR   r)  r(  r.  r4  rU   rL   rJ   r!  r!  R  sI    !G!GK/'*
  F   "2@rL   r!  )&rs  r  r   ru   commonr   r   
networkingr   networking.exceptionsr   utilsr	   r
   r   r   r   r   r   r   r   r   r   r   utils.traversalr   r   rW   r   r  r  r  r  r  r  r  r  r!  rU   rL   rJ   <module>r<     s       	 6 $ -    +3( 3(lU7} U7p
t&# t&n	&
/ &
R-.. -.`2&$4 2&j]G4 ]G@d = d*B< B0-Q7 -Q`%.3 %.P,@)+> ,@rL   