U
    gD$                     @   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jtddhfdthfddthfdthfd}|dr|drd|d krd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   </tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/allstar.pymedia_url_or_none?   s    z:AllstarBaseIE._parse_video_data.<locals>.media_url_or_none_idZshareIdZ	clipTitleZclipLink)ZclipImageThumbZclipImageSourceurlZ
clipLengthZclipSizeBytesZcreatedDatei  )ZscaleusernameuserZviews)id
display_idtitler   Z
thumbnailsdurationfilesize	timestampuploaderuploader_id
view_countr   z/clips/r   r   zhttps://allstar.gg/?=Zwebpage_urlzhttps://allstar.gg/u/r!   )Zextractor_keyZ	extractoruploader_url)r   strr   	functoolspartialgetupdate	AllstarIEZie_keyZ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}|rNt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   r&   r   join)selfr1   r0   r   video_idr2   responser5   r   r   r   	_call_api\   s      zAllstarBaseIE._call_api)NN)__name__
__module____qualname__staticmethodr/   r?   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 )-r+   zUhttps?://(?:www\.)?allstar\.gg/(?P<type>(?:clip|montage))\?(?P=type)=(?P<id>[^/?#&]+)z5https://allstar.gg/clip?clip=64482c2da9eec30008a67d1bZ64482c2da9eec30008a67d1bz4K on Infernoz$md5:66befb5381eef0c9456026386c25fa55z.re:https://media\.allstar\.gg/.+\.(?:png|jpg)$zchrk.Zmp4   iyCi-,HdZ62b8bdfc9021052f7905882dz-https://allstar.gg/u/62b8bdfc9021052f7905882dZ20230425)r   r   r   	thumbnailr    extr   r   r   r!   r%   upload_dater"   )r   	info_dictz&https://allstar.gg/clip?clip=8LJLY4JKBZ64a1ec6b887f4c0008dc50b8Z	8LJLY4JKBzAK-47 3K on Miragez$md5:dde224fd12f035c0e2529a4ae34c4283   isrikdZcherokeeZ20230702)r   r   r   r   rF   rE   r   r   r   r    r!   r%   rG   r"   z;https://allstar.gg/montage?montage=643e64089da7e9363e1fa66cZ643e64089da7e9363e1fa66cZAPQLGM2IMXWz#cherokee Rapid Fire Snipers Montagez$md5:a3ee356022115db2b27c81321d195945id>dZ20230418)r   r   r   r   rE   rF   r   r    r!   r%   rG   r"   z-https://allstar.gg/montage?montage=RILJMH6QOSZ64a2697372ce3703de29e868Z
RILJMH6QOSz$md5:d5672e6f88579730c2310a80fdbc4030izidZ20230703c                 C   s6   |  |dd\}}| | t|d|id|S )Ntyper   )r4   video)Z_match_valid_urlgroupr/   r?   _QUERIESr)   )r<   r   query_idr=   r   r   r   _real_extract   s       zAllstarIE._real_extractN)r@   rA   rB   
_VALID_URLint_TESTSrO   r   r   r   r   r+   i   s   Er+   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   rH   Z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)r4   Zvideosr4   zDownloading page )r?   r/   )r<   user_idr   rX   r1   Z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krtd|| jt	t
| j|||t|| jt||  d |t|p|||dddS )Nz(https://api.allstar.gg/v1/users/profile/r4   r   zUnable to extract the user idZprofiler   rX   r   )viewr   r   )default)r   r   r   zUnsupported playlist URL type z - )delim)Zplaylist_idZplaylist_title)Z	_match_idr7   r
   r   r&   r   r	   r   Zplaylist_resultr   r'   r(   rZ   rM   r)   
_PAGE_SIZEr   lowersplit)	r<   r   r   Zprofile_datarY   r   Z	url_queryrX   rN   r   r   r   rO      s8    
     zAllstarProfileIE._real_extractN)r@   rA   rB   rP   rR   r^   rZ   rO   r   r   r   r   rS      s:   rS   )r'   r8   commonr   utilsr   r   r   r   r	   r
   Zutils.traversalr   Z_FIELDSZ_EXTRA_FIELDSrM   r   r+   rS   r   r   r   r   <module>   s2    -P