
    yf                         d dl mZ 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e      Z G d de      Z G d	 d
e      Zy)   )InfoExtractor   )
compat_str)
clean_htmlclean_podcast_urlExtractorErrorint_or_nonestr_or_nonetry_geturl_or_nonec                   .    e Zd ZdZd Zd Zd Zd Zd Zy)StitcherBaseIEz2https?://(?:www\.)?stitcher\.com/(?:podcast|show)/c                 r    | j                  d|z   ||      }t        |d       }|rt        |d      |d   S )Nzhttps://api.prod.stitcher.com/)queryc                     | d   d   d   S )Nerrors    message xs    ;/usr/lib/python3/dist-packages/yt_dlp/extractor/stitcher.py<lambda>z*StitcherBaseIE._call_api.<locals>.<lambda>   s    (Ay0I     T)expecteddata)_download_jsonr   r   )selfpathvideo_idr   resperror_massages         r   	_call_apizStitcherBaseIE._call_api   sM    "",t3E # #  &IJ >>F|r   c                 \    t        |j                  d      xs |j                  d            S )Nhtml_descriptiondescription)r   get)r   r   s     r   _extract_descriptionz#StitcherBaseIE._extract_description   s%    $((#56Q$((=:QRRr   c                 \    t        |j                  d      xs |j                  d            S )N	audio_urlguid)r   r'   )r   episodes     r   _extract_audio_urlz!StitcherBaseIE._extract_audio_url   s$    7;;{3Jw{{67JKKr   c                 H    |j                  d      |j                  d      dS )Nimage_base_urltitle)	thumbnailseries)r'   )r   shows     r   _extract_show_infoz!StitcherBaseIE._extract_show_info    s%    "23hhw'
 	
r   c                    t        |d         |j                  d      |d   j                         | j                  |      t	        |j                  d            t        |      dt	        |j                  d            t	        |j                  d            t        |j                  d            d	
}|j                  |       |S )
Nidslugr0   durationnonedate_publishedseason	season_id)
r6   
display_idr0   r&   r8   urlvcodec	timestampseason_numberr<   )r   r'   stripr(   r	   r   r
   update)r   r,   r*   	show_infoinfos        r   _extract_episodezStitcherBaseIE._extract_episode&   s    WT]+!++f-W%++-44W=#GKK
$;<$Y/$W[[1A%BC(X)>?$W[[%=>
 	Ir   N)	__name__
__module____qualname___VALID_URL_BASEr#   r(   r-   r4   rF   r   r   r   r   r      s"    KOSL
r   r   c                       e Zd Zej                  dz   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 Zy) 
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)	r6   extr0   r&   r8   r1   upload_dater@   r2   )r>   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  )r6   r=   rR   r0   r&   r8   r1   skip_downloadTzPage Not Found)r>   rU   paramsskipzPhttp://www.stitcher.com/podcast/marketplace-on-stitcher/e/40910226?autoplay=truer>   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                    | j                  |      }| j                  d|d|i      }|d   d   }| j                  |      }|s| j                          t	        |d t
              xs i }| j                  ||| j                  |            S )Nzshows/episodesepisode_idsepisodesr   c                     | d   d   S Nshowsr   r   r   s    r   r   z*StitcherIE._real_extract.<locals>.<lambda>j       qz!} r   )	_match_idr#   r-   raise_login_requiredr   dictrF   r4   )r   r>   audio_idr   r,   r*   r3   s          r   _real_extractzStitcherIE._real_extractb   s    >>#&~~h(ACz"1%++G4	%%'t4d;Ar$$Y 7 7 =? 	?r   NrG   rH   rI   r   rJ   
_VALID_URL_TESTSrg   r   r   r   rL   rL   7   s    //2ffJ^1CA0%#(

 {95A0
 T
 !" b
 P ]I'FR
?r   rL   c                   N    e Zd Zej                  dz   Zdddddddd	d
dgZd Zy)StitcherShowIEz(?P<id>[^/#?&]+)/?(?:[?#&]|$)z4http://www.stitcher.com/podcast/the-talking-machineszthe-talking-machinesrQ   z$md5:831f0995e40f26c10231af39cf1ebf0b)r6   r0   r&   j   )r>   rU   playlist_mincountz2https://www.stitcher.com/show/the-talking-machinesTrZ   c                    | j                  |      }| j                  d|z  |ddi      }t        |d t              xs i }| j	                  |      }g }|j                  d      xs g D ]8  }| j                  |      }|s|j                  | j                  |||             : | j                  |||j                  d      | j                  |            S )Nzsearch/show/%s/allEpisodescounti'  c                     | d   d   S r`   r   r   s    r   r   z.StitcherShowIE._real_extract.<locals>.<lambda>   rb   r   r^   r0   )rc   r#   r   re   r4   r'   r-   appendrF   playlist_resultr(   )	r   r>   	show_slugr   r3   rD   entriesr,   r*   s	            r   rg   zStitcherShowIE._real_extract~   s    NN3'	~~(94i'5AQSt4d;Ar++D1	,2 	QG//8INN400)YOP		Q ##Y 1%%d+- 	-r   Nrh   r   r   r   rl   rl   o   sH    //2RRJE('A

 ! DF-r   rl   N)commonr   compatr   utilsr   r   r   r	   r
   r   r   r   rL   rl   r   r   r   <module>ry      s@    !   &] &R5? 5?p-^ -r   