U
    $Pf%                     @   s   d dl mZ d dlZddlmZ ddlmZ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dS )    )unicode_literalsN   )InfoExtractor   )compat_parse_qscompat_urllib_parse_urlparse)HEADRequestdetermine_extint_or_noneparse_iso8601strip_or_nonetry_getc                   @   s   e Zd Zdd ZdS )	IGNBaseIEc                 C   s   |  d| j||S )Nz(http://apis.ign.com/{0}/v3/{0}s/slug/{1})Z_download_jsonformat
_PAGE_TYPE)selfZslug r   </tmp/pip-unpacked-wheel-7zdooeg3/youtube_dl/extractor/ign.py	_call_api   s     zIGNBaseIE._call_apiN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   sd   e Zd ZdZd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dgZdd ZdS )IGNIEz
    Extractor for some of the IGN sites, like www.ign.com, es.ign.com de.ign.com.
    Some videos of it.ign.com are also supported
    zThttps?://(?:.+?\.ign|www\.pcmag)\.com/videos/(?:\d{4}/\d{2}/\d{2}/)?(?P<id>[^/?&#]+)zign.comvideoz:http://www.ign.com/videos/2013/06/05/the-last-of-us-reviewZ d2e1586d9987d40fad7867bf96a018eaZ 8f862beef863986b2785559b9e1aa599mp4zThe Last of Us Reviewz$md5:c8946d4260a4d43a00d5ae8ed998870ci`DQZ20130605zcount:9)idexttitledescription	timestampupload_datetagsurlmd5	info_dictzYhttp://www.pcmag.com/videos/2015/01/06/010615-whats-new-now-is-gogo-snooping-on-your-dataZ f1581a6fe8c5121be5b807684aeac3f6Z ee10d774b508c9b8ec07e763b9125b91z.What's New Now: Is GoGo Snooping on Your Data?z$md5:817a20299de610bd56f13175386da6fai2TZ20150106zcount:4zOhttps://www.ign.com/videos/is-a-resident-evil-4-remake-on-the-way-ign-daily-fixTr#   Zonly_matchingc                 C   s  |  |}| |}|d }|d }|dp>|dp>|d }g }|dpPi }|d}	|	r||| j|	|dd	d
dd |d}
|
r|| j|
|ddd |dpg D ]T}|d}|sq||t|ddt|dt|dt|dd qt|dd }|r4|t	|ddd|d | 
| g }|dpPg D ](}|d}|sjqR|d|i qRg }|dpg D ]$}|d}|sq|| q||t|d t|d!t|d"||||d#	S )$NZvideoIdmetadataZ	longTitler   namerefsZm3uUrlr   Zm3u8_nativeZhlsF)Zm3u8_idfatalZf4mUrlZhds)Zf4m_idr*   Zassetsr#   Zbitratei  Z
frame_rateheightwidth)r#   ZtbrZfpsr+   r,   c                 S   s   | d d S )NsystemZmezzanineUrlr   xr   r   r   <lambda>b       z%IGNIE._real_extract.<locals>.<lambda>Z	mezzaniner   )r   Z	format_idZ
preferencer#   
thumbnailsr!   ZdisplayNamer   ZpublishDateduration)	r   r   r   r   r3   
display_idr2   formatsr!   )	_match_idr   getextendZ_extract_m3u8_formatsZ_extract_f4m_formatsappendr
   r   r	   Z_sort_formatsr   r   )r   r#   r4   r   video_idr'   r   r5   r)   Zm3u8_urlZf4m_urlZassetZ	asset_urlZmezzanine_urlr2   Z	thumbnailZthumbnail_urlr!   tagZdisplay_namer   r   r   _real_extractA   s    


    
   



 

