o
    i?%                     @   sx   d dl Z d dl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 G dd deZG dd	 d	eZG d
d deZdS )    N   )InfoExtractor   )ExtractorErrordetermine_extextract_attributesint_or_noneparse_qssmuggle_urlunescapeHTMLunsmuggle_urlc                   @   sP   e Zd ZdZdZedd ZedddZdd	 Z	dd
dZ
dd Zdd ZdS )GlomexBaseIEzhttps://player.glomex.com/z:https://integration-cloudfront-eu-west-1.mes.glomex.cloud/c                 C   s   |d u r| S t | d|iS )Norigin)r
   )url
origin_url r   K/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/glomex.py_smuggle_origin_url   s   z GlomexBaseIE._smuggle_origin_urlNc                 C   s*   d|p| j i}t||d\}}||d fS )Nr   )default)_DEFAULT_ORIGIN_URLr   )clsr   fallback_origin_urldefaultsunsmuggled_urldatar   r   r   _unsmuggle_origin_url   s   z"GlomexBaseIE._unsmuggle_origin_urlc                 C   s(   ddddd}| dd }||dS )	Nvideoplaylistzrelated videos playlistzcurated playlist)vplrlcl-r   zunknown type)splitget)selfvideo_id_VIDEOID_TYPESprefixr   r   r   _get_videoid_type!   s   zGlomexBaseIE._get_videoid_typec                 C   sB   |||p| j d}| |}| j| j|d| dd| d|dS )N)integration_idplaylist_idcurrent_urlzDownloading z JSONzUnable to download )query)r   r)   _download_json_API_URL)r%   r&   integrationr,   r-   video_id_typer   r   r   _download_api_data+   s   

zGlomexBaseIE._download_api_datac                    s\     ||}|d }|std  fdd|D }t|dkr(|d S  |S )Nvideoszno videos found for c                    s   g | ]}  |qS r   )_extract_api_data).0r   r%   r&   r   r   
<listcomp>=   s    z?GlomexBaseIE._download_and_extract_api_data.<locals>.<listcomp>r   r   )r2   r   lenplaylist_result)r%   r&   r0   r,   api_datar3   r   r6   r   _download_and_extract_api_data8   s    z+GlomexBaseIE._download_and_extract_api_datac              	   C   s"  | ddkr| j|d d g i }}|d  D ]-\}}t|}|dkr?| j||d|dd	\}}	|| | j|	|d
 q|||d q| drX|D ]}
|d |
d< qO| dp^g | dpdi g }dd |D }| | | dpy|| d| d|t	| d| d||dS )N
error_codecontentGeoblockedgeo_locations)	countriessourcem3u8mp4F)m3u8_idfatal)target)r   	format_idlanguageimagesimagec                 S   s4   g | ]}| d r| d|d   ddddqS )r   idz/profile:player-960x540i  i  )rJ   r   widthheight)r$   )r5   rI   r   r   r   r7   W   s    

z2GlomexBaseIE._extract_api_data.<locals>.<listcomp>clip_idtitledescriptionclip_duration
created_at)rJ   rN   rO   
thumbnailsduration	timestampformats	subtitles)
r$   raise_geo_restricteditemsr   #_extract_m3u8_formats_and_subtitlesextend_merge_subtitlesappend_remove_duplicate_formatsr   )r%   r   r&   rU   subsrF   
format_urlextformats_subs_fmtrH   rR   r   r   r   r4   @   sB   





zGlomexBaseIE._extract_api_dataN)__name__
__module____qualname__r   r/   staticmethodr   classmethodr   r)   r2   r;   r4   r   r   r   r   r      s    


r   c                
   @   sH   e Zd ZdZdZdZdZddddd	d
ddddddidgZdd ZdS )GlomexIEglomexzGlomex videosz1https?://video\.glomex\.com/[^/]+/(?P<id>v-[^-]+)19syy24xjn1oqlpczehttps://video.glomex.com/sport/v-cb24uwg77hgh-nach-2-0-sieg-guardiola-mit-mancity-vor-naechstem-titelzv-cb24uwg77hghrB   u8   Nach 2:0-Sieg: Guardiola mit ManCity vor nächstem Titelz$md5:1ea6b6caff1443fcbbba159e432eedb8is  +re:https?://i[a-z0-9]thumbs\.glomex\.com/.+i颍`20210501rJ   r`   rN   rO   rS   	thumbnailrT   upload_dateskip_downloadrA   r   	info_dictparamsc                 C   s(   |  |}| t|| j|t |S rd   )	_match_id
url_resultGlomexEmbedIEbuild_player_url_INTEGRATION_IDie_key)r%   r   r&   r   r   r   _real_extract   s
   
