From bb500779d93beec6d63bfbaea515975dee8296bd Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 15 Dec 2018 21:09:17 -0600 Subject: [PATCH] Allow use of kate mobile's tokens for accessing all methods --- src/controller/buffers.py | 1 + src/controller/mainController.py | 9 +++++++-- src/session.defaults | 1 + src/sessionmanager/session.py | 10 ++++++---- src/sessionmanager/vkSessionHandler.py | 21 +++++++++++++++------ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 8450089..8f25784 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -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): diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 36dedf5..2fc9db9 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -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...") - albums = self.session.vk.client_audio.get_albums(owner_id=user_id) - except VkApiError as ex: + if self.session.settings["vk"]["use_alternative_tokens"]: + albums = self.session.vk.client_audio.get_albums(owner_id=user_id) + 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) diff --git a/src/session.defaults b/src/session.defaults index 5a14573..3bc78a2 100644 --- a/src/session.defaults +++ b/src/session.defaults @@ -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) diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index 6d55552..9cb08f5 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -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: diff --git a/src/sessionmanager/vkSessionHandler.py b/src/sessionmanager/vkSessionHandler.py index 2331822..bb91b82 100644 --- a/src/sessionmanager/vkSessionHandler.py +++ b/src/sessionmanager/vkSessionHandler.py @@ -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) - 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) + 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.