a
    ha                     @   s   d dl Z d dlZ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 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G dd deZG dd deZG dd deZdS )    N   )InfoExtractor   )determine_extformat_fieldint_or_nonestr_or_nonetraverse_objtry_getc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )GameJoltBaseIEzhttps://gamejolt.com/site-api/c                 O   s8   | di ddi | j| j| g|R i |d S )NheadersAcceptzimage/webp,*/*payload)
setdefaultupdateZ_download_json	_API_BASE)selfendpointargskwargs r   N/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/extractor/gamejolt.py	_call_api   s    zGameJoltBaseIE._call_apic                 C   s   | dpg g  }}|D ]z}| ddkr<|| | q| dpHg d }}|D ]2}| drp||d 7 }qT| ddkrT|d7 }qT|| qd|S )NcontenttypeZ	paragraph textZ	hardBreak
)getappend_parse_content_as_textjoin)r   r   Zouter_contentsZjoined_contentsZouter_contentZinner_contentsZinner_content_textZinner_contentr   r   r   r       s    

z%GameJoltBaseIE._parse_content_as_textc           	      c   s  | j ddgt dd d }}|dv }tdD ]}| jd|||rHd	nd
|rR|n|f |d| d}|dsx qt|dtdD ]p}|d | 	| 
|d |t|ddd|dt|dtddt|dtdt|dtd|dpd dV  qt|d d d}q2d S )NZcomment_sortZhot)ie_keyr   )newyour   z"comments/Fireside_Post/%s/%s?%s=%d	scroll_idpagezDownloading comments list page )notecomments))r)   ZchildComments.expected_typeidZcomment_content	posted_on  ZscaleZvotes)user)display_namenameFr+   get_all)r0   username)r0   Zimage_avatarZ	parent_id)r,   r   	timestamp
like_countauthorZ	author_idZauthor_thumbnailparent)Z_configuration_arg
GameJoltIEr"   	itertoolscountr   r   r	   dictr    _parse_jsonr   r   )	r   Zpost_num_idZpost_hash_idsort_byr&   Zis_scrolledr'   Zcomments_datacommentr   r   r   _get_comments(   s2     


zGameJoltBaseIE._get_commentsc                    s  |d }| j |dpd|ddp$i }|dpF| |  |d|d  }}|dr| j |dp| jd	|d
| |ddddd|dd}| |}|dpi }t dt|dpd| |||p||d|dp|d|dt|dddd |dpg D t|dtdt	|dt	|ddd t	|d!d"d#t	|d$d"d#| 
|d
|d%}t|d&tdd'pi }	g i g   }
}}|	d(pg D ]  d)  d*d+t d)  d,f\}}}}|d-ks|d.kr"| j||d/|d0\}}|
| || n|d1ks6|d2kr`| j|||d3\}}|
| || nld4|v r||| d5 d6 d7d8 n8|
|| d5 d6 d7d9|v rd:nd d; q|
ri ||
||t	|	d<d=S g }|d(g D ]` t d) d>ksd> d*d+vr2q| d  d? d@d  fdAddBD dC q|rdDdEi|dF|iS t|dGtdd'}|r| |S |S )HNhashlead_content{}FfatalZleadStrZhas_articlearticle_contentzweb/posts/article/r,   zDownloading article metadataz#Unable to download article metadatar(   errnoterF   articler0   ZGameJolturlzhttps://gamejolt.com/p/Zslugr1   r2   r5   zhttps://gamejolt.com%sc                 S   s   g | ]}t |d d qS )c                 S   s*   d | d d | d dp&| d d S )Nz{} - {}	communityr2   channeldisplay_titletitle)formatr   )xr   r   r   <lambda>Z       z7GameJoltBaseIE._parse_post.<locals>.<listcomp>.<lambda>)r
   ).0categoryr   r   r   
