o
    ia                     @   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update_download_json	_API_BASE)selfendpointargskwargs r   M/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/gamejolt.py	_call_api   s   "zGameJoltBaseIE._call_apic                 C   s   | dpg g }}|D ]=}| ddkr|| | q| dp$g d}}|D ]}| dr8||d 7 }q*| ddkrC|d7 }q*|| qd|S )Ncontenttype	paragraph text	hardBreak
)getappend_parse_content_as_textjoin)r   r   outer_contentsjoined_contentsouter_contentinner_contentsinner_content_text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 ]n}| jd|||r%d	nd
|r*|n|f |d| d}|ds= d S t|dtdD ]8}|d | 	| 
|d |t|ddd|dt|dtddt|dtdt|dtd|dpxd dV  qDt|d d d}qd S )Ncomment_sorthot)ie_keyr   )newyour   z"comments/Fireside_Post/%s/%s?%s=%d	scroll_idpagezDownloading comments list page )notecomments))r4   childComments.expected_typeidcomment_content	posted_on  scalevotes)user)display_namenameFr7   get_all)r?   username)r?   image_avatar	parent_id)r8   r   	timestamp
like_countauthor	author_idauthor_thumbnailparent)_configuration_arg
GameJoltIEr-   	itertoolscountr   r!   r	   dictr#   _parse_jsonr   r   )	r   post_num_idpost_hash_idsort_byr1   is_scrolledr2   comments_datacommentr   r   r   _get_comments(   s6    


zGameJoltBaseIE._get_commentsc              
      s  |d }| j |dpd|ddpi }|dp#| |  |d|d }}|drP| j |dpF| jd	|d
| |ddddd|dd}| |}|dpVi }i dt dddt|dpld| d
|d|d|pw|d|dd|dp|dd|ddt|dd d!d"d# |d$pg D d%t|d&td'd(t	|d(d)t	|d)d*d+d,t	|d-d.d/d0t	|d1d.d/d2| 
|d
|}t|d3tdd4pi }	g i g }
}}|	d5pg D ]  d6  d7d8t d6  d9f\}}}}|d:ks|d;kr.| j||d<|d=\}}|
| || q|d>ks8|d?krM| j|||d@\}}|
| || qdA|v rg||| dB dC dDdE q|
|| dB dC dDdF|v r~dGnd dH q|
ri ||
||t	|	dIdJS g }|d5g D ]0 t d6 dKksdK d7d8vrq| d  dL dMd*  fdNd#dOD dP q|rdQdRi|dS|iS t|dTtdd4}|r| |S |S )UNhashlead_content{}FfatalleadStrhas_articlearticle_contentzweb/posts/article/r8   zDownloading article metadataz#Unable to download article metadatar3   errnoter^   articler?   extractor_key	extractorGameJoltwebpage_urlurlzhttps://gamejolt.com/p/titledescription
display_idsluguploaderr@   rA   uploader_idrD   uploader_urlzhttps://gamejolt.com%s
categoriesc                 S   s   g | ]	}t |d d qS )c                 S   s*   d | d d | d dp| d d S )Nz{} - {}	communityrA   channeldisplay_titlerj   )formatr!   )xr   r   r   <lambda>Z   s   * z7GameJoltBaseIE._parse_post.<locals>.<listcomp>.<lambda>)r
   ).0categoryr   r   r   
