
    uki                     b    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
 ddlmZ  G d d	e      Zy)
    N   )InfoExtractor   )HEADRequest)determine_ext
js_to_jsonstr_or_none)traverse_objc                       e Zd Z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dddddddddddddd d!d"d#d$ddgZd%d&dd'd(d)d*d+dd,d-d.dd/d0d)d1d2dd,gZed3        Zd4 Zd5 Z	y6)7
SubstackIEz/https?://[\w-]+\.substack\.com/p/(?P<id>[\w-]+)z4https://haleynahman.substack.com/p/i-made-a-vlog?s=r f27e4fc6252001d48d479f45e65cdfd547660949mp4zI MADE A VLOGz$md5:9248af9a759321e1027226f988f54d96z$md5:bec758a34d8ee9142d43bcebdf33af18z
Maybe Baby33628)idexttitledescription	thumbnailuploaderuploader_id)urlmd5	info_dictzHhttps://haleynahman.substack.com/p/-dear-danny-i-found-my-boyfriends?s=r 0a63eacec877a1171a62cfa69710fcea51045592mpgau>   🎧 Dear Danny: I found my boyfriend's secret Twitter accountz$md5:a57f2439319e56e0af92dd0c95d75797z$md5:daa40b6b79249417c14ff8103db29639zIhttps://andrewzimmern.substack.com/p/mussels-with-black-bean-sauce-recipe fd3c07077b02444ff0130715b5f632bb47368578z4Mussels with Black Bean Sauce: Recipe of the Week #7z$md5:b96234a2906c7d854d5229818d889515z$md5:e30bfaa9da40e82aa62354263a9dd232zAndrew Zimmern's Spilled Milk 577659z*https://persuasion1.substack.com/p/summers 1456a755d46084744facdfac9edf900f	141970405mp3z*Larry Summers on What Went Wrong on Campusz^Yascha Mounk and Larry Summers also discuss the promise and perils of artificial intelligence.z*re:https://substackcdn\.com/image/.+\.jpeg
Persuasion61579z-https://www.mollymovieclub.com/p/interstellar53602801InterstellarzListen now | Episode Onezre:https?://.+\.jpegzMolly Movie Club839621)r   r   zEhttps://www.blockedandreported.org/p/episode-117-lets-talk-about-depp57962052z$md5:855b2756f0ee10f6723fa00b16266f8dzThe takes the takes the takeszBlocked and Reported500230c              #   (  K   t        j                  d|      sy t        j                  d|      }|r_t        j                  j	                  |      }|j                  |j                  d       d      j                          | j                  y w)Nz8<script[^>]+src=["\']https://substackcdn.com/[^"\']+\.jszF{[^}]*\\?["\']subdomain\\?["\']\s*:\s*\\?["\'](?P<subdomain>[^\\"\']+)	subdomainz.substack.comnetloc)	researchurllibparseurlparse_replacegroupgeturlStopExtraction)clsr   webpagemobjparseds        T/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/yt_dlp/extractor/substack.py_extract_embed_urlszSubstackIE._extract_embed_urlsZ   s~     yyTV]^yybdkl\\**3/F//DJJ{,C+DM)R/SZZ\\$$$ s   BBc                    g i }}dD ]~  }t         j                  j                  |d| d|       }|dk(  r=| j                  ||dd      \  }}|j	                  |       | j                  ||       k|j                  ||d	        ||fS )
N)hlsr   z/api/v1/video/upload/z
/src?type=r?   r   F)fatal)target)r   r   )r1   r2   urljoin#_extract_m3u8_formats_and_subtitlesextend_merge_subtitlesappend)	selfvideo_idr   formats	subtitlesvideo_format	video_urlfmtssubss	            r<   _extract_video_formatsz!SubstackIE._extract_video_formatse   s    * 	L,,S4I(S]^j]k2lmIu$!EEiQY[`hmEn
dt$%%d9%=$'  	 	!!    c                 L   | j                  |      }| j                  ||      }| j                  | j                  d|d|t        d      |      }|}t        |ddt        hf      }|r=t        j                  j                  |      j                  |      j                         }|d   d	   }g i }	}|d
k(  rbd|d   d   i}
t        |
d   d       s6t        | j                  t        |
d         |dd      j                        |
d<   |j!                  |
       n9|dk(  r| j#                  |d   d   d   |      \  }}	n| j%                  d| d       t        |d   d         ||	t        |d      t        |d      t        |d      t        |d      t'        t        |d            |d	S )Nz%window\._preloads\s*=\s*JSON\.parse\(zjson stringz"{(?s:.+)}")transform_sourcecontains_pattern
domainInfocustomDomainr-   posttypepodcastr   podcast_url)default_extz Resolving podcast file extensionzPodcast URL is invalidr   videovideoUploadr   zPage type "z" is not supported)rV   r   )rV   r   )rV   cover_image)pubname)rV   publication_id)	r   rI   rJ   r   r   r   r   r   webpage_url)	_match_id_download_webpage_parse_json_search_jsonr   r
   strr1   r2   r3   r4   r6   r   _request_webpager   r   rF   rO   raise_no_formatsr	   )rG   r   
display_idr9   webpage_infocanonical_urldomain	post_typerI   rJ   fmts              r<   _real_extractzSubstackIE._real_extractv   s   ^^C(
((j9''(9(94g}n ): )VWac l\>C5,QR"LL11#6??v?NUUWM (0		!,v.}=>C U> +4+@+@E
+Z6,,. /2c3E
 NN3'!!%!<!<\&=QR_=`ae=fhu!vGY!!K	{:L"MN l6*401"!,0AB'6MN%l4KL$\?C&|LB\']^(

 
	
rP   N)
__name__
__module____qualname__
_VALID_URL_TESTS_WEBPAGE_TESTSclassmethodr=   rO   ro    rP   r<   r   r      s   CJE1$A?$"
 Z1UA?$"
 [1KA?8#
 <1A{F$"
	I1Ff ?#50*#
 W;:0.#
N0 % %""(
rP   r   )r/   urllib.parser1   commonr   
networkingr   utilsr   r   r	   utils.traversalr
   r   rw   rP   r<   <module>r}      s.    	  ! $ 
 +P
 P
rP   