U
    g                     @   sd   d dl Z 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mZ G dd deZdS )    N   )PostProcessor   )	PopenPostProcessingErrorcheck_executable
cli_optionencodeArgumentencodeFilenameprepend_extensionshell_quotestr_or_nonec                   @   s<   e Zd ZdZdZdddZddd	Zejdd
dd Z	dS )SponSkrubPPZsponsZ	sponskrub NFc                 C   sp   t | | || _|| _t|p"d| _| || _|s@| d |sl| jd krl|rdt	d| dnt	dd S )Nr   zyt_dlp.postprocessor.SponSkrubPP support is deprecated and may be removed in a future version. Use yt_dlp.postprocessor.SponsorBlock and yt_dlp.postprocessor.ModifyChaptersPP insteadzsponskrub not found in ""zNsponskrub not found. Please install or provide the path using --sponskrub-path)
r   __init__forcecutoutr   argsget_exepathZdeprecation_warningr   )self
downloaderr   r   ZignoreerrorZcutr   Z	_from_cli r   B/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/postprocessor/sponskrub.pyr      s    zSponSkrubPP.__init__c                 C   s4   |rt |dgs0tj|| j}t |dgs0d S |S )Nz-h)r   osr   join	_exe_name)r   r   r   r   r   r   *   s
    zSponSkrubPP.get_exe)Zimagesc                 C   s  | j d krg |fS |d }tj t|s2g |fS |d  dkrT| d g |fS | jr~| js~|dds~| 	d g |fS | d| jrd	nd
  | jr| 	d |dds| 	d t
|| j}tj t|rtt| | j g}| js|dg7 }|t| jjdd7 }|t| j7 }|| j| jdd7 }|d|d ||g7 }dd |D }| dt|  tj|d| drd ntjd\}}}|st|| | d| jrdnd  nN|dkr| d n8t|  |   drdnd  pd!| g |fS )"NfilepathZextractor_keyZyoutubez2Skipping sponskrub since it is not a YouTube videoZ__real_downloadFzhSkipping sponskrub since the video was already downloaded. Use --sponskrub-force to run sponskrub anywayzTrying to %s sponsor sectionsremovemarkzHCutting out sponsor segments will cause the subtitles to go out of sync.zSIf sponskrub is run multiple times, unintended parts of the video could be cut out.z-chapterz-proxyproxy)Z
use_compatz--idc                 S   s   g | ]}t |qS r   )r	   ).0ir   r   r   
<listcomp>T   s     z#SponSkrubPP.run.<locals>.<listcomp>zsponskrub command line: Tverbose)textstdoutzSponsor sections have been %sremovedZmarked   z(No segments in the SponsorBlock databaseZunrecognisedr   z!sponskrub failed with error code )!r   r   existsr
   lowerZ	to_screenr   r   getZreport_warningr   	_temp_extr   r   Z_downloaderparamsshlexsplitr   Z_configuration_argsr   Zwrite_debugr   r   run	get_param
subprocessPIPEreplacer   strip
splitlines
startswith)r   ZinformationfilenameZtemp_filenamecmdr(   _
returncoder   r   r   r3   1   sR    




(
*zSponSkrubPP.run)r   NFFFF)r   )
__name__
__module____qualname__r/   r   r   r   r   Z_restrict_tor3   r   r   r   r   r      s   


r   )r   r1   r5   commonr   utilsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   <module>   s
   ,