o
    iۻ                     @   s  d dl Z d dlZd dlZ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 ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' dd	l(m)Z)m*Z* G d
d deZ+G dd de+Z,G dd de
Z-G dd de
Z.G dd deZ/G dd deZ0G dd de
Z1G dd deZ2G dd de
Z3G dd de+Z4G dd de+Z5dS )     N   )AdobePassIE)InfoExtractor)ThePlatformBaseIEThePlatformIE
default_ns   )HEADRequest)ExtractorErrorRegexNotFoundErrorUserNotLive
clean_htmldetermine_extextract_attributesfloat_or_noneget_element_html_by_classint_or_nonejoin_nonemptymake_archive_idmimetype2extparse_age_limitparse_durationparse_iso8601
remove_endtry_getunescapeHTMLunified_timestampupdate_url_queryurl_basenameurl_or_none)requiretraverse_objc                   @   s4   e Zd ZdgZdZdZdd Zdd Zdd	d
ZdS )NBCUniversalBaseIEUSFz`https?://[^/?#]+/prod/[\w-]+/(?P<folders>[^?#]+/)cmaf/mpeg_(?:cbcs|cenc)\w*/master_cmaf\w*\.m3u8c              
   C   s   | j d| |ddi |dddd|  d}d	t d
}t|| ddd tf }r/|S t|| ddd dtf}|dkrH| j| jd tt|| ddtf|dkd)Nhttps://link.theplatform.com/s/zDownloading SMIL manifestz Failed to download SMIL manifestSMILm3uHLSServiceSecure)formatmanifestswitch)queryheadersz//{}z
video/@srcc                 S   s   t |dkS )Nm3u8)r   _v r2   H/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/nbc.py<lambda>6       zMNBCUniversalBaseIE._download_nbcu_smil_and_extract_m3u8_url.<locals>.<lambda>paramc                 S   s   | ddkS )Nname	exceptiongetr/   r2   r2   r3   r4   9   s    z@valueGeoLocationBlocked)	countrieszref/@abstract.Expiredexpected)_download_xmlgeo_verification_headersr   r!   anyraise_geo_restricted_GEO_COUNTRIESr
   )selftp_pathvideo_idr+   smilnsurlexcr2   r2   r3   (_download_nbcu_smil_and_extract_m3u8_url+   s$   
	"z;NBCUniversalBaseIE._download_nbcu_smil_and_extract_m3u8_urlc                 C   s   d|d< |  ||| }}t| j| }r3d|d< |  |||}d|v r*| d |j|dd}d|v s;d	|v r@| | | j||d
ddd\}}	|sn||krn| j||d
ddd\}
}	dd |
D }|
rn|sn| | ||	fS )Nzm3u+none,mpeg4formatsmpeg4z	{folders}z,Found m3u8 URL template, formatting URL pathfolders)rO   z
/mpeg_cencz
/mpeg_cbcsmp4hlsFm3u8_idfatalc                 S   s   g | ]	}| d s|qS )has_drmr9   ).0fr2   r2   r3   
<listcomp>U   s    zJNBCUniversalBaseIE._extract_nbcu_formats_and_subtitles.<locals>.<listcomp>)	rL   re	fullmatch_M3U8_REwrite_debugr(   group
report_drm#_extract_m3u8_formats_and_subtitles)rE   rF   rG   r+   orig_m3u8_urlm3u8_urlmobj	m3u8_tmplrM   	subtitles	orig_fmtsr2   r2   r3   #_extract_nbcu_formats_and_subtitles>   s*   






z6NBCUniversalBaseIE._extract_nbcu_formats_and_subtitlesNc                    s  |  ||}| d|d|}i }ttd|pd}|rr|dp#|d }|d }	| j|dp0d|d	td
}
|dp>|
d  |ddkrq|d }|d }| |dpX|d |d ||d}| |||d ||d |d< n-t	|ddd t
tdhf}|d  |dp|d }|d }	t	|d fd dt
fpi }
| d!|	 d"  }| | |\}}| j| d	d#}| |}| j|d$ |d% i |t	|
d&thfd'thfd(thfd)thfd*thfd+thfd,thfd-thfd.thfd/	 ||||rt| gd0S d d0S )1Nz=<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>settingsztve-video-deck-app zdata-mpx-media-account-pidzdata-mpx-account-pidzdata-mpx-media-account-idzdata-normalized-videoF)rT   transform_sourcez	data-guidguidzdata-entitlementauthtve_adobe_authzdata-release-pidzdata-adobe-pass-resource-idadobePassResourceIdz
data-titlezdata-ratingadobePassRequestorIdadobePassSoftwareStatementls_playlistc                 S   s   |d S )NdefaultGuidr2   r/   r2   r2   r3   r4   t   s    z8NBCUniversalBaseIE._extract_nbcu_video.<locals>.<lambda>zLS playlistrq   mpxMediaAccountPidmpxAccountPidmpxMediaAccountIdvideosc                    s   |d  kS )Nrj   r2   r/   rG   r2   r3   r4   x   r5   z/media/guid//rT   rd   targettitledescriptiondurationInSecondsairDatethumbnailUrlseasonNumberepisodeNumberepisodeTitleshow)	r{   r|   duration	timestamp	thumbnailseason_numberepisode_numberepisodeseries)id
display_idrM   rd   _old_archive_ids)_download_webpage_search_jsonr   r   r:   _parse_jsonr   _get_mvpd_resource_extract_mvpd_authr!   rB   r    rf   _download_theplatform_metadata_parse_theplatform_metadata_merge_subtitlesstrr   r   r   r   )rE   rJ   r   
old_ie_keywebpagerg   r+   tveaccount_pid
account_idmetadatark   release_pidresourcerp   rF   rM   rd   tp_metadataparsed_infor2   rv   r3   _extract_nbcu_video[   sz   

z&NBCUniversalBaseIE._extract_nbcu_videoN)	__name__
__module____qualname__rD   _GEO_BYPASSr[   rL   rf   r   r2   r2   r2   r3   r"   &   s    r"   c                   @   sd  e Zd ZdZdi 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d"d#d$d%gd&d'd(id)d*i dd+dddd,dd,dd-dd.dd/dd0d	d1dddd2dd3dd4dd5ddd"d6d7d8d9gd:gd;d'd(id)d<d=dd>d?d@dAdd>dBdCdDgdEd'd(id)dFdGdHdIdGdHdJdGdHgZdKZdLdM ZdNS )ONBCIEz\https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/?#]+/video/[^/?#]+/(?P<id>\w+))z[http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237r   2848237extrP   r{   z,Jimmy Fallon Surprises Fans at Ben & Jerry'sr|   zJimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry's scoop shop.r   iFTupload_date20150218uploaderzNBCU-COMr   r   V   seasonSeason 2r   r   r   Tonightr   g㥛 m@tagszcount:2r   re:https?://.+\.jpg
categoriesz-Series/The Tonight Show Starring Jimmy Fallon
media_typeFull Episode   ztheplatform 2848237)	age_limitr   skip_downloadr.   rJ   	info_dictparamszhttps://www.nbc.com/the-golden-globe-awards/video/oprah-winfrey-receives-cecil-b-de-mille-award-at-the-2018-golden-globes/36464393646439zHOprah Winfrey Receives Cecil B. de Mille Award at the 2018 Golden Globesr   z	Season 75K   zGolden GlobeszZOprah Winfrey receives the Cecil B. de Mille Award at the 75th Annual Golden Globe Awards.20180107iQZgv́@zcount:8	Highlightr   r   zSeries/The Golden Globe Awardsztheplatform 3646439)r   r   z}https://www.nbc.com/paris2024/video/ali-truwit-found-purpose-pool-after-her-life-changed/para24_sww_alitruwittodayshow_240823$para24_sww_alitruwittodayshow_240823z;Ali Truwit found purpose in the pool after her life changedz$md5:c16d7489e1516593de1cc5d3f39b9bdbNBCU-SPORTSgZd;qs@g  o3A20240823z0theplatform para24_sww_alitruwittodayshow_240823)r   r   r{   r|   r   r   r   r   r   r   r   zVhttps://www.nbc.com/quantum-leap/video/bens-first-leap-nbcs-quantum-leap/NBCE125189978TrJ   only_matchingzThttps://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310zHhttps://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189a  eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI1Yzg2YjdkYy04NDI3LTRjNDUtOGQwZi1iNDkzYmE3MmQwYjQiLCJuYmYiOjE1Nzg3MDM2MzEsImlzcyI6ImF1dGguYWRvYmUuY29tIiwiaWF0IjoxNTc4NzAzNjMxfQ.QQKIsBhAjGQTMdAqRTqhcz2Cddr4Y2hEjnSiOeKKki4nLrkDOsjQMmqeTR0hSRarraxH54wBgLvsxI7LHwKMvr7G8QpynNAxylHlQD3yhN9tFhxt4KR5wW3as02B-W2TznK9bhNWPKIyHND95Uo2Mi6rEQoq8tM9O09WPWaanE5BX_-r6Llr6dPq5F0Lpx2QOn2xYRb1T4nFxdFTNoss8GBds8OvChTiKpXMLHegLTc1OS4H_1a8tO_37jDwSdJuZ8iTyRLV4kZ2cpL6OL5JPMObD4-HQiec_dfcYgMKPiIfP9ZqdXpec2SVaCLsWEk86ZYvD97hLIQrK5rrKd1y-Ac                 C   s  |  | \}}dtj| }| jd|dt|dddddd	 d
 d }|sF| ||}| 	d|d|d tj
|j d d }|d }d|d  d| }| j||dd}t|dthfph|d}i }	|dr| |d |||d}
| ||d|
| j|	d< | |||	\}}| |}| j|d |d i t|dthtfdthtfd thfd!thfdthfd"d#thtttfd$thfd%|||||td&|gd'S )(Nhttpz$https://friendship.nbc.co/v2/graphqlaH  query bonanzaPage(
  $app: NBCUBrands! = nbc
  $name: String!
  $oneApp: Boolean
  $platform: SupportedPlatforms! = web
  $type: EntityPageType! = VIDEO
  $userId: String!
) {
  bonanzaPage(
    app: $app
    name: $name
    oneApp: $oneApp
    platform: $platform
    type: $type
    userId: $userId
  ) {
    metadata {
      ... on VideoPageData {
        description
        episodeNumber
        keywords
        locked
        mpxAccountId
        mpxGuid
        rating
        resourceId
        seasonNumber
        secondaryTitle
        seriesShortTitle
      }
    }
  }
}T0)r7   oneAppuserId)r+   	variables)r+   databonanzaPager   z<script>\s*PRELOAD\s*=
video datapagesbasempxGuidzNnzsPC/media/guid/mpxAccountIdrw   Frx   r{   secondaryTitlelocked
resourceIdratingnbcentertainmentrk   rd   ry   r|   r   r   keywords.seriesShortTitle)r|   r   r   r   r   r   r   ThePlatform)r   r{   rM   rd   r   )_match_valid_urlgroupsurllibparseunquote_download_jsonjsondumpsr   r   urlparsepathr   r!   r   r:   r   r   _SOFTWARE_STATEMENTrf   r   r   filterr   r   allr   )rE   rJ   	permalinkrG   
video_datar   rF   tpmr{   r+   r   rM   rd   r   r2   r2   r3   _real_extract   s   !(((*





zNBCIE._real_extractN)r   r   r   
_VALID_URL_TESTSr   r   r2   r2   r2   r3   r      s    	
	
Rr   c                   @   sd   e Zd ZdZdZed Zde dgZdddd	d
ddddg dd
dddddddgZdd ZdS )NBCSportsVPlayerIEFzFhttps?://(?:vplayer\.nbcsports\.com|(?:www\.)?nbcsports\.com/vplayer)/z (?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)zF(?:iframe[^>]+|var video|div[^>]+data-(?:mpx-)?)[sS]rc\s?=\s?"(?P<url>z[^\"]+)zJhttps://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI9CsDKds0kvHIrP   z$md5:df390f70a9ba7c95ff1daace988f0d8dz3Tyler Kalinoski hits buzzer-beater to lift Davidsoni(U20150313r   g1Z4R@zre:^https?://.*\.jpg$)
r   r   r|   r{   r   r   r   r   chaptersr   rJ   r   zPhttps://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/PEgOtlNcC_y2Tr   z`https://www.nbcsports.com/vplayer/p/BxmELC/nbcsports/select/PHJSaFWbrTY9?form=html&autoPlay=truec                 C   s0   |  |}| ||}| d|d}| |dS )Nztp:releaseUrl="(.+?)"rJ   r   )	_match_idr   _html_search_regex
url_result)rE   rJ   rG   r   theplatform_urlr2   r2   r3   r   ]  s   
z NBCSportsVPlayerIE._real_extractN)	r   r   r   _WORKING_VALID_URL_BASEr   _EMBED_REGEXr   r   r2   r2   r2   r3   r   A  s4    r   c                   @   sd   e Zd ZdZdZddddddd	d
g ddd
dddddddgZdddddddgZdd ZdS )NBCSportsIEFzMhttps?://(?:www\.)?nbcsports\.com//?(?!vplayer/)(?:[^/]+/)+(?P<id>[0-9a-z-]+)zghttps://www.nbcsports.com/watch/nfl/profootballtalk/pft-pm/unpacking-addisons-reckless-driving-citationPHJSaFWbrTY9rP   z5Tom Izzo, Michigan St. has 'so much respect' for Dukez$md5:ecb459c9d59e0766ac9c7d5d0eda8113r   20150330i`Uzdhttps://hdliveextra-a.akamaihd.net/HD/image_sports/NBCU_Sports_Group_-_nbcsports/253/303/izzodps.jpgg\(@)
r   r   r{   r|   r   r   r   r   r   r   r   z_https://www.nbcsports.com/philadelphia/philadelphia-phillies/bruce-bochy-hector-neris-hes-idiotTr   zUhttps://www.nbcsports.com/boston/video/report-card-pats-secondary-no-match-josh-allenz_http://www.riderfans.com/forum/showthread.php?121827-Freeman&s=e98fa1ea6dc08e886b1678d35212494aln7x1qSThw4kflvz.PFT Live: New leader in the 'new-look' defenser   r   r{   Invalid URLrJ   r   skipc                 C   s(   |  |}| ||}| t|dS )NNBCSportsVPlayer)r   r   r   r   _extract_url)rE   rJ   rG   r   r2   r2   r3   r     s
   

zNBCSportsIE._real_extractN)r   r   r   r   r   r   _WEBPAGE_TESTSr   r2   r2   r2   r3   r   d  s>    
r   c                   @   s:   e Zd ZdZdZddddddd	d
iddgZdd ZdS )NBCSportsStreamIEFz4https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)z4http://stream.nbcsports.com/nbcsn/generic?pid=206559206559rP   z&Amgen Tour of California Women's Recapz$md5:66520066b3b5281ada7698d0ea2aa894r   r   r{   r|   r   Tz"Requires Adobe Pass AuthenticationrJ   r   r   r   c                 C   s$  |  |}| d| d|}|d d }|d }d }dD ]}|d }||p.||d }|r3 nq|d	 }|d
dkpE|ddk}	| d||d}
| ||d|
d }| jd|td|dddd|d t|	 
 t|
	 
 d		 dd }| ||d}|||d||	dS )Nz.http://stream.nbcsports.com/data/live_sources_.jsonvideoSourcesr   r{   )source
