3
b`Z(                 @   sl   d dl mZ d dlZd dlZddlmZ ddlmZ ddlm	Z	m
Z
mZ G dd	 d	eZG d
d deZdS )    )unicode_literalsN   )InfoExtractor   )compat_urlparse)int_or_noneparse_durationunified_strdatec               @   s   e 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	ddddddddd	ddddddgdd d!d"dd#d$gd%d&d'd(dd)d*d+d,d-d.d,d-gZd/Zd0d1 Zd2S )3AppleTrailersIEappletrailerszahttps?://(?:www\.|movie)?trailers\.apple\.com/(?:trailers|ca)/(?P<company>[^/]+)/(?P<movie>[^/]+)z1http://trailers.apple.com/trailers/wb/manofsteel/Z5111zMan of Steel)idtitleZ d97a8e575432dbcb81b7c3acb741f8a8zmanofsteel-trailer4movo   z	Trailer 4Z20130523wb)r   extdurationr   upload_dateuploader_id)md5	info_dictZ b8017b7131b721fb4e8d6f49e1df908czmanofsteel-trailer3   z	Trailer 3Z20130417Z d0f1e1150989b9924679b441f3404d48zmanofsteel-trailer   ZTrailerZ20121212Z 5fe08795b943eb2e757fa95cb6def1cbzmanofsteel-teaser]   ZTeaserZ20120721)urlr   playlistz7http://trailers.apple.com/trailers/magnolia/blackthorn/Z4489Z
Blackthornr   z Unable to download JSON metadata)r   r   playlist_mincountexpected_warningsz4http://trailers.apple.com/trailers/fox/kungfupanda3/Z15881zKung Fu Panda 3   )r   r   r   z.http://trailers.apple.com/ca/metropole/autrui/T)r   only_matchingzLhttp://movietrailers.apple.com/trailers/focus_features/kuboandthetwostrings/ziTunes.playURL\((.*?)\);c       '         sh  t j j|}|jd}|jd} j||} jd|d} jd| |dd}|rg }x|jdg D ]}	|	d	 }
g }x|	jd
i j D ]z\}}xp|jdi j D ]\\}}|jd}|sq|j	d||f t j
dd|t|jdt|jd|d d d qW qW  j| |j	|d t j
dd|
j  ||
|	jdpJ|	jdt|	jdp`|	jdt|	jd|d qjW |jdi } j|||jdS tj|d} fd d!} j|||d"}g }x|jd#D ]}|jd$jd% } j j|d&}tj|}|jd'}|sq|d	 }|d t j
dd|j  }|jd(jd }|d jdd}|d }t jd)|} d }!| rd*t| jd+ t| jd, }!|jd-d= jd/d0 j }"tj|d1|" }# j|#|"d2}$g }xP|$d3 d D ]@}%t j
d4d|%d }&|j	|&|%d5 t|%d t|%d d6 qW  j| |j	d7||||!|||d8d9id:	 qW d;||d<S )>NmovieZcompanyzFilmId\s*=\s*'(\d+)'zfilm idz5http://trailers.apple.com/trailers/feeds/data/%s.jsonF)fatalZclipsr   versionsZsizessrcz%s-%sz_(\d+p\.mov)z_h\1widthheightr   )	format_idr   r$   r%   language-z[^a-zA-Z0-9] ZscreenZthumbruntimeZfadedZposted)r   formatsr   	thumbnailr   r   r   pageZmovie_titlezincludes/playlists/itunes.incc                s@   t jdd| } t jdd| } dd }t j j|| } d|  } | S )Nz(?s)<script[^<]*?>.*?</script>r)   z<img ([^<]*?)/?>z	<img \1/>c             S   s   d| j djdd S )NziTunes.playURL(%s);r   'z&#39;)groupreplace)m r2   NC:\Users\Broad\Desktop\All-Down\binaries\youtube_dl\extractor\appletrailers.py_clean_json   s    zDAppleTrailersIE._real_extract.<locals>.fix_html.<locals>._clean_jsonz<html>%s</html>)resub_JSON_RE)sr4   )selfr2   r3   fix_html   s    z/AppleTrailersIE._real_extract.<locals>.fix_html)transform_sourcez./div/ul/liz.//aZonClickztrailer infor   z.//imgz+(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})<   minutesseconds/r   _r   zincludes/settings/%s.jsonzDownloading settings jsonmetadataz_(\d*p\.mov)type)r   formatr$   r%   videoz
User-Agentz!QuickTime compatible (youtube-dl))	_typer   r+   r   r   r,   r   r   http_headersr   )rE   r   entries)r5   match
_VALID_URLr/   _download_webpage_search_regex_download_jsongetitemsappendr6   r   _sort_formatslowerr   r	   playlist_resultr   urljoin_download_xmlfindallfindattribr7   jsonloadsr0   searchintsplit
rpartition)'r9   r   mobjr    r   webpageZfilm_idZ	film_datarG   ZclipZ
clip_titler+   versionZversion_datasizeZ	size_datar#   Z	page_dataplaylist_urlr:   docr   liZon_clickZtrailer_info_jsonZtrailer_infoZ	first_urlr   video_idr,   r   r*   r1   r   Z
trailer_idZsettings_json_urlsettingsrC   
format_urlr2   )r9   r3   _real_extract`   s    







 

zAppleTrailersIE._real_extractN)__name__
__module____qualname__IE_NAMErJ   _TESTSr7   ri   r2   r2   r2   r3   r
      s`   



r
   c               @   s   e Zd ZdZdddddddddd	d
dddddZddje 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dddddgZdd ZdS ) AppleTrailersSectionIEzappletrailers:sectionZ
just_addedz
Just Added)	feed_pathr   	exclusiveZ	ExclusiveZjust_hdzJust HDZmost_popzMost PopularZstudioszMovie Studios)	justaddedrq   justhdmostpopularmoviestudiosz;https?://(?:www\.)?trailers\.apple\.com/#section=(?P<id>%s)|z,http://trailers.apple.com/#section=justaddedrr   )r   r   P   )r   r   r   z,http://trailers.apple.com/#section=exclusivez)http://trailers.apple.com/#section=justhdrs   z.http://trailers.apple.com/#section=mostpopularrt      z/http://trailers.apple.com/#section=moviestudiosru   c                sN    j |} jd j| d  |} fdd|D } j|| j| d S )Nz5http://trailers.apple.com/trailers/home/feeds/%s.jsonrp   c                s   g | ]} j d |d  qS )zhttp://trailers.apple.comlocation)
url_result).0e)r9   r2   r3   
<listcomp>  s   z8AppleTrailersSectionIE._real_extract.<locals>.<listcomp>r   )	_match_idrM   	_SECTIONSrS   )r9   r   sectionZsection_datarG   r2   )r9   r3   ri     s    

z$AppleTrailersSectionIE._real_extractN)	rj   rk   rl   rm   r   joinrJ   rn   ri   r2   r2   r2   r3   ro      sB   
ro   )
__future__r   r5   rY   commonr   compatr   utilsr   r   r	   r
   ro   r2   r2   r2   r3   <module>   s    G