
    VGh<R                         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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 d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   )InfoExtractorSearchInfoExtractor   )ExtractorErrordetermine_extfloat_or_noneformat_fieldint_or_nonestr_or_nonetraverse_objtry_getunescapeHTMLunified_timestampurl_or_noneurlencode_postdataz8https://prod-api-v2.production.rokfin.com/api/v2/public/c                      e Zd ZdZdZdZi Zdddddd	d
dddddeedddddddddddddddeeddgdddi dd d!dd"d#d$dd%d&d'd(d)d*d+d,d-dd.d/d0d1d2d0d3d4d5d4d6d7d8d7d9eedgd:dd;i dd<d!dd"d=d$dd'd>d)d?d+d@d-dAd2dd9edBed3dCd8dDdEddFgd%dGdHdIddJi ddKd!dd"dLd$dMd'dNd)dOd+dPd-dAd2d0d9edBed3dQd5dRd6dSd8dSdEdgdgZdT Z	dU Z
dV ZdW ZdX Zi i fdYZyZ)[RokfinIEz@https?://(?:www\.)?rokfin\.com/(?P<id>(?P<type>post|stream)/\d+)rokfinzHhttps://secure.rokfin.com/auth/realms/rokfin-web/protocol/openid-connectzOhttps://www.rokfin.com/post/57548/Mitt-Romneys-Crazy-Solution-To-Climate-Changez
post/57548mp4z.Mitt Romney's Crazy Solution To Climate Changez*re:https://img\.production\.rokfin\.com/.+20211023itaz
Jimmy Dore65429z#https://rokfin.com/TheJimmyDoreShowpublicnot_live   )idexttitle	thumbnailupload_date	timestampchannel
channel_idchannel_urlavailabilitylive_statusdislike_count
like_countduration)url	info_dictzJhttps://rokfin.com/post/223/Julian-Assange-Arrested-Streaming-In-Real-Timezpost/223z/Julian Assange Arrested: Streaming In Real Time20190412id8\zRon Placone10zhttps://rokfin.com/RonPlaconezFreeThinkingMedia^zRealProgressives^)r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   tagszrhttps://www.rokfin.com/stream/10543/Its-A-Crazy-Mess-Regional-Director-Blows-Whistle-On-Pfizers-Vaccine-Trial-Datar   zstream/10543r   r   zR"It's A Crazy Mess" Regional Director Blows Whistle On Pfizer's Vaccine Trial Datar   descriptionz$md5:324ce2d3e3b62e659506409e458b9d8er"   TLAVagabondr#   53856r$   zhttps://rokfin.com/TLAVagabondr%   is_liveFwas_liveTr&   r!   iwarelease_timestamprelease_date20211102r    r'   )r(   r.   zihttps://rokfin.com/post/126703/Brave-New-World--Aldous-Huxley-DEEPDIVE--Chpts-13--Quite-Frankly--Jay-Dyerzpost/126703zQBrave New World - Aldous Huxley DEEPDIVE!  (Chpts 1-3) - Quite Frankly & Jay DyerzJay Dyer186881zhttps://rokfin.com/jaydyerpremium_onlyr(   id20230307r.   z	OpenMind^z$md5:cb04e32e68326c9b2b251b297bacff35r)   i  zJhttps://rokfin.com/stream/31332/The-Grayzone-live-on-Nordstream-blame-gamezstream/31332z*The Grayzone live on Nordstream blame gamez#re:https://image\.v\.rokfin\.com/.+zMax Blumenthal248902z https://rokfin.com/MaxBlumenthalidg  A20230310c                    | j                  |      j                  dd      \  }}| j                  t         | |      }t	        |j                  d            }|j                  d      rdn|rdn|dk(  rdnd	}t        |d
dt              }|dv r1t        | j                  dt        |ddt              |d       d d      }|rd
|igng i }	}t        |      dk(  r| j                  ||d|dk(        \  }}	|sgt        |dd      r| j                  ddd       nE|rC| j                  dt        j                  j!                  |      j#                  d       |d       t        |dd       }
|xs7 t%        |j                  d!      d"      xs t	        |j                  d#            }i d|d$|d%|	d&t'        t        |d&d'            d(t%        t        |d)            d*t        t        |d*d+            d,t'        t        |d,d-            d.t)        |j                  d/            d0t)        |j                  d1            d2t'        t        |d3d4            d5t'        t        |d6d7            d8|
rt        d9|
       nd d:|d;|d	k7  r|nd d<t        |d=t&              d>|d?| j+                  t-        t        |dd            dddd@      dA|dBk(  r| j/                  |      iS d iS )CNr   typescheduledAt	stoppedAtr3   is_upcomingstreamr2   r   r*   )content