msl4source	iossourcehlsv4UrlAltottStreamUrltypelivestatusLive	nbcsportsrh   z'https://token.playmakerservices.com/cdn	NBCSportsv1desktopakamai	sourceUrl)	requestorIdpidapplicationversionplatformcdnrJ   tokenr   r   tokenizedUrlrP   r|   )r   r{   r|   rM   is_live)r   r   r:   r   r   r   r   base64	b64encodeencodedecode_extract_m3u8_formats)rE   rJ   rG   live_sourcevideo_sourcer{   
source_urlkskr$  r   r!  tokenized_urlrM   r2   r2   r3   r     sT   


zNBCSportsStreamIE._real_extractN)r   r   r   r   r   r   r   r2   r2   r2   r3   r    s    r  c                   @   s   e Zd ZdZdg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)dd*d+d,dd-d.d/d0d1d2d)d3dd4d5d6dd7d8d9d:d;d<d=d3dd>d?d@dAd?d@gZdBdCddDdEd3dFgZdGdH ZdIS )J	NBCNewsIEzS(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)z\<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//www\.nbcnews\.com/widget/video-embed/[^"\']+)\1zbhttp://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880 fb3dcd2d7b1dd9804305fa2fc95ab610269389891880rP   z,How Twitter Reacted To The Snowden Interviewz$md5:65a0bd5d76fe114f3c2727aa3a81fe64itS20140529g      G@zehttps://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/140529/p_tweet_snow_140529.jpg)r   r   r{   r|   r   r   r   r   rJ   md5r   zZhttp://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156 fdbf39ab73a72df5896b6234ff98518a529953347624zFULL EPISODE: Family Businessz$md5:757988edbaae9d7be1d585eb5d55cc04r  zThis page is unavailable.)rJ   r5  r   r   zqhttp://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844 40d0e48c68896359c80372306ece0fc3394064451844z<Nightly News with Brian Williams Full Broadcast (February 4)z$md5:1c10c1eccbe84a26e5debb4381e2d3c5iT20150205g     P@zbhttps://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/__NEW/nn_netcast_150204.jpgzzhttp://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456 ffb59bcf0733dc3c7f0ace907f5e3939n431456z/Volkswagen U.S. Chief:  We 'Totally Screwed Up'z$md5:d22d1281a24f22ea0880741bb4dd630120150922i-Vg     B@zdhttps://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/__NEW/x_lon_vwhorn_150922.jpg)r   r   r{   r|   r   r   r   r   zehttp://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788 693d1fa21d23afcc9b04c66b227ed9ff669831235788z=See the aurora borealis from space in stunning new NASA videoz$md5:74752b7358afb99939c5f8bb2d1d04b120160420i]iWg     @Q@zthttps://media-cldnry.s-nbcnews.com/image/upload/MSNBC/Components/Video/201604/2016-04-20T11-35-09-133Z--1280x720.jpgr   z`http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924 6d236bf4f3dddc226633ce6e2c3f814d314487875924z The chaotic GOP immigration votezThe Republican House votes on a border bill that has no chance of getting through the Senate or signed by the President and is drawing criticism from all sides.r   i*S20140802g     `@)r   r   r{   r|   r   r   r   r   zPhttp://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952Tr   z6http://www.nbcnews.com/widget/video-embed/701714499682zPhttp://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.htmlx_dtl_oa_LettermanliftPR_160608zDavid Letterman: A Previewr   r   c                 C   s  |  |}| ||}| ||d d }t|dd t}|s+|d d d d d	 }|d
 d }g }|dg D ]N}|d}	|	sCq9d|	v rNt|	ddi}	|d}