<listcomp>Z   s   z.GameJoltBaseIE._parse_post.<locals>.<listcomp>communities)r   .r   .Zmarks.attrstagr*   r7   comment_countr   )defaultZadded_onr.   r/   Zpublished_on)Zextractor_keyZ	extractorZwebpage_urlr,   rO   description
display_iduploaderuploader_iduploader_url
categoriestagsr7   rZ   r6   release_timestampZ__post_extractor)Zvideos.r3   mediaimg_urlZfiletyper   r   zapplication/vnd.apple.mpegurlZm3u8mp4)Zm3u8_idzapplication/dash+xmlZmpd)Zmpd_idimagewidthheightfilesize)r,   rK   rh   ri   rj   z
video-cardnoneZ	format_idrK   rh   ri   rj   Zacodec
view_count)formats	subtitles
thumbnailsrm   Zgiffilename.c              	      sb   g | ]Z}  |r| | |d kr,  dnd|d kr@  dnd|d krT  dndddqS )re   rh   Nri   rj   rk   rl   )r   )rT   Zurl_keyrd   r   r   rV      s   )re   Zmediaserver_urlZmediaserver_url_mp4Zmediaserver_url_webm)r,   rO   rn   _typeplaylistentries)Zembeds.rK   )r>   r   r    r   r:   r"   r   r   r	   r   Zextract_commentsr=   r   Z#_extract_m3u8_formats_and_subtitlesextendr   Z"_extract_mpd_formats_and_subtitlesr   split
url_result)r   	post_datapost_idrC   r\   Zfull_descriptionrG   	user_data	info_dictZ
video_datarn   ro   rp   Z	media_urlmimetypeextZmedia_idZhls_formatsZhls_subsZdash_formatsZ	dash_subsZgif_entriesZ	embed_urlr   rs   r   _parse_postA   s    



.



	$

zGameJoltBaseIE._parse_postN)__name__
__module____qualname__r   r   r    rA   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
gddgdddddeeeddddddddddddg deddgdddd d!dd"d#ed$d%dd&d'd(dd)d*d+d,d-d.d
gd/d0d1d0d2eeed3dd4d5d6d7d7d8d9d:g d;d<d=eed>d?d@dAdBdCigdDdEdFdGdHdIdJdJdKdKdLdMgdNdOeed>dPgZdQdR ZdSS )Tr:   z<https?://(?:www\.)?gamejolt\.com/p/(?:[\w-]*-)?(?P<id>\w{8})z`https://gamejolt.com/p/introducing-ramses-jackson-some-fnf-himbo-i-ve-been-animating-fo-c6achnzuZ cd5f733258f6678b0ce500dd88166d86Zc6achnzurf   zIintroducing-ramses-jackson-some-fnf-himbo-i-ve-been-animating-fo-c6achnzuux   Introducing Ramses Jackson, some FNF himbo I’ve been animating for the past few days, hehe.
#fnfmod #fridaynightfunkinZJakeneutronz!https://gamejolt.com/@JakeneutronFriday Night Funkin' - VideosZfnfmodZfridaynightfunkini9]aZ20211006i:]azre:^https?://.+wgch9mhq.png$)r,   r   r]   rO   r\   r^   r_   r`   ra   rb   r6   upload_daterc   release_date	thumbnailr7   rZ   rm   )rK   md5r}   z^https://gamejolt.com/p/hey-hey-if-there-s-anyone-who-s-looking-to-get-into-learning-a-n6g4jzpqZ 79a931ff500a5c783ef6c3bda3272e32ZXsNA_mzC0q4z5Adobe Animate CC 2021 Tutorial || Part 1 - The Basicsz$md5:9d1ab9e2625b3fe1f42b2a44c67fdd13z'http://www.youtube.com/user/Jakeneutroni  )zAdobe Animate CCZTutorialZ	Animationz
The BasicszFor BeginnersTZ	Educationpublicz:https://i.ytimg.com/vi_webp/XsNA_mzC0q4/maxresdefault.webpr   Znot_livez8https://www.youtube.com/channel/UC6_L7fnczNalFZyBthUE9oAZUC6_L7fnczNalFZyBthUE9oAZ20211015zcount:18)r,   rO   r\   r^   r_   r`   r   durationrb   r7   Zplayable_in_embedra   Zavailabilityr   Z	age_limitZlive_statusZchannel_urlrM   
channel_idr   rm   Zchaptersz4https://gamejolt.com/p/i-fuckin-broke-chaos-d56h3eueZ 786c1ccf98fde02c03a2768acb4258d0Zd56h3euezi-fuckin-broke-chaos-d56h3euezI fuckin broke Chaos.z@I moved my tab durning the cutscene so now it's stuck like this.ZJeff____________ZThe_Nyesh_Manz#https://gamejolt.com/@The_Nyesh_Mani]aZ20211218i
^azre:^https?://.+euksy8bd.png$)r,   r   r]   rO   r\   r^   r_   r`   ra   r6   r   rc   r   r   r7   rZ   rm   zahttps://gamejolt.com/p/hello-everyone-i-m-developing-a-pixel-art-style-mod-for-fnf-and-i-vs4gdrd8Zvs4gdrd8zJhello-everyone-i-m-developing-a-pixel-art-style-mod-for-fnf-and-i-vs4gdrd8z$md5:cc3d8b031d9bc7ec2ec5a9ffc707e1f9ZQuesoguyZCheeseguyDevz"https://gamejolt.com/@CheeseguyDev)zGame Dev - GeneralzArts n' Crafts - CreationszPixel Art - showcasezFriday Night Funkin' - Modsz&Newgrounds - Friday Night Funkin (13+)iaia)r,   r]   rO   r\   r^   r_   r`   ra   r6   rc   r7   rZ   r}   ZdszyjnwiZwebmz"gif-presentacion-mejorado-dszyjnwi)r,   r   rO   r   rK   r}   ru   playlist_countz#https://gamejolt.com/p/gif-yhsqkumq#   Zyhsqkumqzgif-yhsqkumqZGIFZDaniilTvmanz!https://gamejolt.com/@DaniilTvmanz2Five Nights At The AGK Studio Comunity - NEWS gameiaia)rK   r   r}   c                 C   s*   |  |}| d| |d }| |S )Nzweb/posts/view/post)	_match_idr   r   )r   rK   r{   rz   r   r   r   _real_extract%  s    

