remodel config to match jellyfin purpose

This commit is contained in:
2021-02-06 16:36:15 +01:00
parent 110baa67d5
commit 6e1067e43e
11 changed files with 390 additions and 471 deletions

View File

@@ -14,13 +14,32 @@
#
# You should have received a copy of the GNU General Public License
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
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"] = not jellypy.CONFIG.JELLYFIN_SSL
self.url = url
if token:
self.login(token=token)
def get_library(self, section_id):
return self.jf.library.sectionByID(str(section_id))
@@ -31,5 +50,22 @@ class Jellyfin(object):
def get_item(self, rating_key):
return self.jf.fetchItem(rating_key)
def login(self, user, password):
pass
def login(self, user=None, password=None, token=None) -> bool:
if user and password:
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)
server = credentials["Servers"][0]
server["uuid"] = server["Id"]
server["username"] = user
# jellypy.CONFIG.JELLYFIN_TOKEN =
#
# self._connect_client(server)
# self.credentials.append(server)
# self.save_credentials()
return True
return False