o
    i?                     @   s   d dl Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZmZ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 )    N   )InfoExtractor   )HEADRequest)ExtractorErrorbase_url
clean_htmlextract_attributesget_element_html_by_classget_element_html_by_idint_or_none
js_to_jsonmimetype2extsanitize_urltraverse_objtry_callurl_basenameurljoinc                   @   s  e Zd ZdZdZi 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i dddd d!d"d#d"d$d%d&d%d'd(d)d(d*d+d,d+d-d.d/d0d1d0d2d0d3d4d5d4d6d7d7d8d8d9d:Zd;d< Zd=d> Zd?d@ ZdAdB Z	dCS )D	RCSBaseIEz7[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}z[\w-]+-\d{10}zvideoamica-vh.akamaihdamicazmedia2-amica-it.akamaizedzcorrierevam-vh.akamaihdcorrierezmedia2vam-corriere-it.akamaizedzcormezzogiorno-vh.akamaihdcorrieredelmezzogiornoz+media2vam-mezzogiorno-corriere-it.akamaizedzcorveneto-vh.akamaihdcorrieredelvenetoz&media2vam-veneto-corriere-it.akamaizedzcorbologna-vh.akamaihdcorrieredibolognaz'media2vam-bologna-corriere-it.akamaizedzcorfiorentino-vh.akamaihdcorrierefiorentinoz*media2vam-fiorentino-corriere-it.akamaizedzcorinnovazione-vh.akamaihdcorriereinnovazionez%media2-gazzanet-gazzetta-it.akamaizedgazzanetzvideogazzanet-vh.akamaihdzvideogazzaworld-vh.akamaihd
gazzaworldzgazzettavam-vh.akamaihdgazzettazmedia2vam-gazzetta-it.akamaizedzvideoiodonna-vh.akamaihdiodonnazmedia2-leitv-it.akamaizedleitvzvideoleitv-vh.akamaihdzvideoliving-vh.akamaihdlivingz#media2-living-corriere-it.akamaizedzmedia2-oggi-it.akamaizedoggizvideooggi-vh.akamaihdzmedia2-quimamme-it.akamaizedquimammezquimamme-vh.akamaihdzvideorunning-vh.akamaihdrunningz"media2-style-corriere-it.akamaizedstylezstyle-vh.akamaihdzvideostyle-vh.akamaihdz media2-stylepiccoli-it.akamaizedstylepiccolizstylepiccoli-vh.akamaihdzdoveviaggi-vh.akamaihdviaggi
vivimilanoyoureporter)zmedia2-doveviaggi-it.akamaizedz'media2-vivimilano-corriere-it.akamaizedzvivimilano-vh.akamaihdzmedia2-youreporter-it.akamaizedc                 c   s    t |dddd fD ]n}|d }dD ]
\}}|||}qt|d }|dkrDd	|v rDtd
|}|rDd| j|d  |d }t |dsQ|dkrWd|v rW|dd}|dkred|v re|dd}|dkro|dd}|||ddV  qd S )NmediaProfile	mediaFilec                 S   s
   | dS )NmimeType)get)_v r0   H/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/rcs.py<lambda>H   s   
 z*RCSBaseIE._get_video_src.<locals>.<lambda>value))z#media2vam.corriere.it.edgesuite.net#media2vam-corriere-it.akamaized.net)z"media.youreporter.it.edgesuite.netz"media-youreporter-it.akamaized.net)z%corrierepmd.corriere.it.edgesuite.netz%corrierepmd-corriere-it.akamaized.net)z=media2vam-corriere-it.akamaized.net/fcs.quotidiani/vr/videos/zvideo.corriere.it/vr360/videos/)zhttp://zhttps://r,   m3u8z-vh.akamaihdz5(?:https?:)?//(?P<host>[\w\.\-]+)\.net/i(?P<path>.+)$zhttps://vod.rcsobjects.it/hls/hostpath)r*   geoblockingzfcs.quotidiani_!zvod.rcsobjectszvod-it.rcsobjectsvodz.csmilz.urlsetmp3r4   zvod.rcsobjects.it/corrierebitrate)typeurlr;   )r   replacer   research_MIGRATION_MAPgroupr-   )selfvideosourcer=   srtype_matchesr0   r0   r1   _get_video_srcF   s0   

 