zGameJoltIE._real_extractN)r   r   r   
_VALID_URLint_TESTSr   r   r   r   r   r:      s   yr:   c                   @   s   e Zd Zddg fddZdS )GameJoltPostListBaseIEzDownloading post listzUnable to download post listc           
   
   c   s   d\}}|p | j ||||dd }|r|D ]}	| |	d V  q*|d d }|d7 }| j ||| d| |td	|d
 dd}q"d S )N)r   Nr(   rI   itemsZaction_resource_modelr#   r&   r   z page from)ZscrollDirectionZscrollId)r(   rI   data)r   r   jsondumpsencoder   )
r   r   Zlist_idr(   rI   initial_itemsZpage_numr&   r   itemr   r   r   _entries-  s    
zGameJoltPostListBaseIE._entriesN)r   r   r   r   r   r   r   r   r   ,  s   r   c                   @   s:   e Zd ZdZdddddddd	ig d
dgZdd ZdS )GameJoltUserIEz0https?://(?:www\.)?gamejolt\.com/@(?P<id>[\w-]+)z'https://gamejolt.com/@BlazikenSuperStarr   Z6116784zS. Blazez$md5:5ba7fbbb549e8ea2545aafbfe22eb03ar,   rO   r\   ignore_no_formats_errorTzskipping formatzNo video formats foundz!Requested format is not availablerK   playlist_mincountr}   paramsZexpected_warningsc                 C   s   |  |}| jd| |dddd }| | j|dd|dd	pDi }| | d
| d|ddt|d|dp|d|S )Nzweb/profile/@zDownloading user infozUnable to download user infor   r0   Zbio_contentrD   FrE   zweb/posts/fetch/user/@z?tab=activezDownloading user postszUnable to download user postsr,   r1   r2   )r   r   r    r>   r   playlist_resultr   r   )r   rK   Zuser_idr|   Zbior   r   r   r   L  s    
 zGameJoltUserIE._real_extractNr   r   r   r   r   r   r   r   r   r   r   <  s   r   c                   @   s:   e Zd ZdZdddddddd	ig d
dgZdd ZdS )GameJoltGameIEz9https?://(?:www\.)?gamejolt\.com/games/[\w-]+/(?P<id>\d+)z,https://gamejolt.com/games/Friday4Fun/655124r   Z655124z"Friday Night Funkin': Friday 4 Funz$md5:576a7dd87912a2dcf33c50d2bd3966d3r   r   Tr   r   c                 C   sp   |  |}| jd| |dddd }| | j|dd|dd	pDi }| | d
| |dd||d|S )Nzweb/discover/games/zDownloading game infozUnable to download game infor   Zgamedescription_contentrD   FrE   zweb/posts/fetch/game/zDownloading game postszUnable to download game postsrO   )r   r   r    r>   r   r   r   )r   rK   game_idZ	game_datar\   r   r   r   r   g  s    
zGameJoltGameIE._real_extractNr   r   r   r   r   r   W  s   r   c                   @   sj   e Zd ZdZdddddddd	d
dddiddddddddiddddddddigddgZdd ZdS )GameJoltGameSoundtrackIEz\https?://(?:www\.)?gamejolt\.com/get/soundtrack(?:\?|\#!?)(?:.*?[&;])??game=(?P<id>(?:\d+)+)z7https://gamejolt.com/get/soundtrack?foo=bar&game=657899Z657899zFriday Night Funkin': Vs Oswaldr,   rO   r}   Z184434Zmp3zGettin' Lucky (Menu Music)z(re:^https://.+vs-oswald-menu-music\.mp3$i waZ20211025)r,   r   rO   rK   rc   r   Z184435z Rabbit's Luck (Extended Version)z0re:^https://.+rabbit-s-luck--full-version-\.mp3$i9waZ185228z
Last Strawzre:^https://.+last-straw\.mp3$iaZ20211102   r   c                 C   sR   |  |}| jd| |ddd}| dd |dp8g D |t|dd	td
dS )Nzweb/discover/games/overview/zDownloading soundtrack infoz"Unable to download soundtrack infor   c              	   S   sF   g | ]>}t |d t |dt |dt|ddddqS )r,   rO   rK   r-   r.   r/   )r,   rO   rK   rc   )r   r   r   )rT   Zsongr   r   r   rV     s   z:GameJoltGameSoundtrackIE._real_extract.<locals>.<listcomp>Zsongs)Z	microdatar2   ))ZtwitterZfbrO   Fr3   )r   r   r   r   r	   r   )r   rK   r   Zgame_overviewr   r   r   r     s    


