U
    $Pf                     @   s   d dl mZ ddlmZmZ ddlmZ ddlmZ ddl	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_literals   )BrightcoveLegacyIEBrightcoveNewIE)InfoExtractor   )
compat_str)ExtractorErrorsanitized_Requestc                   @   s   e Zd Zdd Zdd ZdS )NownessBaseIEc                 C   s   |d dkr|d D ]}|d dkr|d }|d }|dkr| j d| |dd	d
}t|}|rt| |t   S t| |}|r| |t   S tdq|dkr| d| d  S |dkr| |d  S |dkrqd S )Ntypevideomediacontentsource
brightcovez#http://www.nowness.com/iframe?id=%szDownloading player JavaScriptz$Unable to download player JavaScript)ZnoteZerrnotez Could not find player definitionZvimeozhttp://vimeo.com/%sVimeoZyoutubeZYoutubeZcinematique)Z_download_webpager   Z_extract_brightcove_urlZ
url_resultZie_keyr   Z_extract_urlr	   )selfpostr   Zvideo_idr   Zplayer_codeZbc_url r   @/tmp/pip-unpacked-wheel-7zdooeg3/youtube_dl/extractor/nowness.py_extract_url_result   s2     

z!NownessBaseIE._extract_url_resultc                 C   s>   |  |}td||  dd|kr$dndid}|| ||fS )Nzhttp://api.nowness.com/api/zX-Nowness-Languagezcn.nowness.comzzh-cnzen-us)headers)Z	_match_idr
   Z_download_json)r   urlrequest_path
display_idrequestr   r   r   _api_request,   s    

 zNownessBaseIE._api_requestN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                   @   s   e Zd 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ddddddddddddgdgZdd  Zd!S )"	NownessIEZnownesszchttps?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])z=https://www.nowness.com/story/candor-the-art-of-gesticulationZ 068bc0202558c2e391924cb8cc470676Z2520295746001Zmp4z Candor: The Art of Gesticulationzre:^https?://.*\.jpgiL;VZ20151105Z2385340575001)idexttitledescription	thumbnail	timestampupload_dateuploader_idZBrightcoveNew)r   md5	info_dictZadd_iezDhttps://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnrZ e79cf125e387216f86b2e0a5b5c63aa3Z3716354522001u*   Kasper Bjørke ft. Jaakko Eino Kalevi: TNRiSZ20140806zEhttps://www.nowness.com/series/nowness-picks/jean-luc-godard-supercutZ 9a5a6a8edf806407e411296ab6bc2a49Z	130020913z&Bleu, Blanc, Rouge - A Godard Supercutz$md5:f0ea5f1857dffca02dbd37875d742cecZ20150607zCinema Sem LeiZcinemasemlei)r"   r#   r$   r%   r&   r(   Zuploaderr)   r   c                 C   s   |  |d\}}| |S )Nzpost/getBySlug/%s)r   r   )r   r   _r   r   r   r   _real_extractf   s    zNownessIE._real_extractN)r   r   r    IE_NAME
_VALID_URLZ_TESTSr-   r   r   r   r   r!   6   sV   


-r!   c                   @   s,   e Zd ZdZdZdddiddZdd	 Zd
S )NownessPlaylistIEznowness:playlistz;https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)zNhttps://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-bluesr"   Z3286   r   r+   Zplaylist_mincountc                    s2     |d\}} fdd|d D } ||S )Nzpost?PlaylistId=%sc                    s   g | ]}  |qS r   r   ).0itemr   r   r   
<listcomp>x   s     z3NownessPlaylistIE._real_extract.<locals>.<listcomp>items)r   playlist_result)r   r   Zplaylist_idZplaylistentriesr   r6   r   r-   v   s    zNownessPlaylistIE._real_extractNr   r   r    r.   r/   Z_TESTr-   r   r   r   r   r0   k   s    r0   c                   @   s0   e Zd ZdZdZddddddd	Zd
d ZdS )NownessSeriesIEznowness:serieszFhttps?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])z)https://www.nowness.com/series/60-secondsZ60z
60 Secondsz)One-minute wisdom in a new NOWNESS series)r"   r$   r%      r2   c                    s~     |d\}} fdd|d D }d }d }|dg }|rf|d dpV|d d }|d d	} |t|d
 ||S )Nzseries/getBySlug/%sc                    s   g | ]}  |qS r   r3   )r4   r   r6   r   r   r7      s     z1NownessSeriesIE._real_extract.<locals>.<listcomp>Zpoststranslationsr   r$   ZseoTitleZseoDescriptionr"   )r   getr9   r   )r   r   r   Zseriesr:   Zseries_titleZseries_descriptionr>   r   r6   r   r-      s     
  zNownessSeriesIE._real_extractNr;   r   r   r   r   r<   |   s   
r<   N)
__future__r   r   r   r   commonr   compatr   utilsr	   r
   r   r!   r0   r<   r   r   r   r   <module>   s   &5