
    VGh1$              	           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d
eddez  ded
eddez  ded
eddZ G d de      Z G d de      Z G d de      Zy)    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
    clipSizeByteszQquery ($id: String!) {
        video: getClip(clipIdentifier: $id) {
             z
        }
    }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 { z }
        }
    }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 { )clipmontageClipsMontagesMobile Clipsc                   $    e Zd Zed        ZddZy)AllstarBaseIEc                    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      hfdt        hfddt        hfdt        hfd      }|j                  d      r-|j                  d      rd|d   v rdnd}d| d| d|d    |d<   |j	                  t
        j                         t
        j                  t        d|j                  d            d       |S )Nc                     t        d|       S )Nzhttps://media.allstar.gg/)r   )paths    a/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/allstar.pymedia_url_or_nonez:AllstarBaseIE._parse_video_data.<locals>.media_url_or_none?   s    6==    _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/r1   )extractor_key	extractoruploader_url)	r   strr   getupdate	AllstarIEie_keyIE_NAMEr   )
video_datar   infobasenames       r   _parse_video_datazAllstarBaseIE._parse_video_data=   s$   	> J3%.$se,!C5)!2 34@5K\J]B^_%}5(;-8'+D*A)BC#cU+"EC51"[M2)
  88D>dhhuo!*d5k!9vyH$7z8*AdSWj\"ZD&--/"**#$;TXXm=TU
 	 r   Nc                     | j                  d||ddit        j                  ||d      j                               }t	        |dddt
        hf      }|rt        d	j                  |            t	        ||      S )
Nzhttps://a1.allstar.gg/graphqlzcontent-typezapplication/json)	variablesquery)noteheadersdataerrors.messagez; )_download_jsonjsondumpsencoder   r9   r   join)selfrE   rD   r   video_idrF   responserI   s           r   	_call_apizAllstarBaseIE._call_api\   s    &&+XD#%78)eDELLN ' P
 h3	C5(IJ 6!233Hd++r   )NN)__name__
__module____qualname__staticmethodrB   rS    r   r   r   r   <   s     <
,r   r   c                       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* Zy+),r<   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!   	thumbnailr0   extr-   r.   r/   r1   r8   upload_dater2   )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!   r`   r_   r-   r.   r/   r0   r1   r8   ra   r2   z;https://allstar.gg/montage?montage=643e64089da7e9363e1fa66c643e64089da7e9363e1fa66cAPQLGM2IMXWz#cherokee Rapid Fire Snipers Montagez$md5:a3ee356022115db2b27c81321d195945id>d20230418)r)   r*   r+   r!   r_   r`   r/   r0   r1   r8   ra   r2   z-https://allstar.gg/montage?montage=RILJMH6QOS64a2697372ce3703de29e868
RILJMH6QOSz$md5:d5672e6f88579730c2310a80fdbc4030izid20230703c                     | j                  |      j                  dd      \  }}| j                  | j                  t        j                  |      d|id|            S )Ntyper)   )rH   video)_match_valid_urlgrouprB   rS   _QUERIESr:   )rP   r!   query_idrQ   s       r   _real_extractzAllstarIE._real_extract   s^    !2237==fdK(%%NNX&x(8:KXWX 	Xr   N)rT   rU   rV   
_VALID_URLint_TESTSru   rX   r   r   r<   r<   i   s    iJ G,$9J #5K%
$ 8,%)9J #"5K%
& M,':9J#"5K%
" ?,&:9J#"5K%
gCFJXr   r<   c                   d    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 Zd Zy)AllstarProfileIEzDhttps?://(?:www\.)?allstar\.gg/(?:profile\?user=|u/)(?P<id>[^/?#&]+)z8https://allstar.gg/profile?user=62b8bdfc9021052f7905882dz62b8bdfc9021052f7905882d-clipszcherokee - Clips)r)   r+      )r!   rb   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              #   ~   K   |dz  }| j                  ||||dd|d|       D ]  }| j                  |        y w)Nr   )r'   pagegame)rH   videosrH   zDownloading page )rS   rB   )rP   user_idr*   r   rE   page_numr?   s          r   	_get_pagezAllstarProfileIE._get_page   s]     A..#$  .z=Nxj;Y[ 	5J ((44	5s   ;=c                 t   | j                  |      }| j                  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vrt        d|      | j                  t        t        j                  | j                  |||t        j                  |            | j                        t!        ||j#                         j%                         d   |      t!        |xs |||d            S )Nz(https://api.allstar.gg/v1/users/profile/rH   r   zUnable to extract the user idprofiler&   r   r   )viewr   r   )default)r   r   r   zUnsupported playlist URL type z - )delim)playlist_idplaylist_title)	_match_idrK   r   r   r9   r   r
   r   playlist_resultr   	functoolspartialr   rs   r:   
_PAGE_SIZEr	   lowersplit)	rP   r!   r*   profile_datar   r&   	url_queryr   rt   s	            r   ru   zAllstarProfileIE._real_extract   s=   ^^C(
**>
KZY|fuu-EF !@AAvy:QTPU.VWSM	IK='AB	;H@@ #A(!NOO##!!NNGZx||H?UWX\XgXgi &gx~~/?/E/E/G/JDQ((*@j8TY^_ $ a 	ar   N)rT   rU   rV   rv   rx   r   r   ru   rX   r   r   rz   rz      s    XJ J2'
   C6-
   M5*
  L3.
 +F< J	5ar   rz   )r   rL   commonr   utilsr   r   r   r	   r
   r   utils.traversalr   _FIELDS_EXTRA_FIELDSrs   r   r<   rz   rX   r   r   <module>r      s      !  +
 ]	$
	 	 ]	$
	 	 ]	$+:*,M *,ZMX MX`Ca} Car   