|
dkrf|| j|	|dd|
dd q9t	|dd}|
t|
||	t	|dt	|d|dd q9i }|d}|r| D ]}|sq|dg 
d|i q||t|dd t|dd t|d t|d!||d"S )#NpropsinitialStatec                 S      | d d S )Nvideocurrentr2   xr2   r2   r3   r4   4  r5   z)NBCNewsIE._real_extract.<locals>.<lambda>articlecontentr   primaryMediarH  headlineprimaryvideoAssets	publicUrlz://link.theplatform.com/r(   redirectM3UrP   m3u8_nativeFrR   bitrate  widthheight)	format_idrJ   rX  rY  tbrr   closedCaptioningenrJ   c                 S   rG  )Nr|   rP  r2   rJ  r2   r2   r3   r4   ]  r5   c                 S   s   | d d d S )NprimaryImagerJ   rP  r2   rJ  r2   r2   r3   r4   ^  s    r   datePublished)r   r{   r|   r   r   r   rM   rd   )r   r   _search_nextjs_datar   dictr:   r   extendr)  r   appendr   values
setdefaultr   r   )rE   rJ   rG   r   r   r   r{   rM   va
public_urlrZ  r[  rd   closed_captioningcc_urlr2   r2   r3   r   /  s`   



	
zNBCNewsIE._real_extractN)r   r   r   r   r   r   r  r   r2   r2   r2   r3   r0    s    

V
r0  c                   @   sH   e Zd ZdZdZdddddddd	d
ddddddddgZdd ZdS )NBCOlympicsIEnbcolympicsz9https?://www\.nbcolympics\.com/videos?/(?P<id>[0-9a-z-]+)zUhttps://www.nbcolympics.com/videos/watch-final-minutes-team-usas-mens-basketball-goldSAwGfPlQ1q01rP   z2watch-final-minutes-team-usas-mens-basketball-goldz;Watch the final minutes of Team USA's men's basketball goldz$md5:f704f591217305c9559b23b877aa8d31r   g+0x@r   i(0f20240811)r   r   r   r{   r|   r   r   r   r   r   r   r   zVhttp://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-goldTr   c              	   C   s   |  |}| ||}z| | d|d|}|d d }|dd}W n ty6   | jd|dd	d
}Y nw d|t |dS )Nz1jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);zdrupal settingsvod
iframe_urlzvplayer.nbcolympics.comzplayer.theplatform.comz-([\"'])embedUrl\1: *([\"'])(?P<embedUrl>.+)\2zembedding URLembedUrl)r]   url_transparent)_typerJ   ie_keyr   )r   r   r   _search_regexreplacer   r   rs  )rE   rJ   r   r   drupal_settingsro  r   r2   r2   r3   r     s0   

zNBCOlympicsIE._real_extractN)r   r   r   IE_NAMEr   r   r   r2   r2   r2   r3   rj  f  s,    rj  c                   @   sX   e Zd ZdZdZdZdddddd	d
didddddddd	d
diddgZdd ZdS )NBCOlympicsStreamIEFznbcolympics:streamz4https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)zTokenized m3u8 source URLz;https://stream.nbcolympics.com/womens-soccer-group-round-112019740rP   z^re:Women's Group Stage - Netherlands vs\. Brazil [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$r   r   r.   
Livestream)noterJ   r   r   r   zPlain m3u8 source URLz`https://stream.nbcolympics.com/gymnastics-event-finals-mens-floor-pommel-horse-womens-vault-bars2021729zhre:Event Finals: M Floor, W Vault, M Pommel, W Uneven Bars [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$c                 C   sr  |  |}| ||}| d|d}| d| d|dd }|d }dd	d
|d}| d| d|dd d d d d d }|dr| |ddtdd|d ||dd}	| |||dd|	d }
| jd|dt	
ddd |d!dt|	  t|
  |d"d#
 d$d  d d% }| j||d&|d'}|D ]
}d(g d)i|d*< q|||||d+S ),Nzpid\s*=\s*(\d+);r  z0http://stream.nbcolympics.com/data/event_config_r  zDownloading event configeventConfig
eventTitleTF)r  replayeventStatusz,https://api-leap.nbcsports.com/feeds/assets/zG?application=NBCOlympics&platform=desktop&format=nbc-player&env=stagingzDownloading leap configr	  r   
cdnSourcesrP  r  cdnTokenr   NBCOlympicsz	[^\w\d ]+rh   ratingIdzNO VALUEr  z%https://tokens.playmakerservices.com/zRetrieving tokenized URLr  z
adobe-passr  r  r  )
r  zauthentication-typer   r  r  r  r   r!  rJ   r  r"  r#  rP   )r  ffmpeg_args)z	-seekabler   z-http_seekabler   z-icyr   downloader_options)r   r   r{   rM   r$  )r   r   rt  r   r:   r   rY   subr   r   r   r%  r&  r'  r(  r)  )rE   rJ   r   r   r  event_configr{   r$  r,  ap_resourcemedia_tokenrM   rW   r2   r2   r3   r     s   