zRCSBaseIE._get_video_srcc                 #   s    |D ]M}|d dkrqt dd|d }||d krq|   d= t fdd}| jt||d	d
| d}|s<q ||dt|j	dd d  V  qd S )Nvcodecnonez%(https?://[^/]+)/hls/([^?#]+?\.mp4).+z\g<1>/\g<2>r=   manifest_urlc                      s    d  ddS )N	format_idzhls-zhttps-)r>   r0   http_fr0   r1   r2   q   s    z0RCSBaseIE._create_http_formats.<locals>.<lambda>FzCheck filesize for )fatalnotehttpszContent-Length)rN   r=   protocolfilesize_approx)
r?   subcopyr   _request_webpager   updater   headersr-   )rC   m3u8_formatsvideo_idfhttp_urlrN   urlhr0   rO   r1   _create_http_formatsg   s.   zRCSBaseIE._create_http_formatsc                 c   s|    |D ]8}|d dkr&| j |d |dddd}|E d H  | ||E d H  q|d dkr;d	ddd
|d|d dV  qd S )Nr<   r5   r=   mp4hlsF)m3u8_idrQ   r:   	https-mp3rL   r;   )rN   extacodecrK   abrr=   )_extract_m3u8_formatsr`   r-   )rC   sourcesr\   rE   r[   r0   r0   r1   _create_formats   s$   
zRCSBaseIE._create_formatsc           
      C   s  |  |dd\}}d\}}t| j|st| j|r&d| d| }n`| ||}td|p5td|}|rf| j	t
|d|dd	pFi }|d
rS|d
  d}||dpZ|}}d| d| }n | jd||dd d}|r| t|dd|}||dp|}}|s| ||}| jd|d|d dtd}|st|}	|	rd|	t dS |std|||dt|dpt|dp| d||dp|t| | ||dS )Ncdnid)NNzhttps://video.z/video-json/divVideoPlayerzdata-configF)rQ   	newspaperz.ituuidz(?x)url\s*=\s*(["'])
                    (?P<url>
                        (?:https?:)?//video\.rcs\.it
                        /fragment-includes/video-includes/[^"']+?\.json
                    )\1;r=   )rB   defaultrS   schemez##start-video##z
video dataz##end-video##)rp   end_patterntransform_sourceurl_transparent)_typer=   ie_keyz Video data not found in the pagetitledescriptionhtmlDescriptionprovider)rl   
display_idrx   ry   uploaderformats)_match_valid_urlrB   r?   match_UUID_RE
_RCS_ID_RE_download_webpager   r
   _parse_jsonr	   r-   _search_regex_download_jsonr   _search_jsonr   RCSEmbedsIE_extract_urlrw   r   r   _html_search_metalistrj   rJ   )
rC   r=   rk   r\   r|   
video_datawebpagedata_configjson_urlembr0   r0   r1   _real_extract   sb   



