U
    ga                     @   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   s2   | di ddi | j| j| f||d S )NheadersAcceptzimage/webp,*/*payload)
setdefaultupdateZ_download_json	_API_BASE)selfendpointargskwargs r   =/tmp/pip-unpacked-wheel-q5ljy6pj/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k}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   )newZ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)r/   username)r/   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(   s8      
 
 

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|kr||| d5 d6 d7d8 n8|
|| d5 d6 d7d9|krd:nd d; q|
r||
||t	|	d<d=S g }|d(g D ]` t d) d>ksd> d*d+kr.q| d  d? d@d  fdAddBD dC q|r|dDdEi|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'   errnoterE   articler/   ZGameJolturlzhttps://gamejolt.com/p/Zslugr0   r1   r4   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{} - {}	communityr1   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)   r6   comment_countr   )defaultZadded_onr-   r.   Zpublished_on)Zextractor_keyZ	extractorZwebpage_urlr+   rN   description
display_iduploaderuploader_iduploader_url
categoriestagsr6   rY   r5   release_timestampZ__post_extractor)Zvideos.r2   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+   rJ   rg   rh   ri   z
video-cardnoneZ	format_idrJ   rg   rh   ri   Zacodec
view_count)formats	subtitles
thumbnailsrl   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 )rd   rg   Nrh   ri   rj   rk   )r   )rS   Zurl_keyrc   r   r   rU      s    
)rd   Zmediaserver_urlZmediaserver_url_mp4Zmediaserver_url_webm)r+   rN   rm   _typeplaylistentries)Zembeds.rJ   )r=   r   r    r   r9   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_idrB   r[   Zfull_descriptionrF   	user_data	info_dictZ
video_datarm   rn   ro   Z	media_urlmimetypeextZmedia_idZhls_formatsZhls_subsZdash_formatsZ	dash_subsZgif_entriesZ	embed_urlr   rr   r   _parse_postA   s    

   

  .



	$
  
zGameJoltBaseIE._parse_postN)__name__
__module____qualname__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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dddddgedd gd!d"d#d$d%dd&d'ed(d)dd*d+d,dd-d.d/d0d1d2d
gd3d4d5d4d6eeed7dd8d9d:d;d;d<d=d>d?d@dAdBdCgdDdEeedFdGdHdIdJdKigdLdMdNdOdPdQdRdRdSdSdTdUgdVdWeedFdXgZdYdZ Zd[S )\r9   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c6achnzure   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\   rN   r[   r]   r^   r_   r`   ra   r5   upload_daterb   release_date	thumbnailr6   rY   rl   )rJ   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+   rN   r[   r]   r^   r_   r~   durationra   r6   Zplayable_in_embedr`   Zavailabilityr   Z	age_limitZlive_statusZchannel_urlrL   
channel_idr   rl   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\   rN   r[   r]   r^   r_   r`   r5   r   rb   r   r   r6   rY   rl   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/@CheeseguyDevzGame Dev - GeneralzArts n' Crafts - CreationszPixel Art - showcasezFriday Night Funkin' - Modsz&Newgrounds - Friday Night Funkin (13+)iaia)r+   r\   rN   r[   r]   r^   r_   r`   r5   rb   r6   rY   r|   ZdszyjnwiZwebmz"gif-presentacion-mejorado-dszyjnwi)r+   r~   rN   r   rJ   r|   rt   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)rJ   r   r|   c                 C   s*   |  |}| d| |d }| |S )Nzweb/posts/view/post)	_match_idr   r   )r   rJ   rz   ry   r   r   r   _real_extract%  s    
 zGameJoltIE._real_extractN)r   r   r   
_VALID_URLint_TESTSr   r   r   r   r   r9      s    yr9   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'   rH   itemsZaction_resource_modelr#   r%   r   z page from)ZscrollDirectionZscrollId)r'   rH   data)r   r   jsondumpsencoder   )
r   r   Zlist_idr'   rH   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d
ddg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+   rN   r[   ignore_no_formats_errorTskipping formatNo video formats found!Requested format is not availablerJ   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   r/   Zbio_contentrC   FrD   zweb/posts/fetch/user/@z?tab=activezDownloading user postszUnable to download user postsr+   r0   r1   )r   r   r    r=   r   playlist_resultr   r   )r   rJ   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d
ddg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   r   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_contentrC   FrD   zweb/posts/fetch/game/zDownloading game postszUnable to download game postsrN   )r   r   r    r=   r   r   r   )r   rJ   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+   rN   r|   Z184434Zmp3zGettin' Lucky (Menu Music)z(re:^https://.+vs-oswald-menu-music\.mp3$i waZ20211025)r+   r~   rN   rJ   rb   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+   rN   rJ   r,   r-   r.   )r+   rN   rJ   rb   )r   r   r   )rS   Zsongr   r   r   rU     s   z:GameJoltGameSoundtrackIE._real_extract.<locals>.<listcomp>Zsongs)Z	microdatar1   ))ZtwitterZfbrN   Fr2   )r   r   r   r   r	   r   )r   rJ   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	d
ddgdddddddddd	d
ddg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   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+   rK   rL   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 infoFrG   r1   z - rM   r   rC   rD   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   rJ   r\   Zcommunity_idr   r>   Zcommunity_dataZchannel_datarN   r[   r   r   r   r     sH         "    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dddg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usersrV   Zgamesz,https://gamejolt.com/search?foo=bar&q=%23fnfr   z#fnfr   Tr   r   r   r   r   z6https://gamejolt.com/search/communities?q=cookie%20run
   z
cookie run)rJ   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 ]d}| j d| d| d| |d| d| d| dd}|| D ]}| | j| jf |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ceilrx   _URL_FORMATSrO   )	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   rJ   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   r9   r   r   r   r   r   r   r   r   r   r   <module>   s    
  43