z!NBCOlympicsStreamIE._real_extractN)r   r   r   r   rw  r   r   r   r2   r2   r2   r3   rx    s4    rx  c                   @   s   e Zd ZdeejdZde 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idd d!d"dd#d$d%d&d'd(d)d*d
d+gZ	d,d-d.d/d0d1Z
d2d3 Zd4S )5NBCStationsIE|)
nbcbayarea	nbcboston
nbcchicagonbcconnecticutnbcdfwnbclosangelesnbcmiami
nbcnewyorknbcphiladelphianbcsandiegonbcwashingtonnecntelemundo52telemundoarizonatelemundochicagotelemundonuevainglaterrazhttps?://(?:www\.)?(?P<site>z/)\.com/(?:[^/?#]+/)*(?P<id>[^/?#]+)/?(?:$|[#?])zqhttps://www.nbclosangeles.com/news/local/large-structure-fire-in-downtown-la-prompts-smoke-odor-advisory/2968618/2968618rP   z?Large Structure Fire in Downtown LA Prompts Smoke Odor Advisoryz$md5:417ed3c2d91fe9d301e6db7b0942f182gF \@ic20220822zNBC 4KNBCr  )
r   r   r{   r|   r   r   r   r   
channel_idchannelzSite changedr   zhhttps://www.telemundoarizona.com/responde/huracan-complica-reembolso-para-televidente-de-tucson/2247002/2247002u=   Huracán complica que televidente de Tucson reciba  reembolsoz$md5:af298dc73aab74d4fca6abfb12acb6cfgEe@ib20220819zTelemundo ArizonaKTAZr  r   r.   r   zchttps://www.nbcboston.com/weather/video-weather/highs-near-freezing-in-boston-on-wednesday/2961135/ 9bf8c41dc7abbb75b1a44f1491a4cc852961135z*Highs Near Freezing in Boston on Wednesdayz$md5:3ec486609a926c99f00a3512e6c0e85bg rhum@i0c20230201rh   WBTSr  r4  19201280960640416)1080720540360234c                 C   s  |  |dd\}}| ||}| d|d|}|dpd}t|d}| jd|d	|i td
}|| jd|d|i td
 |sFtdddi g }	}
