U
    g?                     @   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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&Zdd Zdd Zdd Zdd  Z	d!S )"	RCSBaseIEz7[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}z[\w-]+-\d{10}ZamicaZcorriereZcorrieredelmezzogiornoZcorrieredelvenetoZcorrieredibolognaZcorrierefiorentinoZcorriereinnovazioneZgazzanetZ
gazzaworldZgazzettaZiodonnaZleitvZlivingZoggiZquimammeZrunningstyleZstylepiccoliZviaggiZ
vivimilanoZyoureporter)&zvideoamica-vh.akamaihdzmedia2-amica-it.akamaizedzcorrierevam-vh.akamaihdzmedia2vam-corriere-it.akamaizedzcormezzogiorno-vh.akamaihdz+media2vam-mezzogiorno-corriere-it.akamaizedzcorveneto-vh.akamaihdz&media2vam-veneto-corriere-it.akamaizedzcorbologna-vh.akamaihdz'media2vam-bologna-corriere-it.akamaizedzcorfiorentino-vh.akamaihdz*media2vam-fiorentino-corriere-it.akamaizedzcorinnovazione-vh.akamaihdz%media2-gazzanet-gazzetta-it.akamaizedzvideogazzanet-vh.akamaihdzvideogazzaworld-vh.akamaihdzgazzettavam-vh.akamaihdzmedia2vam-gazzetta-it.akamaizedzvideoiodonna-vh.akamaihdzmedia2-leitv-it.akamaizedzvideoleitv-vh.akamaihdzvideoliving-vh.akamaihdz#media2-living-corriere-it.akamaizedzmedia2-oggi-it.akamaizedzvideooggi-vh.akamaihdzmedia2-quimamme-it.akamaizedzquimamme-vh.akamaihdzvideorunning-vh.akamaihdz"media2-style-corriere-it.akamaizedzstyle-vh.akamaihdzvideostyle-vh.akamaihdz media2-stylepiccoli-it.akamaizedzstylepiccoli-vh.akamaihdzdoveviaggi-vh.akamaihdz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 ]}|d }dD ]\}}|||}q$t|d }|dkrd	|krtd
|}|rd| j|d  |d }t |ds|dkrd|kr|dd}|dkrd|kr|dd}|dkr|dd}|||ddV  qd S )NmediaProfileZ	mediaFilec                 S   s
   | dS )NmimeType)get)_v r   8/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/rcs.py<lambda>H       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   Zgeoblockingzfcs.quotidiani_!zvod.rcsobjectszvod-it.rcsobjectsZvodz.csmilz.urlsetmp3r    zvod.rcsobjects.it/corrierebitrate)typeurlr%   )r   replacer   research_MIGRATION_MAPgroupr   )selfvideosourcer'   srtype_matchesr   r   r   _get_video_srcF   s6      
 
zRCSBaseIE._get_video_srcc                 #   s   |D ]}|d dkrqt dd|d }||d kr6q|   d= t fdd}| jt||d	d
| d}|svq ||dt|j	dd d  V  qd S )Nvcodecnonez%(https?://[^/]+)/hls/([^?#]+?\.mp4).+z\g<1>/\g<2>r'   Zmanifest_urlc                      s    d  ddS )N	format_idzhls-zhttps-)r(   r   Zhttp_fr   r   r   q   r   z0RCSBaseIE._create_http_formats.<locals>.<lambda>FzCheck filesize for )fatalZnotehttpszContent-Length)r7   r'   protocolZfilesize_approx)
r)   subcopyr   Z_request_webpager   updater   headersr   )r-   m3u8_formatsvideo_idfZhttp_urlr7   Zurlhr   r8   r   _create_http_formatsg   s*    zRCSBaseIE._create_http_formatsc                 c   sz   |D ]p}|d dkrJ| 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&   r!   r'   mp4ZhlsF)Zm3u8_idr9   r$   	https-mp3r6   r%   )r7   extZacodecr5   Zabrr'   )Z_extract_m3u8_formatsrC   r   )r-   sourcesrA   r/   r@   r   r   r   _create_formats   s&        
zRCSBaseIE._create_formatsc           
      C   s  |  |dd\}}d\}}t| j|s:t| j|rLd| d| }n| ||}td|pjtd|}|r| j	t
|d|dd	pi }|d
r|d
  d}||dp| }}d| d| }nD| jd||dd d}|r| t|dd|}||dp
