72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
# -*- 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 <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))
|
|
|
|
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, 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
|