a
    h`                     @   sP   d dl Z d dlZddlmZ ddlmZ ddlmZm	Z	m
Z
 G dd deZdS )	    N   )get_suitable_downloader)
FragmentFD   )ReExtractInfoupdate_url_queryurljoinc                   @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
DashSegmentsFDz
    Download segments in a DASH manifest. External downloaders can take over
    the fragment downloads by supporting the 'dash_frag_urls' protocol
    Zdashsegmentsc              	      s  d d  dv rd }n, dr,| d t | jd d|dkd}t } fd	d
 dg D }g }|pr gD ]0}t|d trtdddz | jdrdn
t	|d }W n t
y   d }Y n0 |dp||drdn|d|d}	|r| |	 n| |	| ||	d< d }
 d}|r<tj|}
| ||	|
}|r| d| j d|   t| d< || j| j}||   S ||	||g qt| j|ddd iS )NZhttp_dash_segments_generatorprotocol+Zis_livez"Live DASH videos are not supportedZdash_frag_urls-)r
   Z	to_stdoutc                    s   g | ]}i  |qS  r   ).0fmt	info_dictr   K/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/downloader/dash.py
<listcomp>       z0DashSegmentsFD.real_download.<locals>.<listcomp>requested_formats	fragmentsz#the stream needs to be re-extractedT)expectedtestr   filepathZis_from_start)filenameZliveZtotal_fragsstartextra_param_to_segment_url[z*] Fragment downloads will be delegated to Zis_fatalc                 S   s   | dkS )Nr   r   )idxr   r   r   <lambda>D   r   z.DashSegmentsFD.real_download.<locals>.<lambda>)splitgetZreport_errorr   paramstime
isinstancestrr   len	TypeErrorZ_prepare_external_frag_downloadZ _prepare_and_start_frag_downloadurllibparseparse_qs_get_fragmentsZ	to_screenFD_NAMEZget_basenamelistZydlreal_downloadappendZ&download_and_append_fragments_multiple)selfr   r   Zreal_downloaderZ
real_startr   argsr   fragment_countctxextra_queryr   Zfragments_to_downloadfdr   r   r   r.      sN    

 

zDashSegmentsFD.real_downloadc                 C   s2   t |r||n|}| jdr.tt|gS |S )Nr   )callabler"   r!   nextiter)r0   r   r3   r   r   r   _resolve_fragmentsF   s    z!DashSegmentsFD._resolve_fragmentsc           
      c   s   | d}| |d |}d}t|D ]f\}}|d7 }||d krDq&| d}	|	sh|sZJ t||d }	|rvt|	|}	|| d||	d	V  q&d S )
Nfragment_base_urlr   r   r   Zfragment_indexurlpathr2   )
frag_indexr2   indexr;   )r!   r9   	enumerater   r   )
r0   r   r3   r4   r:   r   r=   ifragmentZfragment_urlr   r   r   r+   J   s$    


zDashSegmentsFD._get_fragmentsN)__name__
__module____qualname____doc__r,   r.   r9   r+   r   r   r   r   r	   	   s
   5r	   )r#   urllib.parser(    r   rA   r   utilsr   r   r   r	   r   r   r   r   <module>   s
   