z&GameJoltGameSoundtrackIE._real_extractNr   r   r   r   r   r   r  sH   

%r   c                   @   s\   e Zd ZdZddddddddd	g d
dddddddddd	g d
dgZdd ZdS )GameJoltCommunityIEzhttps?://(?:www\.)?gamejolt\.com/c/(?P<id>(?P<community>[\w-]+)(?:/(?P<channel>[\w-]+))?)(?:(?:\?|\#!?)(?:.*?[&;])??sort=(?P<sort>\w+))?z!https://gamejolt.com/c/fnf/videos2   z
fnf/videosr   z$md5:6d8c06f27460f7d35c1554757ffe53c8r   TZplaylistendr   r   r   z https://gamejolt.com/c/youtuberszyoutubers/featuredzYoutubers - featuredz$md5:53e5582c93dcc467ab597bfca4db17d4c           
   
   C   s   |  |dddd\}}}}|p$d|p*d }}| jd| |dd	d
d }t| jd| d| |dddddpti }|dp| d|dp| }| | j|dpd|ddpi }	| | d| d| d| |dd| d| ||	S )Nr,   rL   rM   sortZfeaturedr$   zweb/communities/view/zDownloading community infoz!Unable to download community infor   zweb/communities/view-channel//zDownloading channel infozUnable to download channel infoFrH   r2   z - rN   r   rD   rE   zweb/posts/fetch/community/z?channels[]=z&channels[]=zDownloading community postsz"Unable to download community posts)	_match_valid_urlgroupr   r	   r   r    r>   r   r   )
r   rK   r]   Zcommunity_idr   r?   Zcommunity_dataZchannel_datarO   r\   r   r   r   r     s6    
"z!GameJoltCommunityIE._real_extractNr   r   r   r   r   r     s2   r   c                   @   s~   e Zd ZdZddd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ddd	dgZdd Zdd ZdS )GameJoltSearchIEz}https?://(?:www\.)?gamejolt\.com/search(?:/(?P<filter>communities|users|games))?(?:\?|\#!?)(?:.*?[&;])??q=(?P<id>(?:[^&#]+)+)z https://gamejolt.com/@{username}zhttps://gamejolt.com/c/{path}z&https://gamejolt.com/games/{slug}/{id})ZusersrW   Zgamesz,https://gamejolt.com/search?foo=bar&q=%23fnfr   z#fnfr   Tr   r   r   z6https://gamejolt.com/search/communities?q=cookie%20run
   z
cookie run)rK   r   r}   z'https://gamejolt.com/search/users?q=mlpi  Zmlpz*https://gamejolt.com/search/games?q=robloxi  Zrobloxc           	      c   s   | j d| d| |d| dd| dd}t|d| d}|sHd S td	t||d
  d	 D ]h}| j d| d| d| |d| d| d| dd}|| D ]"}| | j| jf i |V  qqdd S )Nzweb/search/z?q=zDownloading z listzUnable to download r   r<   ZCountr   ZperPagez&page=z list page )r   r	   rangemathceilry   _URL_FORMATSrP   )	r   queryfilter_modedisplay_queryZinitial_search_dataZentries_numr'   Zsearch_resultsresultr   r   r   _search_entries  s     z GameJoltSearchIE._search_entriesc                 C   sl   |  |dd\}}tj|}| |r8| |||n,| jd| || jd| |dddd d	||S )
Nfilterr,   zweb/posts/fetch/search/zweb/search?q=zDownloading initial post listz$Unable to download initial post listr   Zposts)r   )	r   r   urllibparseunquoter   r   r   r   )r   rK   r   r   r   r   r   r   r     s    
zGameJoltSearchIE._real_extractN)r   r   r   r   r   r   r   r   r   r   r   r   r     sH   #r   )r;   r   r   urllib.parser   commonr   utilsr   r   r   r   r	   r
   r   r:   r   r   r   r   r   r   r   r   r   r   <module>   s    
  43