Allow use of kate mobile's tokens for accessing all methods
This commit is contained in:
parent
815bd4b49e
commit
bb500779d9
@ -504,6 +504,7 @@ class videoBuffer(feedBuffer):
|
|||||||
selected = 0
|
selected = 0
|
||||||
output.speak(_(u"Opening video in webbrowser..."))
|
output.speak(_(u"Opening video in webbrowser..."))
|
||||||
webbrowser.open_new_tab(self.session.db[self.name]["items"][selected]["player"])
|
webbrowser.open_new_tab(self.session.db[self.name]["items"][selected]["player"])
|
||||||
|
# print self.session.db[self.name]["items"][selected]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def open_post(self, *args, **kwargs):
|
def open_post(self, *args, **kwargs):
|
||||||
|
@ -231,6 +231,7 @@ class Controller(object):
|
|||||||
call_threaded(utils.download_file, url, filename, self.window)
|
call_threaded(utils.download_file, url, filename, self.window)
|
||||||
|
|
||||||
def play_audio(self, audio_object):
|
def play_audio(self, audio_object):
|
||||||
|
print audio_object
|
||||||
call_threaded(player.player.play, audio_object)
|
call_threaded(player.player.play, audio_object)
|
||||||
|
|
||||||
def play_audios(self, audios):
|
def play_audios(self, audios):
|
||||||
@ -477,8 +478,12 @@ class Controller(object):
|
|||||||
def get_audio_albums(self, user_id=None):
|
def get_audio_albums(self, user_id=None):
|
||||||
try:
|
try:
|
||||||
log.debug("Create audio albums...")
|
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)
|
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:
|
if ex.code == 6:
|
||||||
log.exception("Something went wrong when getting albums. Waiting a second to retry")
|
log.exception("Something went wrong when getting albums. Waiting a second to retry")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
user = string(default="")
|
user = string(default="")
|
||||||
password = string(default="")
|
password = string(default="")
|
||||||
token = string(default="")
|
token = string(default="")
|
||||||
|
use_alternative_tokens = boolean(default=False)
|
||||||
|
|
||||||
[general]
|
[general]
|
||||||
reverse_timelines = boolean(default=False)
|
reverse_timelines = boolean(default=False)
|
||||||
|
@ -94,8 +94,8 @@ class vkSession(object):
|
|||||||
def login(self):
|
def login(self):
|
||||||
try:
|
try:
|
||||||
config_filename = os.path.join(paths.config_path(), self.session_id, "vkconfig.json")
|
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.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.client._session.access_token
|
self.settings["vk"]["token"] = self.vk.session_object.token["access_token"]
|
||||||
self.settings.write()
|
self.settings.write()
|
||||||
self.logged = True
|
self.logged = True
|
||||||
self.get_my_data()
|
self.get_my_data()
|
||||||
@ -130,13 +130,15 @@ class vkSession(object):
|
|||||||
|
|
||||||
def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs):
|
def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs):
|
||||||
data = None
|
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
|
c = self.vk.client_audio
|
||||||
else:
|
else:
|
||||||
c = self.vk.client
|
c = self.vk.client
|
||||||
if kwargs.has_key("parent_endpoint"):
|
if kwargs.has_key("parent_endpoint"):
|
||||||
p = kwargs["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
|
c = self.vk.client_audio
|
||||||
kwargs.pop("parent_endpoint")
|
kwargs.pop("parent_endpoint")
|
||||||
try:
|
try:
|
||||||
|
@ -12,13 +12,22 @@ class vkObject(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.api_key = keys.keyring.get_api_key()
|
self.api_key = keys.keyring.get_api_key()
|
||||||
|
|
||||||
def login(self, user, password, filename):
|
def login(self, user, password, token, alt_token, filename):
|
||||||
log.debug("Logging in vk using user/password authentication")
|
if alt_token == False:
|
||||||
# token = core.requestAuth(user, password)
|
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 = 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.session_object.auth(token_only=True)
|
||||||
self.client = self.session_object.get_api()
|
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...")
|
log.debug("Getting tokens for 24 hours...")
|
||||||
# info = self.client.account.getProfileInfo()
|
# info = self.client.account.getProfileInfo()
|
||||||
# Add session data to the application statistics.
|
# Add session data to the application statistics.
|
||||||
|
Loading…
Reference in New Issue
Block a user