
    VGh'                     h    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	  G d de      Z
 G d d	e      Zy)
    N   )InfoExtractor   )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| d|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                   j#                  |d      } fd } j%                  |||!      }g }|j'                  d"      D ]  }|j)                  d#      j*                  d$   } j                   j,                  |d%      }t/        j0                  |      }|j                  d&      }|sh|d
   }|dz   t        j                  dd|      j                         z   }|j)                  d'      j*                  d   }|d   j3                  dd      }|d   }t        j4                  d(|      } d }!| r8d)t7        | j                  d*            z  t7        | j                  d+            z   }!|j9                  d,      d-   j;                  d.      d/   j                         }"t        j                   j#                  |d0|" d      }# j	                  |#|"d1      }$g }|$d2   d   D ]M  }%t        j                  d3d|%d         }&|j                  |&|%d4   t        |%d         t        |%d         d5       O |j                  d6||||!|||d7d8id9	        d:||d;S )<NmoviecompanyzFilmId\s*=\s*'(\d+)'zfilm idz.http://trailers.apple.com/trailers/feeds/data/z.jsonF)fatalclipsr   versionssizessrc-z_(\d+p\.mov)z_h\1widthheightr   )	format_idr%   r8   r9   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|  dS )Nz(?s)<script[^<]*?>.*?</script>r<   z<img ([^<]*?)/?>z	<img \1/>c                 b    dj                  | j                  d      j                  dd            S )NziTunes.playURL({});r   'z&#39;)formatgroupreplace)ms    g/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/appletrailers.py_clean_jsonzDAppleTrailersIE._real_extract.<locals>.fix_html.<locals>._clean_json   s(    ,33AGGAJ4F4FtW4UVV    z<html>z</html>)resub_JSON_RE)srN   selfs     rM   fix_htmlz/AppleTrailersIE._real_extract.<locals>.fix_html   sT    8"a@A*L!<AWt}}k15AA3g&&rO   )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/zDownloading settings jsonmetadataz_(\d*p\.mov)type)r%   rI   r8   r9   videoz
User-AgentzQuickTime compatible (yt-dlp))	_typer   rB   r   r   rC   r   r   http_headersr&   )ra   r   entries)_match_valid_urlrJ   _download_webpage_search_regex_download_jsongetitemsappendrP   rQ   r   lowerr   r   playlist_resulturllibparseurljoin_download_xmlfindallfindattribrR   jsonloadsrK   searchintsplit
rpartition)'rT   r%   mobjr0   r   webpagefilm_id	film_datarc   clip
clip_titlerB   versionversion_datasize	size_datar6   	page_dataplaylist_urlrU   docr&   lion_clicktrailer_info_jsontrailer_info	first_urlr   video_idrC   r   r?   rL   r   
trailer_idsettings_json_urlsettingsfmt
format_urls'   `                                      rM   _real_extractzAppleTrailersIE._real_extract^   s   $$S)

7#jj+((e4$$%<gyQ''<WIUK5 ( "	 G!gr2 !']
-1XXj"-E-K-K-M )G\+7+;+;GR+H+N+N+P 
i'mmE2"$,39AdV)<#%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||++C1PQ		'   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 & 4 4S<NzlZ_:` a**+<jJefHG
+G4 VVOWc%jI
%!&k(W6)#h-8	   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n
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j                  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 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>{})|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                  | j                  |   d         |      }|D cg c]  }| j	                  d|d   z          }}| j                  ||| j                  |   d         S c c}w )Nz5http://trailers.apple.com/trailers/home/feeds/{}.jsonr   zhttp://trailers.apple.comlocationr   )	_match_idrg   rI   	_SECTIONS
url_resultrl   )rT   r%   sectionsection_dataerc   s         rM   r   z$AppleTrailersSectionIE._real_extract  s    ..%**CJJ4>>ZaKbcnKop
 "# OO7!J-GH# # ##GWdnnW6Mg6VWW#s   B
N)
r   r   r   r   r   rI   joinr   r   r   r   rO   rM   r   r      s    %G &!

 % 

 #

 $#

 #$
#I, PVVWZW_W_`iWjkJ=!
   > 
   ;
   @#
   A$ 
  9#FJXrO   r   )rt   rP   urllib.parserm   commonr   utilsr   r   r   r
   r   r   rO   rM   <module>r      s:     	  ! 
m 
DFX] FXrO   