zIGNIE._real_extractN)	r   r   r   __doc__
_VALID_URLZIE_NAMEr   _TESTSr<   r   r   r   r   r      s>   r   c                	   @   sT   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gZdd ZdS )
IGNVideoIEzIhttps?://.+?\.ign\.com/(?:[a-z]{2}/)?[^/]+/(?P<id>\d+)/(?:video|trailer)/z[http://me.ign.com/en/videos/112203/video/how-hitman-aims-to-be-different-than-every-other-sZ dd9aca7ed2657c4e118d8b261e5e9de1Z e9be7ea899a9bbfc0674accc22a36cc8r   zIHow Hitman Aims to Be Different Than Every Other Stealth Game - NYCC 2015zGTaking out assassination targets in Hitman has never been more stylish.i VZ20151012r   r   r   r   r   r    r"   zNhttp://me.ign.com/ar/angry-birds-2/106533/video/lrd-ldyy-lwl-lfylm-angry-birdsTr&   zChttps://me.ign.com/ar/ratchet-clank-rift-apart/144327/trailer/embedz9http://adria.ign.com/sherlock-season-4/9687/trailer/embedz.https://kr.ign.com/bic-2018/3307/trailer/embedc                 C   sl   |  |}t|ddd d }| || }tt|jdd gd }|rb| 	|t
 S | 	|S )N/r   r   z/embedr#   )r6   r   rsplitZ_request_webpagegeturlr   r   queryr7   
url_resultr   ie_key)r   r#   r:   reqZign_urlr   r   r   r<      s    
 zIGNVideoIE._real_extractN)r   r   r   r>   r?   r<   r   r   r   r   r@      s2   r@   c                   @   s   e Zd 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gd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#d$ Zd%S )&IGNArticleIEzehttps?://.+?\.ign\.com/(?:articles(?:/\d{4}/\d{2}/\d{2})?|(?:[a-z]{2}/)?feature/\d+)/(?P<id>[^/?&#]+)articlezVhttp://me.ign.com/en/feature/15775/100-little-things-in-gta-5-that-will-blow-your-mindZ524497489e4e8ff5848ece34z3100 Little Things in GTA 5 That Will Blow Your Mind)r   r   r%   Z 5ebbd138523268b93c9141af17bec937r   zGTA 5 Video ReviewzhRockstar drops the mic on this generation of games. Watch our review of the masterly Grand Theft Auto V.ih7RZ20130916rA   Z 638672ee848ae4ff108df2a296418ee2z,26 Twisted Moments from GTA 5 in Slow Motionz4The twisted beauty of GTA 5 in stunning slow motion.idRZ20131212z2-3T)Zplaylist_itemsZskip_download)r#   r%   ZplaylistparamszVhttp://www.ign.com/articles/2014/08/15/rewind-theater-wild-trailer-gamescom-2014?watchZ53ee806780a81ec46e0790f8z+Rewind Theater - Wild Trailer Gamescom 2014r   )r#   r%   Zplaylist_countz`http://www.ign.com/articles/2017/06/08/new-ducktales-short-donalds-birthday-doesnt-go-as-plannedr&   z>https://www.ign.com/articles/2021-mvp-named-in-puppy-bowl-xviizLhttps://www.ign.com/articles/2014/08/07/sons-of-anarchy-final-season-trailerzihttps://www.ign.com/articles/2017/09/20/marvels-the-punisher-watch-the-new-trailer-for-the-netflix-seriesz`https://www.ign.com/articles/2016/01/16/supergirl-goes-flying-with-martian-manhunter-in-new-clipc              	      sF    |}|  fdd}|  dtt dd S )Nc                  3   sZ   t  dd } | r$| t V   dp0g D ]"}td|D ]}|V  qBq2d S )Nc                 S   s   | d d d d d S )NZmediaRelationsr   Zmediar'   r#   r   r.   r   r   r   r0      r1   z=IGNArticleIE._real_extract.<locals>.entries.<locals>.<lambda>contentzD(?:\[(?:ignvideo\s+url|youtube\s+clip_id)|<iframe[^>]+src)="([^"]+)")r   rF   r   rG   r7   refindall)Z	media_urlrL   Z	video_urlrJ   r   r   r   entries   s    z+IGNArticleIE._real_extract.<locals>.entriesZ	articleIdc                 S   s   | d d S )Nr'   Zheadliner   r.   r   r   r   r0     r1   z,IGNArticleIE._real_extract.<locals>.<lambda>)r6   r   Zplaylist_resultr7   r   r   )r   r#   r4   rP   r   rO   r   r<      s    

 zIGNArticleIE._real_extractN)r   r   r   r>   r   r?   r<   r   r   r   r   rI      sh   !	=rI   )
__future__r   rM   commonr   compatr   r   utilsr   r	   r
   r   r   r   r   r   r@   rI   r   r   r   r   <module>   s    
p)