| }}|s`| ||}| jd|d|d dtd}|s`t|}	|	r`d|	t dS |sntd|||dt|dpt|dp| d||dp|t| | ||dS )Ncdnid)NNzhttps://video.z/video-json/ZdivVideoPlayerzdata-configF)r9   Z	newspaperz.ituuidz(?x)url\s*=\s*(["'])
                    (?P<url>
                        (?:https?:)?//video\.rcs\.it
                        /fragment-includes/video-includes/[^"']+?\.json
                    )\1;r'   )r,   defaultr:   schemez##start-video##z
video dataz##end-video##)rL   Zend_patternZtransform_sourceZurl_transparent)_typer'   ie_keyz Video data not found in the pagetitledescriptionZhtmlDescriptionZprovider)rJ   
display_idrQ   rR   uploaderformats)Z_match_valid_urlr,   r)   match_UUID_RE
_RCS_ID_REZ_download_webpager   r
   Z_parse_jsonr	   r   Z_search_regexZ_download_jsonr   Z_search_jsonr   RCSEmbedsIEZ_extract_urlrP   r   r   Z_html_search_metalistrH   r4   )
r-   r'   rI   rA   rS   Z
video_datawebpageZdata_configZjson_urlZembr   r   r   _real_extract   st     
        

zRCSBaseIE._real_extractN)
__name__
__module____qualname__rW   rX   r+   r4   rC   rH   r\   r   r   r   r   r      sZ   )!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 )rY   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-0001585037Z 0faca97df525032bb9847f690bc3720cziodonna-0001585037rD   z6Sky Arte racconta Madonna nella serie "Artist to icon"z$md5:65b09633df9ffee57f48b39e34c9e067rcs.itrJ   rF   rQ   rR   rT   r'   md5	info_dictzGhttps://video.gazzanet.gazzetta.it/video-embed/gazzanet-mo05-0000260789Tr'   Z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'   rd   c                 C   s   t | dd} tt| t| S )Nr:   rM   )r   r   r   r   )r'   r   r   r   _sanitize_url  s    zRCSEmbedsIE._sanitize_urlc                    s   t | jt ||S )N)maprf   super_extract_embed_urls)clsr'   r[   	__class__r   r   ri     s    zRCSEmbedsIE._extract_embed_urls)r]   r^   r_   
_VALID_URLZ_EMBED_REGEX_TESTSZ_WEBPAGE_TESTSstaticmethodrf   classmethodri   __classcell__r   r   rk   r   rY      s<   	
rY   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-38d50a849abbZ 14946840dec46ecfddf66ba4eea7d2b2z$b727632a-f9d0-11ea-91b0-38d50a849abbrD   uf   Vettel guida la Ferrari SF90 al Mugello e al suo fianco c'è Leclerc (bendato): il video è esilarantez$md5:3915ce5ebb3d2571deb69a5eb85ac9b5zCorriere Tvra   rb   zhhttps://viaggi.corriere.it/video/norvegia-il-nuovo-ponte-spettacolare-sopra-la-cascata-di-voringsfossen/Z 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rJ   rS   rF   rQ   rR   rT   zhttps://video.corriere.it/cronaca/audio-telefonata-il-papa-becciu-santita-lettera-che-mi-ha-inviato-condanna/b94c0d20-70c2-11ed-9572-e4b947a0ebd2Z 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:c0ddb61bd94a8d4e0d4bb9cda50a689brE   )r7   rF   )rJ   rF   rQ   rR   rT   rU   zIhttps://viaggi.corriere.it/video/milano-varallo-sesia-sul-treno-a-vapore/Z 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-af2de6b1f945Tre   Nr]   r^   r_   rm   rn   r   r   r   r   rr     sX   
rr   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/Z 3b7a683d105a7313ec7513b014443631zleitv-0000125151zmal-di-testarD   zDCervicalgia e mal di testa, il video con i suggerimenti dell'espertoz$md5:ae21418f34cee0b8d02a487f55bcabb5zleitv.itrs   rb   z6https://www.youreporter.it/fiume-sesia-3-ottobre-2020/Z 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/Z 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`   Nrt   r   r   r   r   ru   L  s@   ru   )r)   commonr   Z
networkingr   utilsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rY   rr   ru   r   r   r   r   <module>   s   @ 8>@