def load_session(self): settings = plexdesktop.settings.Settings() try: # with open('session.pickle', 'rb') as f: # self.session = pickle.load(f) self.session = pickle.loads(base64.b64decode(settings.value('session').encode())) self.user = self.session.get_user_by_id(settings.value('user')) self.current_server = self.session.get_server_by_id(settings.value('last_server')) self.active.emit(True) except Exception as e: logger.error('SessionManager: load_session: ' + str(e)) self.active.emit(False)
def create_session(self, user, passwd): self.working.emit() settings = plexdesktop.settings.Settings() try: logger.debug('SessionManager: creating session') self.session = plexdevices.create_session(user=user, password=passwd) except plexdevices.PlexTVError as e: logger.error('SessionManager: create_session: ' + str(e)) self.done.emit(False, str(e)) else: self.refresh_devices() self.refresh_users() for user in self.session.users: if user.title == self.session.user: settings.setValue('user', user.id) break self.save_session() self.user = self.session.get_user_by_id(settings.value('user')) self.current_server = self.session.get_server_by_id(settings.value('last_server')) if not self.current_server and self.session.servers: self.current_server = self.session.servers[0] self.active.emit(True) self.done.emit(True, '')
def server(self): if not self.current_server: settings = plexdesktop.settings.Settings() return self.session.get_server_by_id(settings.value('last_server')) else: return self.current_server