contentUrlexpected_type)Nz	fake.m3u8z%https?://[^/]+/([^/]+)/storyboard.vtttimelineUrl)rB   rF   defaultz#https://stream.v.rokfin.com/%s.m3u8m3u8F)fatallivepremiumPlanpremiumz-This video is only available to premium usersTcookies)methodz!Stream is offline; scheduled for z%Y-%m-%d %H:%M:%S)video_idexpected)	createdByusername)creatorrS   postedAtMillii  creationDateTimeformats	subtitlesr   rB   contentTitler)   )rB   r)   r   )rB   thumbnailUrl1r/   )rB   contentDescriptionr(   	likeCountr'   dislikeCountr"   )rR   name)rT   r_   r#   )rR   r   )rT   r   r$   https://rokfin.com/r!   r4   r.   )r.   .r   r&   r%   )needs_premium
is_privateneeds_subscription
needs_authis_unlisted__post_extractorpost)_match_valid_urlgroup!_download_json_using_access_token_API_BASE_URLr   getr   r   r
   _search_regexr   #_extract_m3u8_formats_and_subtitlesraise_login_requiredraise_no_formatsdtdatetimefromtimestampstrftimer	   r   r   _availabilityboolextract_comments)selfr*   rP   
video_typemetadata	scheduledr&   	video_urlrW   rX   uploaderr!   s               `/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/rokfin.py_real_extractzRokfinIE._real_extract   s   #44S9??fM*99]OH::VX`a%hll=&AB	%-\\+%>z-6M)3x)?I& 	
 !52K[fg	++$T%7%78X}6P`kl$ &8 &( *./TVI
 6?ui01B#v-!%!I!I85{i7O "J "QGY HmY?))*Y[_hq)r%%78Q8QR[8\8e8efy8z7{|% & 6  *CE\] L-_0Mt"T L)(,,7I*JK 	
(
w
 
 [hA\!]^	

 l8=T&UV
 \(KIe%fg
 ;|HmMn'op
 +hll;&?@
 [n)EF
 {<:OQd#ef
 +l8=PRc&de
 H;)<XJ'GHZ^
 
  kZ.GT
 L+AQ\]
  ;!
" D.."<-#ST UuZ_ / a#
* :QWCW 5 5h ?+
 	
* ^b+
 	
    c              #     K   d }t        j                         D ]O  }| j                  t         d|dd   d| d|d|dz    t	        |d d       d	      xs i }|j                  d
      xs g D ]  }t        |j                  d            t        |j                  d            |j                  d      |j                  d      dt        |j                  d            t        |j                  d            t        |j                  d            d  t        |j                  d            xs d }|j                  d      }|j                  d
      r|s|r	||kD  sH y |dusP y  y w)Nzcomment?postId=   z&page=&size=50z!Downloading viewer comments page r    of %sFnoterJ   rB   commentr_   	commentIduserIdrootnumLikesnumDislikespostedAt)textauthorr   	author_idparentr(   r'   r!   
totalPageslast)		itertoolscount_download_jsonrk   r
   rl   r   r   r   )rx   rP   pages_totalpage_nraw_commentsr   is_lasts          r~   _get_commentszRokfinIE._get_comments   sx    oo' 	F.. /!"fVHHU!B6A:,|\gimowOxNyz /  # !# 
 (++I6<" 
'I(>?)'++f*=>!++k2!(X!6$"-gkk*.E"F%0]1K%L!27;;z3J!K	 	
 &l&6&6|&DEMK"&&v.G##I.'Vaf{>R hov{g{+	s   EE-!E-)E-c                    | j                  | j                   dd dd      }t        | j                  d|d            }| j                  |d dd	d
t	        ||ddd            }| j                         s2t        j                  d|xs d      rt        dd      t        d      | j                  | j                   dd ddddddddd      }| j                  | j                   dd d d!t	        t        j                  j                  t        j                  j                  |j                        j                         j#                  d      d"   dd#dd$      %      | _        y )&Nzw/auth?client_id=web&redirect_uri=https%3A%2F%2Frokfin.com%2Ffeed&response_mode=fragment&response_type=code&scope=openidzloading login pagezerror loading login page)r   errnotezr<form\s+[^>]+action\s*=\s*"(https://secure\.rokfin\.com/auth/realms/rokfin-web/login-actions/authenticate\?[^"]+)"zAuthentication URL)r_   z
logging inF  off )rS   password
rememberMecredentialId)r   rJ   expected_statusdataz((?i)(invalid\s+username\s+or\s+password)zinvalid username/passwordTrQ   zLogin failedz/authzgranting user authorizationz%user authorization rejected by Rokfinwebnonez(https://rokfin.com/silent-check-sso.htmlfragmentcodeopenid)	client_idpromptredirect_uriresponse_moderesponse_typescope)r   r   query/tokenzgetting access credentialsz error getting access credentialsr   authorization_code)r   r   
grant_typer   r   r   r   )_download_webpage
_AUTH_BASEr   rm   r   _authentication_activeresearchr   _request_webpager   urllibparseparse_qs	urldefragr*   r   rl   _access_mgmt_tokens)rx   rS   r   
login_pageauthentication_point_url	resp_bodyurlhs          r~   _perform_loginzRokfinIE._perform_login   s   ++   W  X+5O , Q
 $00B0B B1 1C 13 $4  **$dU\_#x_dvx$yz + |	 **,yyDioSUV$%@4PP 00$$u%t.8_"  J!+!'! % 
 $(#6#6v&-7Y#--fll.D.DTXX.N.W.WX\\]cdefg"2 J	%  $7 $ r   c                 V    h dt        | j                  | j                              z
   S )N>   KEYCLOAK_SESSIONKEYCLOAK_IDENTITYKEYCLOAK_SESSION_LEGACYKEYCLOAK_IDENTITY_LEGACY)set_get_cookiesr   rx   s    r~   r   zRokfinIE._authentication_active   s+    l$##DOO4567 	7r   c                 0    t        | j                  d       S )Nc                 4    dj                  | d   | d   g      S )N 
token_typeaccess_token)join)xs    r~   <lambda>z*RokfinIE._get_auth_token.<locals>.<lambda>  s    388Q|_VWXfVgDh;i r   )r   r   r   s    r~   _get_auth_tokenzRokfinIE._get_auth_token  s    t//1ijjr   c                    d|vsJ |j                         }| j                         }| j                  j                  d      }|r||d<   | j	                  ||||d      \  }}|r|j
                  dk7  s|| j                  ||      S | j                  | j                   d|ddt        d|dd	      
      | _        | j                         |d<   |d   t        dd      | j                  ||||      S )Nauthorizationrefresh_tokeni  )headersr   r   r   zDUser authorization expired or canceled by Rokfin. Re-authorizing ...zFailed to re-authorizer   )r   r   r   r   zUser authorization lostTr   )r   r   )copyr   r   rl   _download_webpage_handlestatus_parse_jsonr   r   r   r   )	rx   url_or_requestrP   r   r   
auth_tokenr   json_stringr   s	            r~   rj   z*RokfinIE._download_json_using_access_token  s'   g---,,.))+
0044_E'1GO$ 99HgUTW : YTT[[C/=3H##K::#'#6#6v&Way#-!."%  $7 $  $(#7#7#9 ?#+ !:TJJ"">8WTY"ZZr   N)__name__
__module____qualname__
_VALID_URL_NETRC_MACHINEr   r   int_TESTSr   r   r   r   r   rj    r   r~   r   r      sZ   TJN[J`FF%##!@$% 
& \FF%#$:$% )+>?
& D
.
5
 k
 F	

 A
 }
 '
 ;
 H
 u
 
 :
 
  
 J
  :!
