a
    h1                     @   s   d dl Z d dlZd dl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 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dS )    N   )InfoExtractor   )
compat_ord)ExtractorErrorint_or_noneparse_iso8601strip_or_nonetry_geturl_or_none)traverse_objc                   @   s   e Zd ZdddZdS )MixcloudBaseIENc              
   C   s@   |d }| j d|dd|||r(d| dnd|f idd	 | S )
NZLookupz https://app.mixcloud.com/graphqlqueryz1{
  %s(lookup: {username: "%s"%s}) {
    %s
  }
}z	, slug: "" )r   data)Z_download_json)selfZobject_typeZobject_fieldsZ
display_idusernameslugZ
lookup_key r   N/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/extractor/mixcloud.py	_call_api   s    zMixcloudBaseIE._call_api)N)__name__
__module____qualname__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	ed
ddddddgeeeedddidddddddddedddd g d!eeed"dd#idd$d%d&gZd'Ze	d(d) Z
d*d+ Zd,S )-
MixcloudIEzihttps?://(?:(?:www|beta|m)\.)?mixcloud\.com/([^/]+)/(?!stream|uploads|favorites|listens|playlists)([^/]+)Zmixcloudz-http://www.mixcloud.com/dholbach/cryptkeeper/Zdholbach_cryptkeeperZm4aZCryptkeeperzvAfter quite a long silence from myself, finally another Drum'n'Bass mix with my favourite current dance floor bangers.Zdholbachzre:https?://.*\.jpgiXNZ20111115z"https://www.mixcloud.com/dholbach/zPSubmorphics & Chino , Telekinesis, Porter Robinson, Enei, Breakage ft Jess Millsi  zliquid drum and basszdrum and bass)idexttitledescriptionuploaderuploader_id	thumbnail
view_count	timestampupload_dateuploader_urlZartistdurationtagscomment_countrepost_count
like_countartistsZskip_downloadZm3u8)url	info_dictparamszEhttp://www.mixcloud.com/gillespeterson/caribou-7-inch-vinyl-mix-chat/z,gillespeterson_caribou-7-inch-vinyl-mix-chatZmp3zCaribou 7 inch Vinyl Mix & Chatz$md5:2b8aec6adce69f9d41724647c65875e8zGilles Peterson WorldwideZgillespetersonzre:https?://.*i1TZ20150203z(https://www.mixcloud.com/gillespeterson/i  )ZjazzZsoulzworld musicZfunk)r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   z404 playback error on sitezOhttps://beta.mixcloud.com/RedLightRadio/nosedrip-15-red-light-radio-01-18-2016/T)r-   Zonly_matchingZ5IFYOUWANTTHEARTISTSTOGETPAIDDONOTDOWNLOADFROMMIXCLOUDc                 C   s    d dd t|t| D S )zDEncrypt/Decrypt XOR cipher. Both ways are possible because it's XOR.r   c                 S   s$   g | ]\}}t t|t|A qS r   )chrr   ).0chkr   r   r   
<listcomp>X   s   z2MixcloudIE._decrypt_xor_cipher.<locals>.<listcomp>)joinzip	itertoolscycle)keyZ
ciphertextr   r   r   _decrypt_xor_cipherU   s    
zMixcloudIE._decrypt_xor_cipherc                 C   sx  |  | \}}tj|tj| }}| d| }| dd|||}|s\tddd|d}|dkr|td	ddn&|d
krtdddn|rtddd|d }g }dD ]}	||	}
|
sq| | j	t
|
}|	dkr|| j||ddddd q|	dkr&|| j||ddd q|d|dddid q|s^|dr^| jdd g }t|dd d!d"thfD ]T}t|d#}|sqx|d$|it|d%d&thfd%d'thfd(thfd) qx|||d*t|d+thfd,thfd-d.thfd/thfd0thfd1d&thfd1d'thfd1d.thfd2thfd3d4thfd5d4thfdd4thfd6d!d7d+thtttfd8d!thtttfd9S ):N_	cloudcasta  audioLength
    comments(first: 100) {
      edges {
        node {
          comment
          created
          user {
            displayName
            username
          }
        }
      }
      totalCount
    }
    description
    favorites {
      totalCount
    }
    featuringArtistList
    isExclusive
    name
    owner {
      displayName
      url
      username
    }
    picture(width: 1024, height: 1024) {
        url
    }
    plays
    publishDate
    reposts {
      totalCount
    }
    streamInfo {
      dashUrl
      hlsUrl
      url
    }
    tags {
      tag {
        name
      }
    }
    restrictedReason
    idzTrack not foundT)expectedZrestrictedReasonZ	tracklistz?Track unavailable in your country due to licensing restrictionsZrepeat_playz/You have reached your play limit for this trackzTrack is restrictedZ
