o
    i                     @   sd   d dl mZ ddl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 )   )InfoExtractor   )ExtractorError
clean_htmlclean_podcast_urlint_or_nonestr_or_nonetry_geturl_or_nonec                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )StitcherBaseIEz2https?://(?:www\.)?stitcher\.com/(?:podcast|show)/c                 C   s:   | j d| ||d}t|dd }|rt|dd|d S )Nzhttps://api.prod.stitcher.com/)queryc                 S   s   | d d d S )Nerrors    message xr   r   M/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/stitcher.py<lambda>   s    z*StitcherBaseIE._call_api.<locals>.<lambda>T)expecteddata)_download_jsonr	   r   )selfpathvideo_idr   resperror_massager   r   r   	_call_api   s   zStitcherBaseIE._call_apic                 C      t |dp
|dS )Nhtml_descriptiondescription)r   get)r   r   r   r   r   _extract_description      z#StitcherBaseIE._extract_descriptionc                 C   r   )N	audio_urlguid)r
   r!   )r   episoder   r   r   _extract_audio_url   r#   z!StitcherBaseIE._extract_audio_urlc                 C   s   | d| ddS )Nimage_base_urltitle)	thumbnailseries)r!   )r   showr   r   r   _extract_show_info   s   z!StitcherBaseIE._extract_show_infoc                 C   sp   t |d |d|d  | |t|dt|dt|dt|dt|dd	
}|| |S )
Nidslugr)   durationnonedate_publishedseason	season_id)
r.   
display_idr)   r    r0   urlvcodec	timestampseason_numberr4   )strr!   stripr"   r   r   r   update)r   r&   r$   	show_infoinfor   r   r   _extract_episode%   s   


zStitcherBaseIE._extract_episodeN)	__name__
__module____qualname___VALID_URL_BASEr   r"   r'   r-   r?   r   r   r   r   r      s    	r   c                   @   sx   e Zd Zejd Zdddddddd	d
ddd	ddddddddd	dddidddddddddddgZdd Zd S )!
StitcherIEz1(?:[^/]+/)+e(?:pisode)?/(?:[^/#?&]+-)?(?P<id>\d+)zMhttp://www.stitcher.com/podcast/the-talking-machines/e/40789481?autoplay=true e9635098e0da10b21a0e2b85585530f640789481mp3z,Machine Learning Mastery and Cancer Clustersz$md5:547adb4081864be114ae3831b4c2b42fiD  zre:^https?://.*\.jpg20151008ihVTalking Machines)	r.   extr)   r    r0   r*   upload_dater8   r+   )r6   md5	info_dictzihttp://www.stitcher.com/podcast/panoply/vulture-tv/e/the-rare-hourlong-comedy-plus-40846275?autoplay=true40846275zthe-rare-hourlong-comedy-pluszThe CW's 'Crazy Ex-Girlfriend'z$md5:04f1e2f98eb3f5cbb094cea0f9e19b17i  )r.   r5   rJ   r)   r    r0   r*   skip_downloadTzPage Not Found)r6   rM   paramsskipzPhttp://www.stitcher.com/podcast/marketplace-on-stitcher/e/40910226?autoplay=truer6   only_matchingz~http://www.stitcher.com/podcast/panoply/getting-in/e/episode-2a-how-many-extracurriculars-should-i-have-40876278?autoplay=truezKhttps://www.stitcher.com/show/threedom/episode/circles-on-a-stick-200212584c                 C   sf   |  |}| d|d|i}|d d }| |}|s|   t|dd tp(i }| ||| |S )Nzshows/episodesepisode_idsepisodesr   c                 S      | d d S Nshowsr   r   r   r   r   r   r   i       z*StitcherIE._real_extract.<locals>.<lambda>)	_match_idr   r'   raise_login_requiredr	   dictr?   r-   )r   r6   audio_idr   r&   r$   r,   r   r   r   _real_extracta   s   


zStitcherIE._real_extractNr@   rA   rB   r   rC   
_VALID_URL_TESTSr^   r   r   r   r   rD   6   sN    

)rD   c                   @   s<   e Zd Zejd Zdddddddd	d
dgZdd ZdS )StitcherShowIEz(?P<id>[^/#?&]+)/?(?:[?#&]|$)z4http://www.stitcher.com/podcast/the-talking-machineszthe-talking-machinesrI   z$md5:831f0995e40f26c10231af39cf1ebf0b)r.   r)   r    j   )r6   rM   playlist_mincountz2https://www.stitcher.com/show/the-talking-machinesTrR   c           	      C   s   |  |}| d| d|ddi}t|dd tpi }| |}g }|dp)g D ]}| |}|s4q*|| ||| q*| 	|||d| 
|S )	Nzsearch/show/z/allEpisodescounti'  c                 S   rV   rW   r   r   r   r   r   r      rY   z.StitcherShowIE._real_extract.<locals>.<lambda>rU   r)   )rZ   r   r	   r\   r-   r!   r'   appendr?   playlist_resultr"   )	r   r6   	show_slugr   r,   r=   entriesr&   r$   r   r   r   r^   }   s    


zStitcherShowIE._real_extractNr_   r   r   r   r   rb   n   s    
	rb   N)commonr   utilsr   r   r   r   r   r	   r
   r   rD   rb   r   r   r   r   <module>   s
    $)8