<listcomp>Z   s    z.GameJoltBaseIE._parse_post.<locals>.<listcomp>communitiestags)r   .r   .marks.attrstagr6   rH   comment_countr   )defaultrG   added_onr;   r<   release_timestamppublished_on__post_extractor)videos.rB   mediaimg_urlfiletyper   r   zapplication/vnd.apple.mpegurlm3u8mp4)m3u8_idzapplication/dash+xmlmpd)mpd_idimagewidthheightfilesize)r8   ri   r   r   r   z
video-cardnone	format_idri   r   r   r   acodec
view_count)formats	subtitles
thumbnailsr   giffilename.c              	      sb   g | ]-}  |r| | |d kr  dnd|d kr   dnd|d kr*  dndddqS )r   r   Nr   r   r   r   )r!   )rx   url_keyr   r   r   rz      s    

)r   mediaserver_urlmediaserver_url_mp4mediaserver_url_webm)r8   rj   r   _typeplaylistentries)embeds.ri   )rR   r!   r#   r   rN   r-   r   r   r	   r   extract_commentsrQ   r   #_extract_m3u8_formats_and_subtitlesextendr   "_extract_mpd_formats_and_subtitlesr"   split
url_result)r   	post_datapost_idr[   rk   full_descriptionra   	user_data	info_dict
video_datar   r   r   	media_urlmimetypeextmedia_idhls_formatshls_subsdash_formats	dash_subsgif_entries	embed_urlr   r   r   _parse_postA   s   




	
.




	$

zGameJoltBaseIE._parse_postN)__name__
__module____qualname__r   r   r#   rY   r   r   r   r   r   r      s    r   c                   @   s  e Zd ZdZddi dddddd	d
dddddddddddgdddgddddddddddd ed!ed"eid#d$d%i dd&d
d'dd(dddddd)ddd*d+dg d,d ed-d.dd/gd0d1dd2d3d4d5d6d7d8dd9d:ed;d<d#d=d>i dd?dddd@d
dAddBddCddDddEddgddFddGddHddGddId ed!ed"ed#dJdKdLdMdMdNdOdPg dQdRdSeedTdUdVdWdXdYigdZd[d\d]d^d_d`d`dadadbdcgdddeeedTdfgZdgdh ZdiS )jrN   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-c6achnzu cd5f733258f6678b0ce500dd88166d86r8   c6achnzur   r   rl   zIintroducing-ramses-jackson-some-fnf-himbo-i-ve-been-animating-fo-c6achnzurj   ux   Introducing Ramses Jackson, some FNF himbo I’ve been animating for the past few days, hehe.
#fnfmod #fridaynightfunkinrk   rn   Jakeneutronro   rp   z!https://gamejolt.com/@Jakeneutronrq   Friday Night Funkin' - Videosr|   fnfmodfridaynightfunkinrG   i9]aupload_date20211006r   i:]arelease_date	thumbnailzre:^https?://.+wgch9mhq.png$rH   r   r   )ri   md5r   z^https://gamejolt.com/p/hey-hey-if-there-s-anyone-who-s-looking-to-get-into-learning-a-n6g4jzpq 79a931ff500a5c783ef6c3bda3272e32XsNA_mzC0q4z5Adobe Animate CC 2021 Tutorial || Part 1 - The Basicsz$md5:9d1ab9e2625b3fe1f42b2a44c67fdd13z'http://www.youtube.com/user/Jakeneutrondurationi  )zAdobe Animate CCTutorial	Animationz
The BasicszFor Beginnersplayable_in_embedT	Educationavailabilitypublicz:https://i.ytimg.com/vi_webp/XsNA_mzC0q4/maxresdefault.webp	age_limitr   live_statusnot_livechannel_urlz8https://www.youtube.com/channel/UC6_L7fnczNalFZyBthUE9oAUC6_L7fnczNalFZyBthUE9oA20211015zcount:18)rs   
channel_idr   r   chaptersz4https://gamejolt.com/p/i-fuckin-broke-chaos-d56h3eue 786c1ccf98fde02c03a2768acb4258d0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.Jeff____________The_Nyesh_Manz#https://gamejolt.com/@The_Nyesh_Mani]a20211218i
^azre:^https?://.+euksy8bd.png$zahttps://gamejolt.com/p/hello-everyone-i-m-developing-a-pixel-art-style-mod-for-fnf-and-i-vs4gdrd8vs4gdrd8zJhello-everyone-i-m-developing-a-pixel-art-style-mod-for-fnf-and-i-vs4gdrd8z$md5:cc3d8b031d9bc7ec2ec5a9ffc707e1f9Quesoguy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)r8   rl   rj   rk   rn   ro   rp   rq   rG   r   rH   r   r   dszyjnwiwebmz"gif-presentacion-mejorado-dszyjnwi)r8   r   rj   r   ri   r   r   playlist_countz#https://gamejolt.com/p/gif-yhsqkumq#   yhsqkumqzgif-yhsqkumqGIFDaniilTvmanz!https://gamejolt.com/@DaniilTvmanz2Five Nights At The AGK Studio Comunity - NEWS gameiaia)ri   r   r   c                 C   s*   |  |}| d| |d }| |S )Nzweb/posts/view/post)	_match_idr   r   )r   ri   r   r   r   r   r   _real_extract%  s   


zGameJoltIE._real_extractN)r   r   r   
_VALID_URLint_TESTSr   r   r   r   r   rN      sH   	
	
	
yrN   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 }|rI|D ]
}	| |	d V  q|d d }|d7 }| j ||| d| |td	|d
 dd}|sd S d S )N)r   Nr3   rc   itemsaction_resource_modelr.   r1   r   z page from)scrollDirectionscrollId)r3   rc   data)r   r   jsondumpsencoder!   )