" S#
$ )*'
0 {
-
5
 h
 F	

 z
 (
 7
 N
 :
 S
 #
 
 :
 );7
 A
  !
* \
.
5
 A
 ?	

 '
 (
 =
 N
 :
 S
 #
 
  
 J
 :
  )*!
_cFJ7
r2$L7
k SU\^ [r   r   c                   "    e Zd ZddddddZd Zy)RokfinPlaylistBaseIErg   rA   stackvideoaudiorA   dead_streamr   c              #   T  K   |j                  d      xs g D ]  }| j                  j                  |j                  d            }|dk(  r|j                  d      n|j                  d      }|r|sY| j                  d| d| | d| t        t	        |d            	        y w)
NrB   	mediaTyperg   r   mediaIdr`   /rY   )rP   video_title)rl   _TYPES
url_resultr   r   )rx   rz   rB   
media_typerP   s        r~   _get_video_dataz$RokfinPlaylistBaseIE._get_video_data)  s     ||I.4" 	oG[)ABJ,6&,@w{{4(gkkR[F\HX//$7
|1XJ"O]g\hhijrisZt.9,wPk:l.m " o o	os   B&B(N)r   r   r   r   r   r   r   r~   r   r      s    For   r   c                   0    e Zd ZdZdZdZddddidgZd	 Zy
)RokfinStackIEzrokfin:stackzRokfin Stacksz2https?://(?:www\.)?rokfin\.com/stack/(?P<id>[^/]+)zShttps://www.rokfin.com/stack/271/Tulsi-Gabbard-Portsmouth-Townhall-FULL--Feb-9-2020   r   271r*   playlist_countr+   c           	          | j                  |      }| j                  | j                  | j                  t         d| |            |      S )Nzstack/)	_match_idplaylist_resultr   r   rk   )rx   r*   list_ids      r~   r   zRokfinStackIE._real_extract@  sQ    ..%##D$8$8=/y A7K%MNUW 	Wr   N)r   r   r   IE_NAMEIE_DESCr   r   r   r   r   r~   r   r   4  s3    GGFJd%
 FWr   r   c                   X    e Zd ZdZdZdZdddddd	d
gZdddddddZd Zd Z	d Z
d Zy)RokfinChannelIEzrokfin:channelzRokfin ChannelszXhttps?://(?:www\.)?rokfin\.com/(?!((feed/?)|(discover/?)|(channels/?))$)(?P<id>[^/]+)/?$z https://rokfin.com/TheConvoCouchd   z	12071-newzTheConvoCouch - Newz$md5:bb622b1bca100209b91cd685f7847f06)r   r   r/   )r*   playlist_mincountr+   poststopr   r   rA   r   )newr  videospodcastsstreamsstacksc                 $    | j                          y N)_validate_extractor_argsr   s    r~   _real_initializez RokfinChannelIE._real_initialize]  s    %%'r   c                     | j                  dd       }|It        |      dkD  s|d   | j                  vr)t        ddj	                  | j                         d      y y )Ntabr   r   z,Invalid extractor-arg "tab". Must be one of z, Tr   )_configuration_arglen_TABSr   r   )rx   requested_tabss     r~   r  z(RokfinChannelIE._validate_extractor_args`  sn    00=%3~+>+BnUVFW_c_i_iFi #OPTPYPYZ^ZdZdPeOf!grvww Gj%r   c              #     K   d }t        j                  d      D ]  }|dv rt         d| d| d| d}nt         d| d| d| }| j                  ||d	|d
z    t	        |d d             }| j                  |      E d {    t        |j                  d            xs d }|j                  d      }|s|r||kD  s y |dus y  y 7 Hw)Nr   )r  r  user/r   z?page=r   zpost/search/z&size=50&creator=z Downloading video metadata page r   r   )r   r   r   F)r   r   rk   r   r
   r   r   rl   )	rx   r#   channel_namer  r   r   data_urlrz   r   s	            r~   _entrieszRokfinChannelIE._entriese  s    ooa( 	F&&+_E,qVF8S[\+_LVF8K\]g\hi**,7
