
    V|hC                     T    S SK Jr  SSKJrJrJrJr   " S S\5      r " S S\5      rg)	   )InfoExtractor   )ExtractorErrormimetype2extparse_iso8601try_getc                       \ rS rSrSrSrSrSSS0SS	S
SS\\SSS.	S.SSS./rSr	Sr
SrSSSS.rS rS rS\4S jrS rSrg)FancodeVodIE   Fzfancode:vodz6https?://(?:www\.)?fancode\.com/video/(?P<id>[0-9]+)\bz8https://fancode.com/video/15043/match-preview-pbks-vs-miskip_downloadT6249806281001mp4zMatch Preview: PBKS vs MIzre:^https?://.*\.jpg$iv9`202104226008340455001)	idexttitle	thumbnail	timestamp
view_count
like_countupload_dateuploader_id)urlparams	info_dictzhttps://fancode.com/video/15043r   only_matchingNfancodezRUse "--username refresh --password <refresh_token>" to login using a refresh tokenzapplication/jsonzhttps://fancode.com)zcontent-typeoriginrefererc                 R   US:w  a  U R                  SU R                   35        U R                  5         SU-  nU R                  SUS5      n[	        US 5      U l        U R
                  c  U R                  S5        g U R                  R                  SS	U R
                   305        g )
Nrefreshz>Login using username and password is not currently supported. a
  {
            "query":"mutation RefreshToken($refreshToken: String\u0021) { refreshToken(refreshToken: $refreshToken) { accessToken }}",
            "variables":{
                "refreshToken":"%s"
            },
            "operationName":"RefreshToken"
        }zrefresh tokenzGetting the Access tokenc                     U S   S   S   $ )NdatarefreshTokenaccessToken xs    R/home/james-whalen/.local/lib/python3.13/site-packages/yt_dlp/extractor/fancode.py<lambda>-FancodeVodIE._perform_login.<locals>.<lambda>:   s    1V9^;TUb;c    zFailed to get Access tokenAuthorizationzBearer )report_warning_LOGIN_HINTreport_logindownload_gqlr   _ACCESS_TOKENheadersupdate)selfusernamepasswordr%   
token_jsons        r+   _perform_loginFancodeVodIE._perform_login+   s    y "`aeaqaq`r st  &&>XY
$Z1cd% <=LLGD<N<N;O2P QRr.   c                     S nU(       a  U R                   c  SU R                   3nOU(       d  U R                   b  SnU(       a  U R                  USS S9  g g )Nz3This video is only available for registered users. z;This video isn't available to the current logged in accountT)metadata_availablemethod)r4   r1   raise_login_required)r7   is_available
is_premiummsgs       r+   _check_login_required"FancodeVodIE._check_login_required@   sX    $,,4GHXHXGYZC$"4"4"@PC%%cd4%P r.   c           	      D    U R                  SUUR                  5       UXTS9$ )Nzhttps://www.fancode.com/graphql)r%   noter5   fatal)_download_jsonencode)r7   variabler%   rG   rH   r5   s         r+   r3   FancodeVodIE.download_gqlI   s-    ""-xT # * 	*r.   c                    SnU R                  U5      nSnSU-  nU R                  X5SS9n[        US [        5      =(       d    0 n[        US [        5      nUc  [        S5      eUR                  S	5      n	U R                  UR                  S
5      U	5        SX$U4-  SUUS   UR                  S5      UR                  S5      UR                  S5      [        UR                  S5      5      U R                  U	S9S.
$ )NzGhttps://players.brightcove.net/%s/default_default/index.html?videoId=%sr   a  {
            "query":"query Video($id: Int\u0021, $filter: SegmentFilter) { media(id: $id, filter: $filter) { id contentId title contentId publishedTime totalViews totalUpvotes provider thumbnail { src } mediaSource {brightcove } duration isPremium isUserEntitled tags duration }}",
            "variables":{
                "id":%s,
                "filter":{
                    "contentDataType":"DEFAULT"
                }
            },
            "operationName":"Video"
        }zDownloading metadata)rG   c                     U S   S   $ )Nr%   mediar(   r)   s    r+   r,   ,FancodeVodIE._real_extract.<locals>.<lambda>b   s    671Cr.   c                     U S   S   $ )NmediaSource
