o
    i1$                     @   s   d dl Z d dl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 dZdZd	eef d
e deef de deef dZG dd deZG dd deZG dd deZdS )    N   )InfoExtractor   )ExtractorErrorOnDemandPagedListint_or_nonejoin_nonemptyparse_qsurljoin)traverse_objz
    _id
    clipImageSource
    clipImageThumb
    clipLink
    clipTitle
    createdDate
    shareId
    user { _id }
    username
    viewsz!
    clipLength
    clipSizeByteszfquery ($id: String!) {
        video: getClip(clipIdentifier: $id) {
            %s %s
        }
    }zfquery ($id: String!) {
        video: getMontage(clipIdentifier: $id) {
            %s
        }
    }zquery ($page: Int!, $user: String!, $game: Int) {
        videos: clips(search: createdDate, page: $page, user: $user, mobile: false, game: $game) {
            data { %s %s }
        }
    }zquery ($page: Int!, $user: String!) {
        videos: montages(search: createdDate, page: $page, user: $user) {
            data { %s }
        }
    }zquery ($page: Int!, $user: String!) {
        videos: clips(search: createdDate, page: $page, user: $user, mobile: true) {
            data { %s %s }
        }
    })clipmontageClipsMontagesMobile Clipsc                   @   s"   e Zd Zedd ZdddZdS )AllstarBaseIEc                 C   s   dd }t | dthfdthfdthfd|hfdd|hifd	thfd
thfdtddhfdthfddthfdthfd}|dr_|dr_d|d v rNdnd}d| d| d|d  |d< |t tjtd|dd |S )Nc                 S   s
   t d| S )Nzhttps://media.allstar.gg/)r
   )path r   L/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/allstar.pymedia_url_or_none?   s   
z:AllstarBaseIE._parse_video_data.<locals>.media_url_or_none_idshareId	clipTitleclipLink)clipImageThumbclipImageSourceurl
clipLengthclipSizeBytescreatedDatei  )scaleusernameuserviews)id
display_idtitler   
thumbnailsdurationfilesize	timestampuploaderuploader_id
view_countr$   z/clips/r   r   zhttps://allstar.gg/?=webpage_urlzhttps://allstar.gg/u/r,   )extractor_key	extractoruploader_url)	r   strr   getupdate	AllstarIEie_keyIE_NAMEr
   )
video_datar   infobasenamer   r   r   _parse_video_data=   s.   
zAllstarBaseIE._parse_video_dataNc              
   C   sX   | j d||ddit||d d}t|dddthf}|r'td	|t||S )
Nzhttps://a1.allstar.gg/graphqlzcontent-typezapplication/json)	variablesquery)noteheadersdataerrors.messagez; )_download_jsonjsondumpsencoder   r4   r   join)selfr?   r>   r   video_idr@   responserC   r   r   r   	_call_api\   s   
zAllstarBaseIE._call_api)NN)__name__
__module____qualname__staticmethodr=   rM   r   r   r   r   r   <   s    
r   c                   @   s   e Zd ZdZdddddddd	d
ddddeddddddddddddddddeddddddd ddd!dddd"ed#dd$d%d&dd'ddd(dddd)ed#dgZd*d+ Zd,S )-r7   zUhttps?://(?:www\.)?allstar\.gg/(?P<type>(?:clip|montage))\?(?P=type)=(?P<id>[^/?#&]+)z5https://allstar.gg/clip?clip=64482c2da9eec30008a67d1b64482c2da9eec30008a67d1bz4K on Infernoz$md5:66befb5381eef0c9456026386c25fa55z.re:https://media\.allstar\.gg/.+\.(?:png|jpg)$zchrk.mp4   iyCi-,Hd62b8bdfc9021052f7905882dz-https://allstar.gg/u/62b8bdfc9021052f7905882d20230425)r$   r&   r   	thumbnailr+   extr(   r)   r*   r,   r3   upload_dater-   )r   	info_dictz&https://allstar.gg/clip?clip=8LJLY4JKB64a1ec6b887f4c0008dc50b8	8LJLY4JKBzAK-47 3K on Miragez$md5:dde224fd12f035c0e2529a4ae34c4283   isrikdcherokee20230702)r$   r%   r&   r   rX   rW   r(   r)   r*   r+   r,   r3   rY   r-   z;https://allstar.gg/montage?montage=643e64089da7e9363e1fa66c643e64089da7e9363e1fa66cAPQLGM2IMXWz#cherokee Rapid Fire Snipers Montagez$md5:a3ee356022115db2b27c81321d195945id>d20230418)r$   r%   r&   r   rW   rX   r*   r+   r,   r3   rY   r-   z-https://allstar.gg/montage?montage=RILJMH6QOS64a2697372ce3703de29e868
RILJMH6QOSz$md5:d5672e6f88579730c2310a80fdbc4030izid20230703c                 C   s6   |  |dd\}}| | t|d|id|S )Ntyper$   )rB   video)_match_valid_urlgroupr=   rM   _QUERIESr5   )rJ   r   query_idrK   r   r   r   _real_extract   s   zAllstarIE._real_extractN)rN   rO   rP   
_VALID_URLint_TESTSrl   r   r   r   r   r7   i   s    Er7   c                   @   sh   e 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gZdZdd Zdd ZdS )AllstarProfileIEzDhttps?://(?:www\.)?allstar\.gg/(?:profile\?user=|u/)(?P<id>[^/?#&]+)z8https://allstar.gg/profile?user=62b8bdfc9021052f7905882dz62b8bdfc9021052f7905882d-clipszcherokee - Clips)r$   r&      )r   rZ   playlist_mincountz1https://allstar.gg/u/cherokee?game=730&view=Clipsz"62b8bdfc9021052f7905882d-clips-730zcherokee - Clips - 730z;https://allstar.gg/u/62b8bdfc9021052f7905882d?view=Montagesz!62b8bdfc9021052f7905882d-montageszcherokee - Montages   z:https://allstar.gg/profile?user=cherokee&view=Mobile Clipsz62b8bdfc9021052f7905882d-mobilezcherokee - Mobile Clipsr   
   c                 c   s@    |d7 }|  ||||dd|d| D ]}| |V  qd S )Nr   )r"   pagegame)rB   videosrB   zDownloading page )rM   r=   )rJ   user_idr%   rv   r?   page_numr:   r   r   r   	_get_page   s   zAllstarProfileIE._get_pagec           	      C   s   |  |}| td||}t|ddthf}|stdt|dddthf}t|}t|ddthf}t|d	d
d}|dvrFtd|| jt	t
| j|||t|| jt||  d |t|pg|||dddS )Nz(https://api.allstar.gg/v1/users/profile/rB   r   zUnable to extract the user idprofiler!   rv   r   )viewr   r   )default)r   r   r   zUnsupported playlist URL type z - )delim)playlist_idplaylist_title)	_match_idrE   r
   r   r4   r   r	   r   playlist_resultr   	functoolspartialrz   rj   r5   
_PAGE_SIZEr   lowersplit)	rJ   r   r%   profile_datarx   r!   	url_queryrv   rk   r   r   r   rl      s.   

zAllstarProfileIE._real_extractN)rN   rO   rP   rm   ro   r   rz   rl   r   r   r   r   rp      s<    rp   )r   rF   commonr   utilsr   r   r   r   r	   r
   utils.traversalr   _FIELDS_EXTRA_FIELDSrj   r   r7   rp   r   r   r   r   <module>   s4     -P