zGlomexIE._real_extractN)	re   rf   rg   IE_NAMEIE_DESC
_VALID_URLrz   _TESTSr|   r   r   r   r   rj   k   s$    
rj   c                
   @   s   e Zd ZdZdZdZeeddZ	de	 dZ
dd	d
dddddddddiddddidddddiddgZddd
d d!d"dd#d$d%ddidgZed-d'd(Zed)d* Zd+d, Zd&S ).rx   zglomex:embedzGlomex embedded videosz4//player.glomex.com/integration/1/iframe-player.htmlz/1/z/[^/]/zhttps?:z$\?([^#]+&)?playlistId=(?P<id>[^#&]+)zvhttps://player.glomex.com/integration/1/iframe-player.html?integrationId=4059a013k56vb2yd&playlistId=v-cfa6lye0dkdd-sfzv-cfa6lye0dkdd-sfrB   uu   Φώφη Γεννηματά: Ο επικήδειος λόγος του 17χρονου γιου της, Γιώργουrm   iCyai 20211027z$md5:e741185fc309310ff5d0c789b437be66)rJ   r`   rN   rp   rT   rS   rq   rO   rr   rA   rs   zhttps://player.glomex.com/integration/1/iframe-player.html?origin=fullpage&integrationId=19syy24xjn1oqlpc&playlistId=rl-vcb49w1fb592p&playlistIndex=0rJ   zrl-vcb49w1fb592pd   )r   rt   playlist_countzthttps://player.glomex.com/integration/1/iframe-player.html?playlistId=cl-bgqaata6aw8x&integrationId=19syy24xjn1oqlpczcl-bgqaata6aw8xr   )r   rt   playlist_mincountzwhttps://www.skai.gr/news/world/iatrikos-syllogos-tourkias-to-turkovac-aplo-dialyma-erntogan-eiste-apateones-kai-pseyteszv-ch2nkhcirwc9-sfu   Ιατρικός Σύλλογος Τουρκίας: Το Turkovac είναι ένα απλό διάλυμα –Ερντογάν: Είστε απατεώνες και ψεύτεςz$md5:8b517a61d577efe7e36fde72fd535995i i[-a20220111ro   Nc                 C   s,   t j||d}| d| j d| |S )N)
playlistIdintegrationIdzhttps:?)urllibparse	urlencoder   _BASE_PLAYER_URL)r   r&   r0   r   query_stringr   r   r   ry      s
   zGlomexEmbedIE.build_player_urlc                 c   s   d}d| d| j  d}t||D ]}t|d}| |r(| ||V  qd| d}t||D ]}t|d}|d	rT|d
rT| 	|d
 |d	 |V  q5d| d}td|D ]$}|d}t
|d |}	|	ssqat
|d |}
|
r| 	|
|	|V  qad S )Nz["\']z((?x)
            <iframe[^>]+?src=(?P<q>z&)(?P<url>
                (?:https?:)?z&\?(?:(?!(?P=q)).)+
            )(?P=q)r   zX(?x)
            <glomex-player [^>]+?>|
            <div[^>]* data-glomex-player=(?P<q>z)true(?P=q)[^>]*>r   zdata-integration-idzdata-playlist-idzN(?x)
            (?P<is_js>dataset\.)?%s\s*(?(is_js)=|:)\s*
            (?P<q>z!)(?P<id>(?:(?!(?P=q)).)+)(?P=q)\sz(?x)<script[^<]*>.+?</script>r   r   )_BASE_PLAYER_URL_RErefinditerr   groupsuitabler   r   r$   ry   search)r   r   webpagequot_reregexmobj	embed_urlattrsscriptr*   r+   r   r   r   _extract_embed_urls   sB   

z!GlomexEmbedIE._extract_embed_urlsc                 C   sL   |  |\}}| |}t|dd gd }|stddd| |||S )Nr   r   zNo integrationId in URLT)expected)r   rv   r	   r$   r   r;   )r%   r   r   r+   r0   r   r   r   r|      s   
zGlomexEmbedIE._real_extractrd   )re   rf   rg   r}   r~   r   r   escapereplacer   r   r   _WEBPAGE_TESTSri   ry   r   r|   r   r   r   r   rx      s\    


"rx   )r   urllib.parser   commonr   utilsr   r   r   r   r	   r
   r   r   r   rj   rx   r   r   r   r   <module>   s    (Z