t	|ddk}dd|t|ddddddd|rednddddd }|r}t|d!d"d#}| d$|	d%< not|d&d"d#}t|d'd(}|r| j
d)|d*d"d+}nt|d,d"d#}t|d-d"d#}|rt|}| j
d.t|d/d d}|
||t	| j|t	|d0| d1 |	|d%pt|d2d"d#t|d3d4d5ptt|d6t|d7 d }|r|r| jd8| d9| |d:||d;}t|tjjjsd }|d ur| |tni }|d ur*|| d<tng D ]\}tt|d=d>d?|	d@< |dA}t|dBt|d}|dCkrl| j||dDdE||dFdG\}}|
| | j ||dH q,|r|
|dI| |t	|dJt	|d/dK q,|
s| j!dLdd n!|rz| j"t#|
dM dN |dOdP W n ty   t$|dQw |||dR|dS|
||dT|	S )UNsiter   z1(?:<script>\s*var\s+nbc\s*=|Object\.assign\(nbc,)zNBC JSON datapdkAcctYh1nAC)rH  fwSSIDzdata-videos="\[r   )defaultri   zdata-meta="r   z"No video metadata found in webpageTr>   mpx_is_livestreamr   z0MPEG-DASH none,M3U none,MPEG-DASH none,MPEG4,MP3r%   )rH  fwNetworkID382114)r  ots_desktop_htmlfalser  r  LIVEz	on-demandscriptz2.0z	PDK 6.1.3)rM   r(   fwsitesectionr  pprofile	sensitivewhmodevpaidschemasdk)N)rH  meta)
mpx_m3upidmpx_pidpid_streaming_web_mediumF)get_allz livestreamr{   )r  )pid_streaming_web_highr  date_stringdate_gmtzdatetime="([^"]+)"zdate stringrx   )	dataLayeradobe)prop70eVar70eVar59)r  mp4_urlz
\d+-(\d+)prY  zhttp-)rJ   r   rX  rY  rZ  )r  )Nr  )contenttitler{   prop22summaryexcerptvideo_hero_text)r  r  )r{   r|   r   r$   rw   zDownloading SMIL data)r{  r+   rT   z.//videodurmsrW  r   srcr  r.   rP   rQ   zNo HLS formats found)rS   rT   r  errnotery   zhttps-rX  )rJ   rZ  r   rX  rY  z!No video content found in webpager   rJ   zChecking live status)r{  rv   callLetterson_air_name)r   r  r  r   rM   rd   r$  )%r   r]   r   r   r:   r!   r   updater
   r   rt  r   r   rc  _RESOLUTIONSr   r   r@   
isinstancexmletreeElementTreeElement_parse_smil_subtitlesr   findall	_xpath_nsr   r   r   r_   rb  r   raise_no_formats_request_webpager	   r   )rE   rJ   r  rG   r   nbc_datapdk_acctfw_ssidr   inforM   r$  r+   	player_idr  	video_urlr   rY  rH   rd   rH  video_src_urlfmtssubsr2   r2   r3   r   1  s   


	$






