
    V|h4?                         S SK r S SKrS SKrS SKrS SKrSSKJr  SSKJr  SSK	J
r
JrJrJrJrJrJrJr  SSKJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      rg)    N   )AnvatoIE)InfoExtractor   )ExtractorError
clean_htmldetermine_extget_element_by_classint_or_nonemake_archive_idurl_or_noneurlencode_postdata)traverse_objc                      \ rS rSrSrSrSrSS\" \R                  " 5       5      \
R                  " \R                  " SSS	S
S.SS9R                  5       5      R                  5       SSS.r0 rSrSrSrS rS rSS jrS rSrg)	NFLBaseIE   a  (?x)
                    https?://
                        (?P<host>
                            (?:www\.)?
                            (?:
                                (?:
                                    nfl|
                                    buffalobills|
                                    miamidolphins|
                                    patriots|
                                    newyorkjets|
                                    baltimoreravens|
                                    bengals|
                                    clevelandbrowns|
                                    steelers|
                                    houstontexans|
                                    colts|
                                    jaguars|
                                    (?:titansonline|tennesseetitans)|
                                    denverbroncos|
                                    (?:kc)?chiefs|
                                    raiders|
                                    chargers|
                                    dallascowboys|
                                    giants|
                                    philadelphiaeagles|
                                    (?:redskins|washingtonfootball)|
                                    chicagobears|
                                    detroitlions|
                                    packers|
                                    vikings|
                                    atlantafalcons|
                                    panthers|
                                    neworleanssaints|
                                    buccaneers|
                                    azcardinals|
                                    (?:stlouis|the)rams|
                                    49ers|
                                    seahawks
                                )\.com|
                                .+?\.clubs\.nfl\.com
                            )
                        )/
                    zp<script[^>]+id="[^"]*video-config-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}[^"]*"[^>]*>\s*({.+});?\s*</script>z(anvato:GXvEgwyJeWem8KCYXfeoHWknwP48Mboj: 4cFUW6DmwJpzT9L7LrG3qRAcABG5s04gCZuvCL49d9OwfGsRdesktopChromeWindowsz10.0)modelversionosName	osVersion,:
separatorsother	undefined)	clientKeyclientSecretdeviceId
deviceInfonetworkTypepeacockUUIDB3_Qa8TkWpIB8ESCBT8tY2TukbVKgO5F6BJVc7N1oComdwFzI7H2L9NOWdm11i_BY9fNr   c                    U R                  S5      n[        USU R                   3S 4S 14SS9nU(       d  U R                  5         SU;  a
  [	        SS	S
9eU R                  SS S[        SSU R                  SUSS[        USS 14SS9SS.	5      SS0S9n[        USSSS.5      U l        [        U R                  5      S:w  a
  [	        S S	S
9eg )!Nzhttps://auth-id.nfl.com/glt_c                 $    U R                  S5      $ )Nr+   )
startswith)k_s     N/home/james-whalen/.local/lib/python3.13/site-packages/yt_dlp/extractor/nfl.py<lambda>-NFLBaseIE._get_account_info.<locals>.<lambda>\   s    !,,v2F    c                     U R                   $ N)valuexs    r0   r1   r2   \   s    TUT[T[r3   Fget_allucidzRequired cookies for the auth-id.nfl.com domain were not found among passed cookies. If using --cookies, these cookies must be exported along with .nfl.com cookies, or else try using --cookies-from-browser insteadT)expectedz/https://auth-id.nfl.com/accounts.getAccountInfozDownloading account infozprofile,dataen	js_latestcookiezhttps://www.nfl.com/gig_canary_verc                 >    U R                   R                  S5      S   $ )N-r   )r6   	partitionr7   s    r0   r1   r2   p   s    1B1B31G1Jr3   15170)defaultjson)	includelangAPIKeysdklogin_tokenauthModepageURLsdkBuildformatContent-Typez!application/x-www-form-urlencoded)notedataheaderssignatureTimestampUIDUIDSignature)rT   uiduidSignature   z5Failed to retrieve account info with provided cookies)	_get_cookiesr   _API_KEYraise_login_requiredr   _download_jsonr   _ACCOUNT_INFOlen)selfcookiesrK   accounts       r0   _get_account_infoNFLBaseIE._get_account_infoY   s,   ##$>?"7DMM?#%FGJ[I\-^gln%%'  CMQS S
 %%=t+2D)--"*$1($'J&K3MV]_ F 3 ()LM & O *'"6*4
  t!!"a' !Xcghh (r3   c                    U R                   (       a0  U R                  [        [        R                  " 5       S-   5      :  a  g U R	                  SU R
                  R                  S5      (       a  SOS-  S SS0S[        R                  " 0 U R                  EU R
                  ES	S
9R                  5       S9nUS   U l         US   U l        US   U R
                  S'   g )N   z'https://api.nfl.com/identity/v3/token%srefreshTokenz/refresh rP   application/jsonzDownloading access tokenr   r   )rS   rQ   rR   accessToken	expiresIn)_TOKEN_TOKEN_EXPIRYinttimer]   r^   getrF   dumps_CLIENT_DATAencode)r`   tokens     r0   _get_auth_tokenNFLBaseIE._get_auth_token}   s    ;;4--DIIK"4D0EE##5"0044^DD
"N>+=>E_Gt00GD4F4FGT^_ffh	 $ j M*";/-2>-B>*r3   c                    U R                  5         U R                  SU 3USU R                   3SSS.[        R                  " SUS.SS9R                  5       S	9nU R                  US
   USSS9u  pEUUUU[        [        U5      /S.[        USSS[        1[        4SS[        14SS[        14SSSS[        104S.45      E$ )Nz"https://api.nfl.com/play/v1/asset/Bearer ri   )AuthorizationAcceptrP   T)initliver   r   )rS   rR   	accessUrlmp4hls)m3u8_id)idformats	subtitlesis_live_old_archive_idsmetadataevent)	def_titlefriendlyNamedef_descriptionduration
thumbnails.url)titledescriptionr   r   )ru   r]   rl   rF   rq   rs   #_extract_m3u8_formats_and_subtitlesr   r   r   stranyr   r   )r`   mcp_idr   rR   r   r   s         r0   _extract_videoNFLBaseIE._extract_video   s   ""096#*4;;-!8, 2L JJg>:V]]_ # a "EEvue F = "!06!B C
 4*!#@3%M '):SEB$j;-@+S%%+9OP	/ " 
 	
r3   c           	      L   U R                  X5      n[        US[        145      =(       d    SnUS   S   nUR                  S5      =n(       a  U R	                  XSS9$ SUR                  S5      =(       d    US   0nUS	   n[        U5      nUS
:X  a  U R                  XvS   S5      US'   OXvS	'   UR                  S5      SL a  SUS'   S n	[        USS[        S9=n
(       a  U
[        U
S5      S./n	UR                  0 [        US[        14S[        14S.5      EUU	S.E5        U$ )Nr|   Fplaylistr   mcpID)r   r   entityIdr   m3u8r~   r   audioTnonevcodecimageSrcposterImage)expected_typejpg)r   extr   r   )r   r   )r   r   )_parse_jsonr   boolrp   r   r	   _extract_m3u8_formatsr   updater   r   )r`   video_config
display_idr   itemr   infoitem_urlr   r   	image_urls              r0   _parse_video_configNFLBaseIE._parse_video_config   sV   ''A|ftf-=>G%J'*XXg&&6&&&v&??dhhtn8Z(89;H%&="88:uUDO"Kxx D(!'X
$T:}T_``9` $Y6 J
 	 
4!C5) -
|<" 

 $
 	 r3   )r^   rl   rm   )F)__name__
__module____qualname____firstlineno___VALID_URL_BASE_VIDEO_CONFIG_REGEX_ANVATO_PREFIXr   uuiduuid4base64	b64encoderF   rq   rs   decoderr   r^   r[   rl   rm   rc   ru   r   r   __static_attributes__ r3   r0   r   r      s    +OX N?N 8*

%&&tzz	3

 !("
 #)&(,
 -3FH"L MSHFM"iHC
2!r3   r   c            	           \ rS rSrSr\R                  S-   rSSSSSS	S
S/S.S.SSSSSSSS.S.SSS.SSS./rS r	Sr
g)NFLIE   znfl.comz)(?:videos?|listen|audio)/(?P<id>[^/#?&]+)zVhttps://www.nfl.com/videos/baker-mayfield-s-game-changing-plays-from-3-td-game-week-14899441r~   z;Baker Mayfield's game-changing plays from 3-TD game Week 14z$md5:85e05a3cc163f8c344340f220521136dzre:https?://.+\.jpg   zanvato 899441)r   r   r   r   	thumbnailr   r   )r   	info_dictzchttps://www.chiefs.com/listen/patrick-mahomes-travis-kelce-react-to-win-over-dolphins-the-breakdown 92a517f05bd3eb50fe50244bc621aec8z$8b7c3625-a461-4751-8db4-85f536f2bbd0mp3zHPatrick Mahomes, Travis Kelce React to Win Over Dolphins | The Breakdownz$md5:12ada8ee70e6762658c30e223e095075zshttps://static.clubs.nfl.com/image/private/t_editorial_landscape_12_desktop/v1571153441/chiefs/rfljejccnyhhkpkfq855)r   r   r   r   r   )r   md5r   zMhttps://www.buffalobills.com/video/buffalo-bills-military-recognition-week-14T)r   only_matchingzjhttps://www.raiders.com/audio/instant-reactions-raiders-week-14-loss-to-indianapolis-colts-espn-jason-fitzc                     U R                  U5      nU R                  X5      nU R                  U R                  U R                  US5      U5      $ )Nzvideo config)	_match_id_download_webpager   _search_regexr   )r`   r   r   webpages       r0   _real_extractNFLIE._real_extract   sR    ^^C(
((9''(:(:$$g~)?@JL 	Lr3   r   N)r   r   r   r   IE_NAMEr   r   
_VALID_URL_TESTSr   r   r   r3   r0   r   r      s    G**-YYJgRA/!0 1
 u18_A O

 _ |1F:Lr3   r   c                   N    \ rS rSrSr\R                  S-   rSSSS.SS	.rS
 r	Sr
g)NFLArticleIE   znfl.com:articleznews/(?P<id>[^/#?&]+)zrhttps://www.buffalobills.com/news/the-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-ezPthe-only-thing-we-ve-earned-is-the-noise-bills-coaches-discuss-handling-rising-ez_'The only thing we've earned is the noise' | Bills coaches discuss handling rising expectations)r   r      )r   r   playlist_countc                    ^ ^^ T R                  U5      mT R                  UT5      mUU U4S jn[        [        ST5      5      =(       d    T R	                  SS/T5      nT R                  U" 5       TU5      $ )Nc               3      >#    [         R                  " TR                  T5       H  n TR                  U T5      v   M     g 7fr5   )refindallr   r   )r   r   r`   r   s    r0   entries+NFLArticleIE._real_extract.<locals>.entries   s5      "

4+C+CW M..|ZHH !Ns   >Aznfl-c-article__titlezog:titleztwitter:title)r   r   r   r
   _html_search_metaplaylist_result)r`   r   r   r   r   r   s   `   @@r0   r   NFLArticleIE._real_extract   s{    ^^C(
((j9	I /"G- . 4151G1G)724 	 ##GIz5AAr3   r   N)r   r   r   r   r   r   r   r   _TESTr   r   r   r3   r0   r   r      s;    G**-EEJ Ddv
 EBr3   r   c                       \ rS rSrSrSrSSSSSS	S
SSS// SQSS.SS0S.SSSSS0S.SSSSS0S.SSSSSSS	S S!S"S/S#/SS.SS$S%S&/00S'.S(./rS)S*S+S,S-.rS. rS/ r	S0r
g1)2NFLPlusReplayIEi
  znfl.com:plus:replayzHhttps?://(?:www\.)?nfl\.com/plus/games/(?P<slug>[\w-]+)(?:/(?P<id>\d+))?zDhttps://www.nfl.com/plus/games/giants-at-vikings-2022-post-1/15721081572108r~   z$New York Giants at Minnesota VikingszSNew York Giants play the Minnesota Vikings at U.S. Bank Stadium on January 15, 2023NFL20230116iH%ci  zGame Highlights)zMinnesota VikingszNew York Giantsz%Minnesota Vikings vs. New York Giantsre:^https?://.*\.jpgr   r   r   r   uploaderupload_date	timestampr   
categoriestagsr   skip_downloadr   )r   r   paramsSubscription requiredz<https://www.nfl.com/plus/games/giants-at-vikings-2022-post-1r   r   zgiants-at-vikings-2022-post-1)rQ   r   r   r   z<https://www.nfl.com/plus/games/giants-at-patriots-2011-pre-4r   zgiants-at-patriots-2011-pre-4950701zGiants @ Patriotsz(Giants at Patriots on September 01, 201120210724i2\`i  zplay-by-playnflplusreplaytypecondensed_game)r   extractor_argsrQ   r   r   r   z	Full GamezFull Game - SpanishzCondensed GamezAll-22)	full_gamefull_game_spanishr   all_22c                 $    U R                  5         g r5   rc   r`   s    r0   _real_initialize NFLPlusReplayIE._real_initializeH       r3   c                 V  ^ ^^ T R                  U5      R                  SS5      u  p#T R                  SS/5      mST;   a#  [        T R                  R                  5       5      m[        T R                  S T45      mU(       dr  T R                  5         SST R                   30nT R                  SU 3USS	S
0US9S   nT R                  SUSSU0US9m[        T5      S:X  a  [        TSU4S jS4SS9nU(       a  T R                  U5      $ UUU 4S jnT R                  U" 5       U5      $ )Nslugr   r   allry   rx   z6https://api.nfl.com/football/v2/games/externalId/slug/zDownloading game IDwithExternalIdstrue)queryrS   z-https://api.nfl.com/content/v1/videos/replayszDownloading replays JSONgameIdr   itemsc                    > US   TS   :H  $ )NsubTyper   r   r/   vrequested_typess     r0   r1   /NFLPlusReplayIE._real_extract.<locals>.<lambda>]  s    !I,/!:L*Lr3   mcpPlaybackIdFr9   c               3   l   >#    [        TSU4S j45       H  n TR                  U S   5      v   M     g 7f)Nr  c                 ,   > US   =(       a    US   T;   $ )Nr  r	  r   r
  s     r0   r1   @NFLPlusReplayIE._real_extract.<locals>.entries.<locals>.<lambda>d  s    /0B0fq|WfGf0fr3   r  )r   r   )replayreplaysr  r`   s    r0   r   .NFLPlusReplayIE._real_extract.<locals>.entriesb  s8     &'#fg ))&*ABBs   14)_match_valid_urlgroup_configuration_arglist_REPLAY_TYPESkeysr   ru   rl   r]   r_   r   r   )	r`   r   r  video_idrS   game_idr   r  r  s	   `      @@r0   r   NFLPlusReplayIE._real_extractK  sU   ..s399&$G11&5'BO#"4#5#5#:#:#<=O&t'9'9D/;RS  "&'$++(?@G))HOQU%.?-HRY * [[_aG ))?Ga)7 * <G ?#q('Lo2_hmo &&x00	C ##GIt44r3   r   N)r   r   r   r   r   r   r   r  r   r   r   r   r3   r0   r   r   
  s    #G\JU;p%#,-e0
 #F+" (M1
	 (M1
	 (M(E%#,-#$0
 $.:J9K0LM
!=2Fj !2*	M!5r3   r   c                   X    \ rS rSrSrSrSSSSSS	S
SSSS/S/SS.SS0S./rS rS rSr	g)NFLPlusEpisodeIEik  znfl.com:plus:episodez8https?://(?:www\.)?nfl\.com/plus/episodes/(?P<id>[\w-]+)r   zLhttps://www.nfl.com/plus/episodes/kurt-s-qb-insider-conference-championships1576832r~   zConference Championshipsz$md5:944f7fab56f7a37430bf8473f5473857r   20230127i((ci  Analysisz6Cincinnati Bengals at Kansas City Chiefs (2022-POST-3)r   r   r   r   r   c                 $    U R                  5         g r5   r   r   s    r0   r   !NFLPlusEpisodeIE._real_initialize  r   r3   c                     U R                  U5      nU R                  5         U R                  SU 3USSU R                   30S9S   nU R	                  U5      $ )Nz/https://api.nfl.com/content/v1/videos/episodes/ry   rx   )rS   r  )r   ru   r]   rl   r   )r`   r   r  r  s       r0   r   NFLPlusEpisodeIE._real_extract  sp    ~~c"&&=dVDd74;;-!8U '   
 ""8,,r3   r   N)
r   r   r   r   r   r   r   r   r   r   r   r3   r0   r  r  k  s]    $GLJ']/A%#%,MN0
 #F+! F&!-r3   r  )r   rF   r   ro   r   anvator   commonr   utilsr   r   r	   r
   r   r   r   r   utils.traversalr   r   r   r   r   r  r   r3   r0   <module>r+     su      	    !	 	 	 +o od$LI $LNB9 B6^5i ^5B!-y !-r3   