U
    $Pfu
                     @   s<   d dl mZ d dlZd dlZddlmZ G dd deZdS )    )unicode_literalsN   )InfoExtractorc                   @   sp   e Zd ZdZde ZdZdeeef Zdddddd	d
iddd
ddd
ddd
dgZedd Z	dd Z
dS )CloudflareStreamIEz<(?:cloudflarestream\.com|(?:videodelivery|bytehighway)\.net)z&embed\.%s/embed/[^/]+\.js\?.*?\bvideo=z"[\da-f]{32}|[\w-]+\.[\w-]+\.[\w-]+z(?x)
                    https?://
                        (?:
                            (?:watch\.)?%s/|
                            %s
                        )
                        (?P<id>%s)
                    zchttps://embed.cloudflarestream.com/embed/we4g.fla9.latest.js?video=31c9291ab41fac05471db4e73aa11717Z 31c9291ab41fac05471db4e73aa11717mp4)idexttitleZskip_downloadT)urlZ	info_dictparamszChttps://watch.cloudflarestream.com/9df17203414fd1db3e3ed74abbe936c1)r
   Zonly_matchingzPhttps://cloudflarestream.com/31c9291ab41fac05471db4e73aa11717/manifest/video.mpdz`https://embed.videodelivery.net/embed/r4xu.fla9.latest.js?video=81d80727f3022488598f68d323c1ad5ec                 C   s"   dd t dtjtjf | D S )Nc                 S   s   g | ]}| d qS )r
   )group).0Zmobj r   I/tmp/pip-unpacked-wheel-7zdooeg3/youtube_dl/extractor/cloudflarestream.py
<listcomp>-   s   z4CloudflareStreamIE._extract_urls.<locals>.<listcomp>z=<script[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//%s(?:%s).*?)\1)refinditerr   	_EMBED_RE_ID_RE)Zwebpager   r   r   _extract_urls+   s    z CloudflareStreamIE._extract_urlsc                 C   s   |  |}d|krdnd}d||f }d|krN| t|dd |d }|d }| j|d	 |d
dddd}|| j|d |ddd | | |||d |dS )Nzbytehighway.net/zbytehighway.netzvideodelivery.netzhttps://%s/%s/.r   subzmanifest/video.Zm3u8r   Zm3u8_nativeZhlsF)Zm3u8_idfatalZmpdZdash)Zmpd_idr   zthumbnails/thumbnail.jpg)r   r	   Z	thumbnailformats)	Z	_match_idZ_parse_jsonbase64urlsafe_b64decodesplitZ_extract_m3u8_formatsextendZ_extract_mpd_formatsZ_sort_formats)selfr
   Zvideo_iddomainbase_urlZmanifest_base_urlr   r   r   r   _real_extract3   s@    
       
z CloudflareStreamIE._real_extractN)__name__
__module____qualname__Z
_DOMAIN_REr   r   Z
_VALID_URLZ_TESTSstaticmethodr   r!   r   r   r   r   r   
   s8   	 
r   )
__future__r   r   r   commonr   r   r   r   r   r   <module>   s   