zNBCStationsIE._real_extractN)r   r   r   joinmaprY   escape
_DOMAIN_REr   r   r  r   r2   r2   r2   r3   r    sl    3r  c                   @   s*  e Zd ZdZdi 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d$d%d&d'id(d)i dd*dddd+d	d,dd-dd.dd/dd0dd1dddd+dd2dd3d4d5ddd6d7d8d9d:d#gd%d;d&d'id<d=d>i dd?dddd@d	dAddBddCddDdd1dd1ddEdd@ddFddGd4dHddd6d7d8d9d:dIgg dJd;d&d'id<d=dKi ddLddddMd	dNddOddPddQddRddddEddSddTddUddd6d7ddVd!dIgd$g dWid&d'id(dXdYdZgZd[d\ Zd]S )^	BravoTVIEzGhttps?://(?:www\.)?(?:bravotv|oxygen)\.com/(?:[^/?#]+/)+(?P<id>[^/?#]+)z]https://www.bravotv.com/top-chef/season-16/episode-15/videos/the-top-chef-season-16-winner-isr   3923059r   rP   r{   z#The Top Chef Season 16 Winner Is...r   z the-top-chef-season-16-winner-isr|   z)Find out who takes the title of Top Chef!r   20190315r   il\r      r      r   zTop Chefr   Finaler      r   z	Season 16r   zre:^https://.+\.jpgr   z	NBCU-BRAVr   SerieszSeries/Top Chefr   zcount:10r   r.   r   zChttps://www.bravotv.com/top-chef/season-20/episode-1/london-calling
9000234570zLondon Callingzlondon-callingz$md5:5af95a8cbac1856bd10e7562f86bb75920230310i
d   r   i  z	Season 20r   zcount:7r   r   r   r   	NBCU-MPAT)r   r   r   -This video requires AdobePass MSO credentialsr  z?https://www.oxygen.com/in-ice-cold-blood/season-1/closing-night3692045zClosing Nightzclosing-nightz$md5:c8a5bb523c8ef381f3328c6d9f1e463220230126iczIn Ice Cold BloodiE
  zSeason 1zcount:6zSeries/In Ice Cold Blood)ice-tin ice cold bloodlaw and orderoxygen