zRCSBaseIE._real_extractN)
__name__
__module____qualname__r   r   rA   rJ   r`   rj   r   r0   r0   r0   r1   r      s    	
 !"#)!r   c                       sx   e Zd ZdZdgZddddddd	d
dddddddgZdddddd	d
dgZedd Ze	 fddZ
  ZS )r   a?  (?x)
                    https?://(?P<vid>video)\.
                    (?P<cdn>
                    (?:
                        rcs|
                        (?:corriere\w+\.)?corriere|
                        (?:gazzanet\.)?gazzetta
                    )\.it)
                    /video-embed/(?P<id>[^/=&\?]+?)(?:$|\?)a  (?x)
            (?:
                data-frame-src=|
                <iframe[^\n]+src=
            )
            (["'])
                (?P<url>(?:https?:)?//video\.
                    (?:
                        rcs|
                        (?:corriere\w+\.)?corriere|
                        (?:gazzanet\.)?gazzetta
                    )
                \.it/video-embed/.+?)
            \1z3https://video.rcs.it/video-embed/iodonna-0001585037 0faca97df525032bb9847f690bc3720cziodonna-0001585037ra   z6Sky Arte racconta Madonna nella serie "Artist to icon"z$md5:65b09633df9ffee57f48b39e34c9e067rcs.itrl   re   rx   ry   r}   r=   md5	info_dictzGhttps://video.gazzanet.gazzetta.it/video-embed/gazzanet-mo05-0000260789Tr=   only_matchingzJhttps://video.gazzetta.it/video-embed/49612410-00ca-11eb-bcd8-30d4253e0140zhttps://www.iodonna.it/video-iodonna/personaggi-video/monica-bellucci-piu-del-lavoro-oggi-per-me-sono-importanti-lamicizia-e-la-famiglia/ziodonna-0002033648uZ   Monica Bellucci: «Più del lavoro, oggi per me sono importanti l'amicizia e la famiglia»z$md5:daea6d9837351e56b1ab615c06bebac1)r=   r   c                 C   s   t | dd} tt| t| S )NrS   rq   )r   r   r   r   )r=   r0   r0   r1   _sanitize_url  s   zRCSEmbedsIE._sanitize_urlc                    s   t | jt ||S )N)mapr   super_extract_embed_urls)clsr=   r   	__class__r0   r1   r     s   zRCSEmbedsIE._extract_embed_urls)r   r   r   
_VALID_URL_EMBED_REGEX_TESTS_WEBPAGE_TESTSstaticmethodr   classmethodr   __classcell__r0   r0   r   r1   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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"d#d$gZd%S )&RCSIEa  (?x)https?://(?P<vid>video|viaggi)\.
                    (?P<cdn>
                    (?:
                        corrieredelmezzogiorno\.
                        |corrieredelveneto\.
                        |corrieredibologna\.
                        |corrierefiorentino\.
                    )?corriere\.it
                    |(?:gazzanet\.)?gazzetta\.it)
                    /(?!video-embed/)[^?#]+?/(?P<id>[^/\?]+)(?=\?|/$|$)zhttps://video.corriere.it/sport/formula-1/vettel-guida-ferrari-sf90-mugello-suo-fianco-c-elecrerc-bendato-video-esilarante/b727632a-f9d0-11ea-91b0-38d50a849abb 14946840dec46ecfddf66ba4eea7d2b2z$b727632a-f9d0-11ea-91b0-38d50a849abbra   uf   Vettel guida la Ferrari SF90 al Mugello e al suo fianco c'è Leclerc (bendato): il video è esilarantez$md5:3915ce5ebb3d2571deb69a5eb85ac9b5zCorriere Tvr   r   zhhttps://viaggi.corriere.it/video/norvegia-il-nuovo-ponte-spettacolare-sopra-la-cascata-di-voringsfossen/ f22a92d9e666e80f2fffbf2825359c81z$5b7cd134-e2c1-11ea-89b3-b56dd0df2aa2zFnorvegia-il-nuovo-ponte-spettacolare-sopra-la-cascata-di-voringsfossenuK   La nuova spettacolare attrazione in Norvegia: il ponte sopra Vøringsfossenz$md5:18b35a291f6746c0c8dacd16e5f5f4f8zDOVE Viaggirl   r|   re   rx   ry   r}   zhttps://video.corriere.it/cronaca/audio-telefonata-il-papa-becciu-santita-lettera-che-mi-ha-inviato-condanna/b94c0d20-70c2-11ed-9572-e4b947a0ebd2 aaffb08d02f2ce4292a4654694c78150z$b94c0d20-70c2-11ed-9572-e4b947a0ebd2r:   ui   L'audio della telefonata tra il Papa e Becciu: «Santità, la lettera che mi ha inviato è una condanna»z$md5:c0ddb61bd94a8d4e0d4bb9cda50a689brd   )rN   re   )rl   re   rx   ry   r}   r~   zIhttps://viaggi.corriere.it/video/milano-varallo-sesia-sul-treno-a-vapore/ 2dfdce7af249654ad27eeba03fe1e08dz$d8f6c8d0-f7d7-11e8-bfca-f74cf4634191z'milano-varallo-sesia-sul-treno-a-vaporez'Milano-Varallo Sesia sul treno a vaporez$md5:6348f47aac230397fe341a74f7678d53zhhttps://video.corriere.it/video-360/metro-copenaghen-tutta-italiana/a248a7f0-e2db-11e9-9830-af2de6b1f945Tr   Nr   r   r   r   r   r0   r0   r0   r1   r     sZ    
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ddd
dddddddddd
dgZdS )RCSVariousIEz(?x)https?://www\.
                    (?P<cdn>
                        leitv\.it|
                        youreporter\.it|
                        amica\.it
                    )/(?:[^/]+/)?(?P<id>[^/]+?)(?:$|\?|/)z,https://www.leitv.it/benessere/mal-di-testa/ 3b7a683d105a7313ec7513b014443631zleitv-0000125151zmal-di-testara   zDCervicalgia e mal di testa, il video con i suggerimenti dell'espertoz$md5:ae21418f34cee0b8d02a487f55bcabb5zleitv.itr   r   z6https://www.youreporter.it/fiume-sesia-3-ottobre-2020/ 3989b6d603482611a2abd2f32b79f739zyoureporter-0000332574zfiume-sesia-3-ottobre-2020zFiume Sesia 3 ottobre 2020z$md5:0070eef1cc884d13c970a4125063de55zyoureporter.itzghttps://www.amica.it/video-post/saint-omer-al-cinema-il-film-leone-dargento-che-ribalta-gli-stereotipi/ 187cce524dfd0343c95646c047375fc4zamica-0001225365zFsaint-omer-al-cinema-il-film-leone-dargento-che-ribalta-gli-stereotipizJ"Saint Omer": al cinema il film Leone d'argento che ribalta gli stereotipiz$md5:b1c8869c2dcfd6073a2a311ba0008aa8r   Nr   r0   r0   r0   r1   r   L  sB    r   )r?   commonr   
networkingr   utilsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r0   r0   r0   r1   <module>   s    @ 8>@