U
    Mf                     @   sT   d dl Z d dlZddlmZ ddlmZmZmZm	Z	 ddl
mZ G dd deZdS )	    N   )InfoExtractor   )ExtractorErrorparse_iso8601update_url_queryurl_or_none)traverse_objc                
   @   sZ   e Zd ZdZ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idgZdd ZdS )BoxIEzShttps?://(?:[^.]+\.)?app\.box\.com/s/(?P<shared_name>[^/?#]+)(?:/file/(?P<id>\d+))?zRhttps://mlssoccer.app.box.com/s/0evd2o3e08l60lr4ygukepvnkord1o1x/file/510727257538Z 1f81b2fd3960f38a40a3b8823e5fcd43Z510727257538Zmp4z7Garber   St. Louis will be 28th MLS team  +scarving.mp4 i&\]Z20190820Z	235196876)idexttitleuploader	timestampZupload_dateuploader_idZskip_downloadzdash fragment too small)urlmd5	info_dictparamsz=https://utexas.app.box.com/s/2x6vanv85fdl8j2eqlcxmv0gp1wvps6eZ787379022466z%Webinar recording: Take the Leap!.mp4zPatricia MoseleiO`Z20210315Z	239068974)r   r   r   c              	   C   s  |  | \}}| ||p|}|sp| d|d|}t|dthfpHi }|ddkrdtdddt|d	 }| d
|d|d }| j	d|dt
d|gi d|d| dd| d }d| }	| j	d| |dd| d|	 ddddid}
|
d }||	d }g }t|
d!d"d#d$ d%d&thfD ]L}t|d'd(|}| ||}|D ]}tj|j|d)< qH|| q"|
d*p~i }||||
d+pd |dt|
d,|d-d.S )/NzBox\.postStreamData\s*=zBox post-stream dataz/app-api/enduserapp/shared-itemZitemTypefilez$The requested resource is not a fileT)expectedZitemIDzBox\.config\s*=z
Box configZrequestTokenz6https://app.box.com/app-api/enduserapp/elements/tokenszDownloading token JSON metadataZfileIDszapplication/jsonzsharedName=)zContent-TypezX-Request-TokenzX-Box-EndUser-API)dataheadersreadzhttps://app.box.com/s/zhttps://api.box.com/2.0/files/zDownloading file JSON metadatazBearer zshared_link=z[dash])AuthorizationZBoxApizX-Rep-Hintsfieldszvauthenticated_download_url,created_at,created_by,description,extension,is_download_available,name,representations,size)r   queryname)access_tokenshared_linkZrepresentationsentriesc                 S   s   |d dkS )NZrepresentationZdash )_vr"   r"   8/tmp/pip-unpacked-wheel-zk9bgjdq/yt_dlp/extractor/box.py<lambda>W       z%BoxIE._real_extract.<locals>.<lambda>contentZurl_templatez{+asset_path}zmanifest.mpdZextra_param_to_segment_urlZ
created_bydescriptionZ
created_atr   )r   r   formatsr)   r   r   r   )Z_match_valid_urlgroupsZ_download_webpageZ_search_jsonr	   dictgetr   strZ_download_jsonjsondumpsencoder   r   replaceZ_extract_mpd_formatsurllibparseurlparser   extendr   )selfr   Zshared_nameZfile_idZwebpageZpost_stream_dataZshared_itemZrequest_tokenr   r    fr   r   r*   Zurl_tmplZmanifest_urlZfmtsfmtZcreatorr"   r"   r%   _real_extract+   s              	    
zBoxIE._real_extractN)__name__
__module____qualname__Z
_VALID_URLZ_TESTSr:   r"   r"   r"   r%   r
      s4   		r
   )r/   urllib.parser3   commonr   utilsr   r   r   r   Zutils.traversalr	   r
   r"   r"   r"   r%   <module>   s
   