true crimezxhttps://www.oxygen.com/in-ice-cold-blood/season-2/episode-16/videos/handling-the-horwitz-house-after-the-murder-season-23974019zC'Handling The Horwitz House After The Murder (Season 2, Episode 16)z4handling-the-horwitz-house-after-the-murder-season-2z$md5:f9d638dd6946a1c1c0533a9c6100eae520190618i7]r   zMother Vs SonD   r   zNBCU-OXY)r  r
  r  r  r  z@https://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1Tr   c                 C   s   |  |}| ||S r   r   r   rE   rJ   r   r2   r2   r3   r     s   
zBravoTVIE._real_extractNr   r   r   r   r   r   r2   r2   r2   r3   r    sV   	
	
	
	
fr  c                   @   sd  e Zd ZdZdi 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d&d'gd(d)d*id+d,i dd-dddd.d	d/dd0dd1dd2ddd3d4d5d6d7d5d8d9d7d8d:d;d7d:d<d=d7d<d>d?d7d>d2d@d7gddddddddddddAddBd!dCd$d%gd&dDgdEd)d*idFdGgZdHdI ZdJS )KSyfyIEzchttps?://(?:www\.)?syfy\.com/[^/?#]+/(?:season-\d+/episode-\d+/(?:videos/)?|videos/)(?P<id>[^/?#]+)zBhttps://www.syfy.com/face-off/season-13/episode-10/videos/keyed-upr   3774403r   rP   r   zkeyed-upr{   zKeyed Upr|   z$md5:feafd15bee449f212dcd3065bbe9a755r   r   r      r   z$re:https://www\.syfy\.com/.+/.+\.jpgr   zFace Offr   z	Season 13r      r   z Through the Looking Glass Part 2r   
   r   ij[r   20180808r   Excerptr   r  zSeries/Face Offzcount:15ztheplatform 3774403)r   r   r   r   r.   r   zShttps://www.syfy.com/face-off/season-13/episode-10/through-the-looking-glass-part-23772391z through-the-looking-glass-part-2zThrough the Looking Glass Pt.2z$md5:90bd5dcbf1059fe3296c263599af41d2r   i'
  r   g        g     8@z<Untitled Chapter 1>)
start_timeend_timer{   g|?5C@z<Untitled Chapter 2>g     @z<Untitled Chapter 3>g     8@z<Untitled Chapter 4>gw@z<Untitled Chapter 5>z<Untitled Chapter 6>igc20230101r   ztheplatform 3772391)r   r   r   r   r  r  c                 C   s   |  |}| j||ddS )Nr   )r   r  r  r2   r2   r3   r   R  s   
zSyfyIE._real_extractNr  r2   r2   r2   r3   r    s    	
	




;r  )6r%  r   rY   urllib.parser   xml.etree.ElementTreer  	adobepassr   commonr   theplatformr   r   r   
networkingr	   utilsr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   utils.traversalr    r!   r"   r   r   r   r  r0  rj  rx  r  r  r  r2   r2   r2   r3   <module>   s2    `o -#-; 3V :m