Allow use of kate mobile's tokens for accessing all methods

This commit is contained in:
Manuel Cortez 2018-12-15 21:09:17 -06:00
parent 815bd4b49e
commit bb500779d9
5 changed files with 30 additions and 12 deletions

View File

@ -504,6 +504,7 @@ class videoBuffer(feedBuffer):
selected = 0
output.speak(_(u"Opening video in webbrowser..."))
webbrowser.open_new_tab(self.session.db[self.name]["items"][selected]["player"])
# print self.session.db[self.name]["items"][selected]
return True
def open_post(self, *args, **kwargs):

View File

@ -231,6 +231,7 @@ class Controller(object):
call_threaded(utils.download_file, url, filename, self.window)
def play_audio(self, audio_object):
print audio_object
call_threaded(player.player.play, audio_object)
def play_audios(self, audios):
@ -477,8 +478,12 @@ class Controller(object):
def get_audio_albums(self, user_id=None):
try:
log.debug("Create audio albums...")
if self.session.settings["vk"]["use_alternative_tokens"]:
albums = self.session.vk.client_audio.get_albums(owner_id=user_id)
except VkApiError as ex:
else:
albums = self.session.vk.client.audio.getPlaylists(owner_id=user_id)
albums = albums["items"]
except SyntaxError:#VkApiError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting albums. Waiting a second to retry")
time.sleep(2)

View File

@ -2,6 +2,7 @@
user = string(default="")
password = string(default="")
token = string(default="")
use_alternative_tokens = boolean(default=False)
[general]
reverse_timelines = boolean(default=False)

View File

@ -94,8 +94,8 @@ class vkSession(object):
def login(self):
try:
config_filename = os.path.join(paths.config_path(), self.session_id, "vkconfig.json")
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"], filename=config_filename)
self.settings["vk"]["token"] = self.vk.client._session.access_token
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"], token=self.settings["vk"]["token"], alt_token=self.settings["vk"]["use_alternative_tokens"], filename=config_filename)
self.settings["vk"]["token"] = self.vk.session_object.token["access_token"]
self.settings.write()
self.logged = True
self.get_my_data()
@ -130,13 +130,15 @@ class vkSession(object):
def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs):
data = None
if "audio" in endpoint:
if "audio" in endpoint and self.settings["vk"]["use_alternative_tokens"]:
log.info("Using alternative audio methods.")
c = self.vk.client_audio
else:
c = self.vk.client
if kwargs.has_key("parent_endpoint"):
p = kwargs["parent_endpoint"]
if "audio" in p:
if "audio" in p and self.settings["vk"]["use_alternative_tokens"]:
log.info("Using alternative audio methods.")
c = self.vk.client_audio
kwargs.pop("parent_endpoint")
try:

View File

@ -12,13 +12,22 @@ class vkObject(object):
def __init__(self):
self.api_key = keys.keyring.get_api_key()
def login(self, user, password, filename):
log.debug("Logging in vk using user/password authentication")
# token = core.requestAuth(user, password)
def login(self, user, password, token, alt_token, filename):
if alt_token == False:
log.info("Using kate's token...")
if token == "" or token == None:
log.info("Token is not valid. Generating one...")
token = core.requestAuth(user, password)
token = token[0]
receipt = core.getReceipt(token)
token = core.validateToken(token, receipt)
log.info("Token validated...")
self.session_object = vk_api.VkApi(app_id=self.api_key, login=user, password=password, token=token, scope="offline, wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats", config_filename=filename)
else:
self.session_object = vk_api.VkApi(app_id=self.api_key, login=user, password=password, scope="offline, wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats", config_filename=filename)
self.session_object.auth(token_only=True)
self.client = self.session_object.get_api()
# self.client = API(s, v=self.api_version)
# print self.client.audio.get()
log.debug("Getting tokens for 24 hours...")
# info = self.client.account.getProfileInfo()
# Add session data to the application statistics.