
    yf'                     l    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e      Z
 G d	 d
e      Zy)    N   )InfoExtractor   )compat_urlparse)int_or_noneparse_durationunified_strdatec                       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d0 Zy1)2AppleTrailersIEappletrailerszahttps?://(?:www\.|movie)?trailers\.apple\.com/(?:trailers|ca)/(?P<company>[^/]+)/(?P<movie>[^/]+)z1http://trailers.apple.com/trailers/wb/manofsteel/5111zMan of Steel)idtitle d97a8e575432dbcb81b7c3acb741f8a8zmanofsteel-trailer4movo   z	Trailer 420130523wb)r   extdurationr   upload_dateuploader_id)md5	info_dict b8017b7131b721fb4e8d6f49e1df908czmanofsteel-trailer3   z	Trailer 320130417 d0f1e1150989b9924679b441f3404d48zmanofsteel-trailer   Trailer20121212 5fe08795b943eb2e757fa95cb6def1cbzmanofsteel-teaser]   Teaser20120721)urlr   playlistz7http://trailers.apple.com/trailers/magnolia/blackthorn/4489
Blackthornr   z Unable to download JSON metadata)r&   r   playlist_mincountexpected_warningsz4http://trailers.apple.com/trailers/fox/kungfupanda3/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                      j                  |      }|j                  d      }|j                  d      } j                  ||      } j                  d|d      } j	                  d|z  |d      }|rg }|j                  dg       D ]y  }	|	d	   }
g }|	j                  d
i       j                         D ]  \  }}|j                  di       j                         D ]}  \  }}|j                  d      }|s|j                  |d|t        j                  dd|      t        |j                  d            t        |j                  d            |d d d         |j                  |dz   t        j                  dd|
      j                         z   ||
|	j                  d      xs |	j                  d      t        |	j                  d      xs |	j                  d            t        |	j                  d            |d       | |j                  di       } j                  |||j                  d            S t        j                   |d      } fd} j#                  |||       }g }|j%                  d!      D ]  }|j'                  d"      j(                  d#   } j                   j*                  |d$      }t-        j.                  |      }|j                  d%      }|sh|d	   }|dz   t        j                  dd|      j                         z   }|j'                  d&      j(                  d   }|d   j1                  dd      }|d   }t        j2                  d'|      } d }!| r8d(t5        | j                  d)            z  t5        | j                  d*            z   }!|j7                  d+      d,   j9                  d-      d.   j                         }"t        j                   |d/|"z        }# j	                  |#|"d0      }$g }|$d1   d   D ]M  }%t        j                  d2d|%d         }&|j                  |&|%d3   t        |%d         t        |%d         d4       O |j                  d5||||!|||d6d7id8	        d9||d:S );NmoviecompanyzFilmId\s*=\s*'(\d+)'zfilm idz5http://trailers.apple.com/trailers/feeds/data/%s.jsonF)fatalclipsr   versionssizessrc-z_(\d+p\.mov)z_h\1widthheightr   )	format_idr&   r9   r:   languagez[^a-zA-Z0-9] screenthumbruntimefadedposted)r   formatsr   	thumbnailr   r   r   pagemovie_titlezincludes/playlists/itunes.incc                     t        j                  dd|       } t        j                  dd|       } d }t        j                  j                  ||       } d| z  } | S )Nz(?s)<script[^<]*?>.*?</script>r=   z<img ([^<]*?)/?>z	<img \1/>c                 J    d| j                  d      j                  dd      z  S )NziTunes.playURL(%s);r   'z&#39;)groupreplace)ms    @/usr/lib/python3/dist-packages/yt_dlp/extractor/appletrailers.py_clean_jsonzDAppleTrailersIE._real_extract.<locals>.fix_html.<locals>._clean_json   s"    ,qwwqz/A/A$/PPP    z<html>%s</html>)resub_JSON_RE)srN   selfs     rM   fix_htmlz/AppleTrailersIE._real_extract.<locals>.fix_html   sT    8"a@A*L!<AQt}}k15A!A%AHrO   )transform_sourcez./div/ul/liz.//aonClickztrailer infor&   z.//imgz+(?P<minutes>[0-9]+):(?P<seconds>[0-9]{1,2})<   minutesseconds/_r   zincludes/settings/%s.jsonzDownloading settings jsonmetadataz_(\d*p\.mov)type)r&   formatr9   r:   videoz
User-AgentzQuickTime compatible (yt-dlp))	_typer   rC   r   r   rD   r   r   http_headersr'   )rb   r   entries)_match_valid_urlrJ   _download_webpage_search_regex_download_jsongetitemsappendrP   rQ   r   lowerr   r	   playlist_resultr   urljoin_download_xmlfindallfindattribrR   jsonloadsrK   searchintsplit
rpartition)'rT   r&   mobjr1   r   webpagefilm_id	film_datard   clip
clip_titlerC   versionversion_datasize	size_datar7   	page_dataplaylist_urlrU   docr'   lion_clicktrailer_info_jsontrailer_info	first_urlr   video_idrD   r   r@   rL   r   
trailer_idsettings_json_urlsettingsr`   
format_urls'   `                                      rM   _real_extractzAppleTrailersIE._real_extract^   s   $$S)