streamInfo)r-   hlsUrldashUrlr>   Zmp4Zm3u8_nativeZhlsF)Zentry_protocolZm3u8_idfatalr?   Zdash)Zmpd_idr@   httpnoneZhttp_chunk_sizei  P )Z	format_idr-   ZvcodecZdownloader_optionsZisExclusive)Zmetadata_availablecommentsedges.nodecommenttextuserdisplayNamer   created)authorZ	author_idr$   )r   formatsrC   namer   Zpicturer-   ZpublishDateZaudioLengthownerZplaysZ	favoritesZ
totalCountZrepostsr(   tagZfeaturingArtistList)r   r   r"   r$   r'   r    r!   r&   r#   r+   r*   r)   r(   r,   )_match_valid_urlgroupsurllibparseunquoter   r   getr:   _DECRYPTION_KEYbase64	b64decodeextendZ_extract_m3u8_formatsZ_extract_mpd_formatsappendZraise_login_requiredr   dictr	   strr   r   r   filterall)r   r-   r   r   Ztrack_idr<   reasonZstream_inforL   Zurl_keyZ
format_urlZ	decryptedrC   rE   rG   r   r   r   _real_extract\   s    -/


















zMixcloudIE._real_extractN)r   r   r   
_VALID_URLIE_NAMEintlist_TESTSrV   staticmethodr:   r`   r   r   r   r   r      sh   0
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )MixcloudPlaylistBaseIEc                 C   s   |S Nr   r   rE   r   r   r   _get_cloudcast   s    z%MixcloudPlaylistBaseIE._get_cloudcastc                 C   s   |S rh   r   r   r   r   r   r   r   _get_playlist_title   s    z*MixcloudPlaylistBaseIE._get_playlist_titlec              	   C   sz  |  | \}}tj|}|s(d}ntj|}| d| }| jdk}|rTdn|}d}d}g }	|rT| | jd| j| j||| j	f |||r|nd }
|

|pi }|
dg D ]~}| |
d	pi }|
d
}|sqt|dd t}t|dd t}|r|r| d| nd }|	| |t | q|d }|d }d|d }qd| |	|| |
| j ||

| jS )NZuploadsr;   playlistitemsr   Tz%s
    %s
    %s(first: 100%s) {
      edges {
        node {
          %s
        }
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }rD   rE   r-   c                 S   s   | d S )Nr   r   xr   r   r   <lambda>      z6MixcloudPlaylistBaseIE._real_extract.<locals>.<lambda>c                 S   s   | d d S )NrN   r   r   ro   r   r   r   rq     rr   ZpageInfoZhasNextPagez, after: "{}"Z	endCursor)rP   rQ   rR   rS   rT   
_ROOT_TYPEr   
_TITLE_KEY_DESCRIPTION_KEY_NODE_TEMPLATErU   rj   r
   r\   rZ   Z
url_resultr   Zie_keyformatZplaylist_resultrl   )r   r-   r   r   Zplaylist_idZis_playlist_typeZplaylist_typeZlist_filterZhas_next_pageentriesrm   rn   Zedger<   Zcloudcast_urlZ	item_slugZowner_usernameZvideo_idZ	page_infor   r   r   r`      sL    



z$MixcloudPlaylistBaseIE._real_extractN)r   r   r   rj   rl   r`   r   r   r   r   rg      s   rg   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	gZdZdZdZdZ	dd  Z
d!S )"MixcloudUserIEz]https?://(?:www\.)?mixcloud\.com/(?P<id>[^/]+)/(?P<type>uploads|favorites|listens|stream)?/?$zmixcloud:userz!http://www.mixcloud.com/dholbach/Zdholbach_uploadszdholbach (uploads)z$md5:a3f468a60ac8c3e1f8616380fc469b2b)r   r   r   $   r-   r.   playlist_mincountz)http://www.mixcloud.com/dholbach/uploads/z+http://www.mixcloud.com/dholbach/favorites/Zdholbach_favoriteszdholbach (favorites)i  z)http://www.mixcloud.com/dholbach/listens/Zdholbach_listenszDaniel Holbach (listens)z$md5:b60d776f0bab534c5dabe0a34e47a789iW  z
Large list)r-   r.   r|   skipz)https://www.mixcloud.com/FirstEar/stream/ZFirstEar_streamzFirst Ear (stream)zwe maraud for earsi  rI   ZbiogrH   z/slug
          url
          owner { username }c                 C   s   | d| dS )Nz ()r   rk   r   r   r   rl   W  s    z"MixcloudUserIE._get_playlist_titleN)r   r   r   ra   rb   re   rt   ru   rs   rv   rl   r   r   r   r   ry     sX   		1ry   c                   @   s@   e Zd ZdZdZddddddgZd	Zd
ZdZdZ	dd Z
dS )MixcloudPlaylistIEzQhttps?://(?:www\.)?mixcloud\.com/(?P<user>[^/]+)/playlists/(?P<playlist>[^/]+)/?$zmixcloud:playlistzBhttps://www.mixcloud.com/maxvibes/playlists/jazzcat-on-ness-radio/zmaxvibes_jazzcat-on-ness-radiozNess Radio sessions)r   r   :   r{   rM   r   rm   zWcloudcast {
            slug
            url
            owner { username }
          }c                 C   s   | dpi S )Nr<   )rU   ri   r   r   r   rj   p  s    z!MixcloudPlaylistIE._get_cloudcastN)r   r   r   ra   rb   re   rt   ru   rs   rv   rj   r   r   r   r   r   [  s   r   )rW   r7   urllib.parserR   commonr   compatr   utilsr   r   r   r	   r
   r   Zutils.traversalr   r   r   rg   ry   r   r   r   r   r   <module>   s     @=@