@ -19,11 +19,11 @@ except ImportError:
ADDON = xbmcaddon . Addon ( )
class r umbleUser:
class R umbleUser:
""" main rumble user class """
base U rl = ' https://rumble.com '
base _u rl = ' https://rumble.com '
username = ' '
password = ' '
session = ' '
@ -33,9 +33,9 @@ class rumbleUser:
""" Construct to get the saved details """
self . get LoginD etails( )
self . get _login_d etails( )
def get LoginD etails( self ) :
def get _login_d etails( self ) :
""" get the saved login details """
@ -47,13 +47,13 @@ class rumbleUser:
if self . expiry :
self . expiry = float ( self . expiry )
def has LoginD etails( self ) :
def has _login_d etails( self ) :
""" if there is login details """
return ( self . username and self . password )
def set SessionD etails( self ) :
def set _session_d etails( self ) :
"""
sets the session details
@ -62,39 +62,39 @@ class rumbleUser:
ADDON . setSetting ( ' session ' , self . session )
ADDON . setSetting ( ' expiry ' , str ( self . expiry ) )
self . set SessionC ookie( )
self . set _session_c ookie( )
def reset SessionD etails( self ) :
def reset _session_d etails( self ) :
""" resets the session details to force a login """
self . session = ' '
self . expiry = ' '
self . set SessionD etails( )
self . set _session_d etails( )
def has S ession( self , login = True ) :
def has _s ession( self , login = True ) :
""" resets the session details to force a login """
has_session = self . session and self . expiry and self . expiry > time . time ( )
if not has_session and login and self . has LoginD etails( ) :
if not has_session and login and self . has _login_d etails( ) :
self . login ( )
return self . has S ession( False )
return self . has _s ession( False )
return has_session
def get S alts( self ) :
def get _s alts( self ) :
"""
method to get the salts from rumble
these are used to generate the login hashes
"""
if self . has LoginD etails( ) :
if self . has _login_d etails( ) :
# gets salts
data = request_get (
self . base U rl + ' /service.php?name=user.get_salts ' ,
self . base _u rl + ' /service.php?name=user.get_salts ' ,
{ ' username ' : self . username } ,
[ ( ' Referer ' , self . base U rl ) , ( ' Content-type ' , ' application/x-www-form-urlencoded ' ) ]
[ ( ' Referer ' , self . base _u rl ) , ( ' Content-type ' , ' application/x-www-form-urlencoded ' ) ]
)
if data :
salts = json . loads ( data ) [ ' data ' ] [ ' salts ' ]
@ -106,16 +106,19 @@ class rumbleUser:
""" method to generate the hashes and login """
salts = self . get S alts( )
salts = self . get _s alts( )
if salts :
login_hash = MD5Ex ( )
hashes = login_hash . hash ( login_hash . hashStretch ( self . password , salts [ 0 ] , 128 ) + salts [ 1 ] ) + ' , ' + login_hash . hashStretch ( self . password , salts [ 2 ] , 128 ) + ' , ' + salts [ 1 ]
hashes = login_hash . hash (
login_hash . hashStretch ( self . password , salts [ 0 ] , 128 ) + salts [ 1 ] ) + ' , ' \
+ login_hash . hashStretch ( self . password , salts [ 2 ] , 128
) + ' , ' + salts [ 1 ]
# login
data = request_get (
self . base U rl + ' /service.php?name=user.login ' ,
self . base _u rl + ' /service.php?name=user.login ' ,
{ ' username ' : self . username , ' password_hashes ' : hashes } ,
[ ( ' Referer ' , self . base U rl ) , ( ' Content-type ' , ' application/x-www-form-urlencoded ' ) ]
[ ( ' Referer ' , self . base _u rl ) , ( ' Content-type ' , ' application/x-www-form-urlencoded ' ) ]
)
if data :
@ -124,13 +127,15 @@ class rumbleUser:
self . session = session
# Expiry is 30 Days
self . expiry = math . floor ( time . time ( ) ) + 2592000
self . set SessionD etails( )
self . set _session_d etails( )
return session
return False
def setSessionCookie ( self ) :
def set_session_cookie ( self ) :
""" Sets the cookie to be used in the session """
if self . session :
# get stored cookie string
@ -138,14 +143,14 @@ class rumbleUser:
# split cookies into dictionary
if cookies :
cookie D ict = json . loads ( cookies )
cookie _d ict = json . loads ( cookies )
else :
cookie D ict = { }
cookie _d ict = { }
cookie D ict[ ' u_s ' ] = self . session
cookie _d ict[ ' u_s ' ] = self . session
# store cookies
ADDON . setSetting ( ' cookies ' , json . dumps ( cookie D ict) )
ADDON . setSetting ( ' cookies ' , json . dumps ( cookie _d ict) )
else :
ADDON . setSetting ( ' cookies ' , ' ' )
@ -153,7 +158,7 @@ class rumbleUser:
""" method to subscribe and unsubscribe to a channel or user """
if self . has S ession( ) :
if self . has _s ession( ) :
post_content = {
' slug ' : name ,
@ -162,11 +167,16 @@ class rumbleUser:
}
headers = {
' Referer ' : self . base U rl + name ,
' Referer ' : self . base _u rl + name ,
' Content-type ' : ' application/x-www-form-urlencoded '
}
data = request_get ( self . baseUrl + ' /service.php?api=2&name=user.subscribe ' , post_content , headers )
data = request_get (
self . base_url + ' /service.php?api=2&name=user.subscribe ' ,
post_content ,
headers
)
return data
return False