7#jj+((e4$$%<gyQ''CgM5 ( "	 G!gr2 !']
-1XXj"-E-K-K-M )G\+7+;+;GR+H+N+N+P 
i'mmE2"$4;T)B#%66/7C#H%0w1G%H&1)--2I&J(/( 	
 #+J(O(U(U(WW&'!%(!3!Htxx7H .txx	/B/WdhhwFW X#2488H3E#F#.  #6 "fb1I'')--:VWW&..s4ST
	   ux P++m, .	Bwwv--i8H $ 2 24==3;^!M::&78L$((/I )Es{RVVOR%G%M%M%OOH)007I&x088bAK"9-G		H'RAHAGGI$6 77#aggi>P:QQ"-b1<<SA!DJJLJ / 7 7=X[e=e f**+<jJefHG":.w7 VVOWfUmL
%$Vn(9)&*:;	   OO "$&** "A! E.	b  
 	
rO   N)__name__
__module____qualname__IE_NAME
_VALID_URL_TESTSrR   r    rO   rM   r   r      s   GuJB#
 :/  #(#-#'
 :/  #(#-#'
 :.  #&#-#'
 :-  "%#-#'
E-
4j I!
 @A F&
  @ ^OJFX +Ho
rO   r   c                       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  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 Zy)AppleTrailersSectionIEzappletrailers:section
just_addedz
Just Added)	feed_pathr   	exclusive	Exclusivejust_hdzJust HDmost_popzMost PopularstudioszMovie Studios)	justaddedr   justhdmostpopularmoviestudiosz;https?://(?:www\.)?trailers\.apple\.com/#section=(?P<id>%s)|z,http://trailers.apple.com/#section=justaddedr   )r   r   P   r.   z,http://trailers.apple.com/#section=exclusivez)http://trailers.apple.com/#section=justhdr   z.http://trailers.apple.com/#section=mostpopularr      z/http://trailers.apple.com/#section=moviestudiosr   c                    | j                  |      }| j                  d| j                  |   d   z  |      }|D cg c]  }| j                  d|d   z          }}| j	                  ||| j                  |   d         S c c}w )Nz5http://trailers.apple.com/trailers/home/feeds/%s.jsonr   zhttp://trailers.apple.comlocationr   )	_match_idrh   	_SECTIONS
url_resultrm   )rT   r&   sectionsection_dataerd   s         rM   r   z$AppleTrailersSectionIE._real_extract  s    ..%**CdnnU\F]^iFjj
 "# OO7!J-GH# # ##GWdnnW6Mg6VWW#s   A>N)	r   r   r   r   r   joinr   r   r   r   rO   rM   r   r      s    %G &!

 % 

 #

 $#

 #$
#I, PRURZRZ[dReeJ=!
   > 
   ;
   @#
   A$ 
  9#FJXrO   r   )rP   rs   commonr   compatr   utilsr   r   r	   r   r   r   rO   rM   <module>r      s:    	  ! $ @
m @
FFX] FXrO   