# -*- coding: utf-8 -*- # This file is part of Tautulli. # # Tautulli is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Tautulli is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Tautulli. If not, see . import pprint import uuid from jellyfin_apiclient_python import JellyfinClient import jellypy from jellypy.common import PRODUCT, RELEASE class Jellyfin(object): def __init__(self, url, token=None): if not jellypy.CONFIG.JELLYFIN_CLIENT_UUID: jellypy.CONFIG.JELLYFIN_CLIENT_UUID = uuid.uuid4() jellypy.CONFIG.write() self.jf = JellyfinClient() self.jf.config.data["app.default"] = True self.jf.config.app( PRODUCT, RELEASE, PRODUCT, jellypy.CONFIG.JELLYFIN_CLIENT_UUID ) self.jf.config.data["http.user_agent"] = PRODUCT self.jf.config.data["auth.ssl"] = jellypy.CONFIG.JELLYFIN_SSL self.url = url self.id = None self.token = token if self.token: self.login() def get_library(self, section_id): return self.jf.library.sectionByID(str(section_id)) def get_library_items(self, section_id): return self.get_library(str(section_id)).all() def get_item(self, rating_key): return self.jf.fetchItem(rating_key) def login(self, user=None, password=None) -> bool: if user and password and self.url: self.jf.auth.connect_to_address(self.url) result = self.jf.auth.login(self.url, user, password) if "AccessToken" in result: credentials = self.jf.auth.credentials.get_credentials() pprint.pprint(credentials) self.id = credentials["Servers"][0]["Id"] # jellypy.CONFIG.JELLYFIN_TOKEN = # # self._connect_client(server) # self.credentials.append(server) # self.save_credentials() return True if self.token and self.url: # TODO: Add token auth pass return False