brightcover(   r)   s    r+   r,   rP   c   s    q7G7Ur.   z%Unable to extract brightcove Video ID	isPremiumisUserEntitledurl_transparentBrightcoveNewr   totalUpvotes
totalViewstagspublishedTime)needs_premium)
_typer   ie_keyr   r   r   r   rZ   release_timestampavailability)
	_match_idr3   r   dictstrr   getrD   r   _availability)
r7   r   BRIGHTCOVE_URL_TEMPLATEvideo_idbrightcove_user_idr%   metadata_jsonrO   brightcove_video_idrB   s
             r+   _real_extractFancodeVodIE._real_extractO   s   "k>>#&,	 	 ))(?U)V'CTJPb%e-UWZ[& !HIIYY{+
""599-=#>
K '*BU-VV%7^))N3))L1IIf%!.uyy/I!J ..Z.H
 	
r.   )r4   )__name__
__module____qualname____firstlineno___WORKINGIE_NAME
_VALID_URLint_TESTSr4   _NETRC_MACHINEr1   r5   r;   rD   r3   rk   __static_attributes__r(   r.   r+   r
   r
      s    HGJJ JT
 "01#%*

" 1!F* MNfK +'(GS*Q 8=g *(
r.   r
   c                   R    \ rS 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./rS rSr	g)FancodeLiveIEz   Fzfancode:livez4https?://(www\.)?fancode\.com/match/(?P<id>[0-9]+).+z[https://fancode.com/match/35328/cricket-fancode-ecs-hungary-2021-bub-vs-blb?slug=commentary35328r   z
BUB vs BLBips`T20210628)r   r   r   r   is_liver   Ended)r   r   skipz https://fancode.com/match/35328/r   z.https://fancode.com/match/35567?slug=scorecardc           
         U R                  U5      nSU-  nU R                  X#S5      n[        US 5      nUR                  S5      S:w  a
  [	        SSS9eU R                  UR                  S	5      S5        UUR                  S
5      U R                  [        US 5      U5      [        [        US 5      5      S[        UR                  S5      5      S.$ )Na  {
            "query":"query MatchResponse($id: Int\u0021, $isLoggedIn: Boolean\u0021) { match: matchWithScores(id: $id) { id matchDesc mediaId videoStreamId videoStreamUrl { ...VideoSource } liveStreams { videoStreamId videoStreamUrl { ...VideoSource } contentId } name startTime streamingStatus isPremium isUserEntitled @include(if: $isLoggedIn) status metaTags bgImage { src } sport { name slug } tour { id name } squads { name shortName } liveStreams { contentId } mediaId }}fragment VideoSource on VideoSource { title description posterUrl url deliveryType playerType}",
            "variables":{
                "id":%s,
                "isLoggedIn":true
            },
            "operationName":"MatchResponse"
        }z	Info jsonc                     U S   S   $ )Nr%   matchr(   r)   s    r+   r,   -FancodeLiveIE._real_extract.<locals>.<lambda>   s    !F)G2Dr.   streamingStatusSTARTEDzThe stream can't be accessedT)expectedrU   namec                     U S   S   $ )NvideoStreamUrlr   r(   r)   s    r+   r,   r      s    RSTdRefkRlr.   c                     U S   S   $ )Nr   deliveryTyper(   r)   s    r+   r,   r      s    a@P>QR`>ar.   	startTime)r   r   formatsr   r}   r_   )	ra   r3   r   rd   r   rD   _extract_akamai_formatsr   r   )r7   r   rg   r%   	info_json
match_infos         r+   rk   FancodeLiveIE._real_extract   s    >>#&  %%hkB	Y(DE
>>+,	9 !@4PP"":>>2B#CTJ ^^F+33GJHl4mowx
4a bc!.z~~k/J!K
 	
r.   r(   N)
rm   rn   ro   rp   rq   rr   rs   ru   rk   rw   r(   r.   r+   ry   ry   z   s_    HGHJ m!#%
  2 @F&
r.   ry   N)	commonr   utilsr   r   r   r   r
   ry   r(   r.   r+   <module>r      s)    ! H Hr
= r
j4
L 4
r.   