|LQ\^bdlDmCno + qH ++H555%hll<&@AITKll6*G;6K/ ELSXDX	 6s   A>C C	<C>CCc           
      V   | j                  |      }| j                  t         d| |      }|d   }| j                  ddg      d   }| j	                  | j                  ||| j                  |         | d| | d|j                          t        |j                  d	                  S )
Nr  r   r  r  rG   r   -z - r/   )
r  r   rk   r  r  r   r  r   r   rl   )rx   r*   r  channel_infor#   r  s         r~   r   zRokfinChannelIE._real_extractv  s    ~~c***m_E,+PR^_!$'
%%eeW%=a@##MM*lDJJsODl!C5!l^3syy{m#DkR^RbRbcpRqFrt 	tr   N)r   r   r   r  r  r   r   r  r  r  r   r   r   r   r~   r  r  F  sb    GGlJ1 *A
 F E(x
"tr   r  c                   ^    e Zd ZdZdZdZddddddZdd	d
d
ddgZdZdZ	d Z
d Zd ZddZy)RokfinSearchIEzrokfin:searchzRokfin Search
rkfnsearch))r   rawrg   )
content_idr'  rA   )r(  r   r   zrkfnsearch5:"zelenko"r   z	"zelenko")r   r   r   Nc                     | j                   j                  | j                         dd      \  | _        | _        | j                  s| j                          y y )NauthNNrG   )cacheloadie_key_db_url_db_access_key_get_db_access_credentialsr   s    r~   r  zRokfinSearchIE._real_initialize  sC    ,0JJOODKKM6[gO,h)d)||++- r   c              #     K   d }t        j                  d      D ]  }| j                  ||d|ddd| t        |d d             }t	        |dt
        	      }|j                  d
      xs g D ]]  }| j                  j                  t	        |d      d      \  }}t	        ||t
        	      }|sA|sD| j                  d| d|        _ |j                  d
      r y  y w)Nr   r	  )sizecurrent)r   pagezDownloading page z of ~%s)r   r   )metar6  total_pagesrD   results)content_typer'  r,  r`   r   )r*   )	r   r   _run_search_queryr
   r   r   rl   r   r   )	rx   r   r8  page_numbersearch_resultsresultvideo_id_keyry   rP   s	            r~   _search_resultszRokfinSearchIE._search_results  s     $??1- 	K!33eck5Z[(l;PTV_6`5ab 4 dN '~7VfqrK(,,Y7=2 ]+/;;??<Pg;hjv+w(j'KX
//0CJ<qQYPZ.[/\\	]
 "%%i0	s   B,C$/C$2-C$ C$c                    t        j                  |      j                         }t        d      D ][  } | j                  | j
                  |f||dk(  d| j                  id|}|r|c S | j                  d       | j                  |       ] y )Nr   r   r   )r   rJ   r   zUpdating access credentials)	jsondumpsencoderanger   r0  r1  write_debugr2  )rx   rP   r   kwargsattemptr=  s         r~   r;  z RokfinSearchIE._run_search_query  s    zz$&&(Qx 	6G0T00hJ-1'Q,($*=*=>JBHJN %%:;++H5	6r   c           
      D   d d d}| j                  d|dd      }t        j                  d|      D ]  }| j                  d| |dd	
      }|j                  t        j                  ddj	                  |j                                d|xs d             t        |j                               st        |d    d      | _	        d|d    | _
        | j                  j                  | j                         d| j                  | j                  f        y  t        d      )N)
SEARCH_KEYENDPOINT_BASEzhttps://rokfin.com/discoverr   zDownloading home page)r   r   z/<script\b[^>]*\ssrc\s*=\s*"(/static/js/[^">]+)"zhttps://rokfin.comzDownloading JavaScript fileFr   zREACT_APP_(|z)\s*:\s*"([^"]+)"r   rK  z,/api/as/v1/engines/rokfin-search/search.jsonzBearer rJ  r+  z$Unable to extract access credentials)r   r   findallupdater   keysallvaluesr   r0  r1  r-  storer/  r   )rx   rP   	auth_datanotfound_err_pagejs_file_path
js_contents         r~   r2  z)RokfinSearchIE._get_db_access_credentials  s1   #'$?	 22)8SOf 3 hJJ'Y[lm 	L//$\N3XDain 0 pJRZZsxx	(89::KLjN^\^` ay'')*&)O*D)EEq'rsDL$+Il,C+D"EDJJT[[]FT\\4CVCV4WX	 CDDr   r  )r   r   r   r  r  _SEARCH_KEYr   r   r0  r1  r  r@  r;  r2  r   r   r~   r%  r%    sg    GGK((381F ' 
 F GN.
 	6Er   r%  )rr   rq   r   rB  r   urllib.parser   commonr   r   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   rk   r   r   r   r  r%  r   r   r~   <module>r[     s       	  6    KC[} C[Lo= o(W( W$8t* 8tvFE( FEr   