r   r   list_idr3   rc   initial_itemspage_numr1   r   itemr   r   r   _entries-  s$   zGameJoltPostListBaseIE._entriesN)r   r   r   r  r   r   r   r   r   ,  s    r   c                   @   :   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   6116784zS. Blazez$md5:5ba7fbbb549e8ea2545aafbfe22eb03ar8   rj   rk   ignore_no_formats_errorTzskipping formatzNo video formats foundz!Requested format is not availableri   playlist_mincountr   paramsexpected_warningsc                 C   s   |  |}| jd| |dddd }| | j|dd|dd	p"i }| | d
| d|ddt|d|dp@|d|S )Nzweb/profile/@zDownloading user infozUnable to download user infor   r?   bio_contentr\   Fr]   zweb/posts/fetch/user/@z?tab=activezDownloading user postszUnable to download user postsr8   r@   rA   )r   r   r#   rR   r!   playlist_resultr  r   )r   ri   user_idr   bior   r   r   r   L  s   
 zGameJoltUserIE._real_extractNr   r   r   r   r   r   r   r   r   r   r  <      r  c                   @   r  )GameJoltGameIEz9https?://(?:www\.)?gamejolt\.com/games/[\w-]+/(?P<id>\d+)z,https://gamejolt.com/games/Friday4Fun/655124r   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	p"i }| | d
| |dd||d|S )Nzweb/discover/games/zDownloading game infozUnable to download game infor   gamedescription_contentr\   Fr]   zweb/posts/fetch/game/zDownloading game postszUnable to download game postsrj   )r   r   r#   rR   r!   r  r  )r   ri   game_id	game_datark   r   r   r   r   g  s   
zGameJoltGameIE._real_extractNr  r   r   r   r   r  W  r  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=657899657899zFriday Night Funkin': Vs Oswaldr8   rj   r   184434mp3zGettin' Lucky (Menu Music)z(re:^https://.+vs-oswald-menu-music\.mp3$i wa20211025)r8   r   rj   ri   r   r   184435z Rabbit's Luck (Extended Version)z0re:^https://.+rabbit-s-luck--full-version-\.mp3$i9wa185228z
Last Strawzre:^https://.+last-straw\.mp3$ia20211102   r   c                 C   sR   |  |}| jd| |ddd}| dd |dpg 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 )r8   rj   ri   r:   r;   r<   )r8   rj   ri   r   )r   r!   r   )rx   songr   r   r   rz     s    
z:GameJoltGameSoundtrackIE._real_extract.<locals>.<listcomp>songs)	microdatarA   ))twitterfbrj   FrB   )r   r   r  r!   r	   r   )r   ri   r  game_overviewr   r   r   r     s   


z&GameJoltGameSoundtrackIE._real_extractNr  r   r   r   r   r  r  sJ    

%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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p:i }|dpA| d|dpI| }| | j|dpVd|ddp\i }	| | d| d| d| |dd| d| ||	S )Nr8   rr   rs   sort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 infoFrb   rA   z - rt   r  r\   r]   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#   rR   r  r  )
r   ri   rl   community_idr   rU   community_datachannel_datarj   rk   r   r   r   r     s6   
"z!GameJoltCommunityIE._real_extractNr  r   r   r   r   r)    s4    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})usersr{   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)ri   r
  r   z'https://gamejolt.com/search/users?q=mlpi  mlpz*https://gamejolt.com/search/games?q=robloxi  robloxc           	      c   s    | j d| d| |d| dd| dd}t|d| d}|s%d S td	t||d
  d	 D ]4}| j d| d| d| |d| d| d| dd}|| D ]}| | j| jdi |V  qUq3d S )Nzweb/search/z?q=zDownloading z listzUnable to download r   rP   Countr   perPagez&page=z list page r   )r   r	   rangemathceilr   _URL_FORMATSru   )	r   queryfilter_modedisplay_queryinitial_search_dataentries_numr2   search_resultsresultr   r   r   _search_entries  s"     z GameJoltSearchIE._search_entriesc                 C   sr   |  |dd\}}tj|}| |r| |||||S | jd| || jd| |dddd d	||S )
Nfilterr8   zweb/posts/fetch/search/zweb/search?q=zDownloading initial post listz$Unable to download initial post listr   posts)r   )	r0  r1  urllibparseunquoter  rH  r  r   )r   ri   rB  rA  rC  r   r   r   r     s    
zGameJoltSearchIE._real_extractN)r   r   r   r   r@  r   rH  r   r   r   r   r   r5    sJ    #r5  )rO   r   r>  urllib.parserK  commonr   utilsr   r   r   r   r	   r
   r   rN   r   r  r  r  r)  r5  r   r   r   r   <module>   s      
  43