
    yf<                         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mZmZmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Zy)    N   )AnvatoIE)InfoExtractor   )ExtractorError
clean_htmldetermine_extget_element_by_classtraverse_objurlencode_postdatac                       e Zd ZdZdZdZdd e ej                                e	j                   ej                  dddd	d
d      j                               j                         dg g dZi ZdZdZdZd Zd Zd Zy)	NFLBaseIEa  (?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)	clientKeyclientSecretdeviceId
deviceInfonetworkTypenflClaimGroupsToAddnflClaimGroupsToRemoveNr   c                 2   | j                   s6| j                  ||d      xs d}| j                  d|dd      xs d| _         | j                  d      }t	        |d| j                    d	 fd
 hfd      }|s| j                          d|vrt        dd      | j                  d|dt        dd| j                   d|d|t	        |dd hfd      dd	      ddi      }t	        |dd d!d"      | _	        t        | j                        d#k7  rt        d$d      y )%NF)fatal z*window\.gigyaApiKey\s*=\s*["\'](\w+)["\'];zAPI keyB3_Qa8TkWpIB8ESCBT8tY2TukbVKgO5F6BJVc7N1oComdwFzI7H2L9NOWdm11i_BY9fzhttps://auth-id.nfl.com/glt_c                 $    | j                  d      S )Nr)   )
startswith)k_s     6/usr/lib/python3/dist-packages/yt_dlp/extractor/nfl.py<lambda>z-NFLBaseIE._get_account_info.<locals>.<lambda>`   s    !,,v2F     c                     | j                   S )N)valuexs    r.   r/   z-NFLBaseIE._get_account_info.<locals>.<lambda>`   s    TUT[T[ r0   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cookiegig_canary_verc                 >    | j                   j                  d      d   S )N-r   )r2   	partitionr3   s    r.   r/   z-NFLBaseIE._get_account_info.<locals>.<lambda>t   s    1B1B31G1J r0   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)rP   uiduidSignature   z5Failed to retrieve account info with provided cookies)_API_KEY_download_webpage_search_regex_get_cookiesr   raise_login_requiredr   _download_jsonr   _ACCOUNT_INFOlen)selfurlslugwebpagecookiesrG   accounts          r.   _get_account_infozNFLBaseIE._get_account_infoW   s~   }},,S$e,DJG ..=w	 /  e d M ##$>?"7DMM?#%FGJ[I\-^gln%%'  CMQS S
 %%=t+2D)--"*$($'J&K3MV]_ F 3 ()LM & O *'"6*4
  t!!"a' !Xcghh (r0   c           
         | j                   r.| j                  t        t        j                         dz         kD  ry | j                  s| j                  ||       | j                  d| j                  j                  d      rdndz  |ddidt        j                  i | j                  | j                  d	
      j                               }|d   | _         |d   | _        |d   | j                  d<   y )N   z'https://api.nfl.com/identity/v3/token%srefreshTokenz/refreshr'   rL   zapplication/jsonzDownloading access tokenr   r   )rO   rM   rN   accessToken	expiresIn)_TOKEN_TOKEN_EXPIRYinttimer\   rd   r[   getrB   dumps_CLIENT_DATAencode)r^   r_   r`   tokens       r.   _get_auth_tokenzNFLBaseIE._get_auth_token   s    ;;4--DIIK"4D0EE!!""3-##5"0044^D
"N>+=>E_Gt00GD4F4FGT^_ffh	 $ j M*";/-2>-B>*r0   c           	         | j                  ||      }|d   d   }|j                  d      }|r'| j                  | j                   | t        |      }|S |j                  d      xs |d   }|j                  d      }|d   }d|i}t        |      }	|	dk(  r| j                  ||d	      |d
<   n||d<   |j                  d      du rd|d<   |j                  d      du }
d }|j                  |j                  d            xs  |j                  |j                  d            }|r|t        |d      dg}|j                  ||
t        |j                  d            |d       |S )Nplaylistr   mcpIDidentityIdtitler_   m3u8mp4formatsaudioTnonevcodecliveimageSrcposterImagejpg)r_   extdescription)ry   is_liver   
thumbnails)	_parse_jsonrn   
url_result_ANVATO_PREFIXr   r	   _extract_m3u8_formatsupdater   )r^   video_config
display_iditemmcp_idinfomedia_idry   item_urlr   r   r   	image_urls                r.   _parse_video_configzNFLBaseIE._parse_video_config   s|   ''jAJ'*'"??d&9&9%:6(#CXvVD6 3 xx~9j)9HHHW%EE{H(#D)Cf}"&"<"<XxQV"WY&U88G$,%+DN"&&v.$6GJ*!56[$((488MCZ:[I$(E: 
 KK")$((=*AB(	  r0   )__name__
__module____qualname___VALID_URL_BASE_VIDEO_CONFIG_REGEXr   struuiduuid4base64	b64encoderB   ro   rq   decoderp   r\   rV   rj   rk   rd   rs   r    r0   r.   r   r      s    +OX N?N 8*


%&f&&ztzz	3

 !("
 #)&(,
 -3FH!"$L MHFM(iTC" r0   r   c                   ~    e Zd 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dddddgZd Zy) NFLIEz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:85e05a3cc163f8c344340f220521136d20201215iH_zre:^https?://.*\.jpg$NFLzcount:6   zcount:3)rw   r   ry   r   upload_date	timestamp	thumbnailuploadertagsduration
categories)r_   	info_dictzchttps://www.chiefs.com/listen/patrick-mahomes-travis-kelce-react-to-win-over-dolphins-the-breakdown 6886b32c24b463038c760ceb55a34566z$d87e8790-3e14-11eb-8ceb-ff05c2867f99mp3zHPatrick Mahomes, Travis Kelce React to Win Over Dolphins | The Breakdownz$md5:12ada8ee70e6762658c30e223e095075)rw   r   ry   r   zHTTP Error 404: Not Found)r_   md5r   skipzMhttps://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                     | j                  |      }| j                  ||      }| j                  | j                  | j                  |d      |      S )Nzvideo config)	_match_idrW   r   rX   r   )r^   r_   r   ra   s       r.   _real_extractzNFLIE._real_extract   sT    ^^C(
((j9''(:(:$$g~)?@JL 	Lr0   N)	r   r   r   IE_NAMEr   r   
_VALID_URL_TESTSr   r   r0   r.   r   r      s    G**-YYJgRA%#1#
  u18_A	
 ,
 _ |9FBLr0   r   c                   F    e Zd ZdZej
                  dz   ZddddddZd	 Zy
)NFLArticleIEz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)rw   ry      )r_   r   playlist_countc                 T   | j                  |      }| j                  ||      }g }t        j                  | j                  |      D ]#  }|j                  | j                  ||             % t        t        d|            xs | j                  ddg|      }| j                  |||      S )Nznfl-c-article__titlezog:titleztwitter:title)r   rW   refindallr   appendr   r   r
   _html_search_metaplaylist_result)r^   r_   r   ra   entriesr   ry   s          r.   r   zNFLArticleIE._real_extract   s    ^^C(
((j9JJt'?'?I 	OLNN433L*MN	O/"G- . 4151G1G)724 	 ##GZ??r0   N)	r   r   r   r   r   r   r   _TESTr   r   r0   r.   r   r      s;    G**-EEJ Ddv
 E	@r0   r   c                       e Zd ZdZdZddddddd	d
ddgg dddddiddddddiddddddidddddddddd d!dgd"gdddd#d$d%giid&d'gZd(d)d*d+d,Zd- Zy.)/NFLPlusReplayIEz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, 2023r   20230116iH%ci  zGame Highlights)zMinnesota VikingszNew York Giantsz%Minnesota Vikings vs. New York Giantsre:^https?://.*\.jpgrw   r   ry   r   r   r   r   r   r   r   r   skip_downloadrz   )r_   r   paramsSubscription requiredz<https://www.nfl.com/plus/games/giants-at-vikings-2022-post-1r   rw   zgiants-at-vikings-2022-post-1)rM   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rM   r_   r   r   z	Full GamezFull Game - SpanishzCondensed GamezAll-22)	full_gamefull_game_spanishr   all_22c                 x     j                  |      j                  dd      \  }} j                  ddg      dv r#t         j                  j                               t         j                  d f      |s{ j                  ||       dd j                   i} j                  d| |dd	d
i|      d   } j                  d|dd|i|      t              dk(  rt        dfddfd      }|r% j                   j                   | t        |      S  fd} j                   |       |      S )Nr`   rw   r   allAuthorizationBearer z6https://api.nfl.com/football/v2/games/externalId/slug/zDownloading game IDwithExternalIdstrue)queryrO   z-https://api.nfl.com/content/v1/videos/replayszDownloading replays JSONgameIdr   itemsc                     |d   d   k(  S )NsubTyper   r   r-   vrequested_typess     r.   r/   z/NFLPlusReplayIE._real_extract.<locals>.<lambda>H  s    !I,/!:L*L r0   mcpPlaybackIdFr5   c               3      K   t        dfdf      D ].  } | d   }j                  j                   | t        |       0 y w)Nr   c                      |d   xr |d   v S )Nr   r   r   r   s     r.   r/   z@NFLPlusReplayIE._real_extract.<locals>.entries.<locals>.<lambda>O  s    /0B0fq|WfGf r0   r   )r   r   r   r   )replayvideo_idreplaysr   r^   s     r.   r   z.NFLPlusReplayIE._real_extract.<locals>.entriesM  sX     &'#fg ^ "/2oo)<)<(=hZ&H(T\]]	^s   AA)_match_valid_urlgroup_configuration_arglist_REPLAY_TYPESkeysr   rs   rj   r[   r]   r   r   r   r   )	r^   r_   r`   r   rO   game_idr   r   r   s	   `      @@r.   r   zNFLPlusReplayIE._real_extract6  sn   ..s399&$Gh11&5'BO#"4#5#5#:#:#<=O&t'9'9D/;RS  d+&'$++(?@G))HOQU%.?-HRY * [[_aG ))?Ga)7 * <G ?#q('Lo2_hmo ??d&9&9%:8*#ExQYZZ	^ ##GIt44r0   N)r   r   r   r   r   r   r   r   r   r0   r.   r   r      s    #G\JU;p%#,-e0
 #F+" (M1
	 (M1
	 (M(E%#,-#$0
 $.:J9K0LM
!=2Fj !2*	M5r0   r   c                   J    e Zd ZdZdZddddddd	d
dddgdgddddidgZd Zy)NFLPlusEpisodeIEz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   rz   r   c                     | j                  |      }| j                  ||       | j                  d| |dd| j                   i      d   }| j	                  | j
                   | t        |      S )Nz/https://api.nfl.com/content/v1/videos/episodes/r   r   )rO   r   )r   rs   r[   rj   r   r   r   )r^   r_   r`   r   s       r.   r   zNFLPlusEpisodeIE._real_extractm  s    ~~c"S$'&&=dVDd74;;-!8U '   
 $"5"5!6xjA8XVVr0   N)r   r   r   r   r   r   r   r   r0   r.   r   r   W  sY    $GLJ']/A%#%,MN0
 #F+! F&Wr0   r   )r   rB   r   rm   r   anvator   commonr   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   r0   r.   <module>r      sm      	    ! _ _D(LI (LV@9 @0\5i \5~Wy Wr0   