mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-01-27 18:36:11 +00:00
Make mypy happier
This commit is contained in:
parent
a190826ad1
commit
49f6546aca
19 changed files with 76 additions and 52 deletions
|
@ -154,7 +154,7 @@ class Connect(object):
|
|||
def select_servers(self, state=None):
|
||||
|
||||
state = state or self.connect_manager.connect({'enableAutoLogin': False})
|
||||
user = {}
|
||||
user = {} # TODO: Fixme: content of this dict is used below, but can never contain anything
|
||||
|
||||
dialog = ServerConnect("script-jellyfin-connect-server.xml", *XML_PATH)
|
||||
dialog.set_args(
|
||||
|
|
|
@ -8,6 +8,7 @@ import os
|
|||
import sqlite3
|
||||
import sys
|
||||
import re
|
||||
from typing import Any, Dict
|
||||
|
||||
from kodi_six import xbmc, xbmcvfs
|
||||
from six import text_type
|
||||
|
@ -36,7 +37,7 @@ class Database(object):
|
|||
'''
|
||||
timeout = 120
|
||||
discovered = False
|
||||
discovered_file = None
|
||||
discovered_file: str = None
|
||||
|
||||
def __init__(self, db_file=None, commit_close=True):
|
||||
|
||||
|
@ -318,7 +319,7 @@ def reset_artwork():
|
|||
LOG.info("[ reset artwork ]")
|
||||
|
||||
|
||||
def get_sync():
|
||||
def get_sync() -> dict:
|
||||
if (3, 0) <= sys.version_info < (3, 6):
|
||||
LOG.error("Python versions 3.0-3.5 are NOT supported.")
|
||||
|
||||
|
@ -342,7 +343,7 @@ def get_sync():
|
|||
return sync
|
||||
|
||||
|
||||
def save_sync(sync):
|
||||
def save_sync(sync: Dict[str, Any]):
|
||||
|
||||
if not xbmcvfs.exists(ADDON_DATA):
|
||||
xbmcvfs.mkdirs(ADDON_DATA)
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
##################################################################################################
|
||||
|
||||
import os
|
||||
from typing import List
|
||||
from typing import List, cast
|
||||
|
||||
from kodi_six import xbmcgui, xbmcaddon
|
||||
from six import ensure_text
|
||||
|
@ -52,7 +52,7 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
|
|||
self.getControl(USER_IMAGE).setImage(window('JellyfinUserImage'))
|
||||
|
||||
LOG.info("options: %s", self._options)
|
||||
self.list_ = self.getControl(LIST)
|
||||
self.list_ = cast(xbmcgui.ControlList, self.getControl(LIST))
|
||||
|
||||
for option in self._options:
|
||||
self.list_.addItem(self._add_listitem(option))
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import division, absolute_import, print_function, unicode_literals
|
||||
|
||||
from typing import Optional
|
||||
|
||||
##################################################################################################
|
||||
|
||||
from kodi_six import xbmc, xbmcgui
|
||||
|
@ -22,7 +24,7 @@ START_BEGINNING = 3011
|
|||
class ResumeDialog(xbmcgui.WindowXMLDialog):
|
||||
|
||||
_resume_point = None
|
||||
selected_option = None
|
||||
selected_option: Optional[int] = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
|
||||
|
|
|
@ -885,7 +885,7 @@ def backup():
|
|||
if xbmcvfs.exists(backup + '/'):
|
||||
if not dialog("yesno", "{jellyfin}", translate(33090)):
|
||||
|
||||
return backup()
|
||||
return backup
|
||||
|
||||
delete_folder(backup)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
# Workaround for threads using datetime: _striptime is locked
|
||||
import _strptime # noqa:F401
|
||||
|
@ -37,7 +38,7 @@ class Service(xbmc.Monitor):
|
|||
monitor = None
|
||||
play_event = None
|
||||
warn = True
|
||||
settings = {'last_progress': datetime.today(), 'last_progress_report': datetime.today()}
|
||||
settings: Dict[str, Any] = {'last_progress': datetime.today(), 'last_progress_report': datetime.today()}
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
@ -264,17 +265,17 @@ class Service(xbmc.Monitor):
|
|||
window('jellyfin_should_stop.bool', True)
|
||||
self.running = False
|
||||
|
||||
elif method in ('SyncLibrarySelection', 'RepairLibrarySelection', 'AddLibrarySelection', 'RemoveLibrarySelection'):
|
||||
elif self.library_thread is not None and method in ('SyncLibrarySelection', 'RepairLibrarySelection', 'AddLibrarySelection', 'RemoveLibrarySelection'):
|
||||
self.library_thread.select_libraries(method)
|
||||
|
||||
elif method == 'SyncLibrary':
|
||||
elif self.library_thread is not None and method == 'SyncLibrary':
|
||||
if not data.get('Id'):
|
||||
return
|
||||
|
||||
self.library_thread.add_library(data['Id'], data.get('Update', False))
|
||||
xbmc.executebuiltin("Container.Refresh")
|
||||
|
||||
elif method == 'RepairLibrary':
|
||||
elif self.library_thread is not None and method == 'RepairLibrary':
|
||||
if not data.get('Id'):
|
||||
return
|
||||
|
||||
|
@ -288,7 +289,7 @@ class Service(xbmc.Monitor):
|
|||
self.library_thread.add_library(data['Id'])
|
||||
xbmc.executebuiltin("Container.Refresh")
|
||||
|
||||
elif method == 'RemoveLibrary':
|
||||
elif self.library_thread is not None and method == 'RemoveLibrary':
|
||||
libraries = data['Id'].split(',')
|
||||
|
||||
for lib in libraries:
|
||||
|
@ -309,10 +310,11 @@ class Service(xbmc.Monitor):
|
|||
self.library_thread = None
|
||||
|
||||
Jellyfin.close_all()
|
||||
self.monitor.server = []
|
||||
self.monitor.sleep = True
|
||||
if self.monitor is not None:
|
||||
self.monitor.server = []
|
||||
self.monitor.sleep = True
|
||||
|
||||
elif method == 'System.OnWake':
|
||||
elif self.monitor is not None and method == 'System.OnWake':
|
||||
|
||||
if not self.monitor.sleep:
|
||||
LOG.warning("System.OnSleep was never called, skip System.OnWake")
|
||||
|
@ -365,7 +367,7 @@ class Service(xbmc.Monitor):
|
|||
self.settings['enable_context_transcode'] = settings('enableContextTranscode.bool')
|
||||
LOG.info("New context transcode setting: %s", self.settings['enable_context_transcode'])
|
||||
|
||||
if settings('useDirectPaths') != self.settings['mode'] and self.library_thread.started:
|
||||
if self.library_thread is not None and settings('useDirectPaths') != self.settings['mode'] and self.library_thread.started:
|
||||
|
||||
self.settings['mode'] = settings('useDirectPaths')
|
||||
LOG.info("New playback mode setting: %s", self.settings['mode'])
|
||||
|
|
|
@ -31,7 +31,7 @@ class FullSync(object):
|
|||
'''
|
||||
# Borg - multiple instances, shared state
|
||||
_shared_state: Dict[str, Any] = {}
|
||||
sync = None
|
||||
sync = get_sync()
|
||||
running = False
|
||||
screensaver = None
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import division, absolute_import, print_function, unicode_literals
|
||||
|
||||
from typing import Any, Dict, List
|
||||
|
||||
##################################################################################################
|
||||
|
||||
from . import settings, LazyLogger
|
||||
|
@ -42,7 +44,7 @@ class API(object):
|
|||
return self.item['Name']
|
||||
|
||||
def get_actors(self):
|
||||
cast = []
|
||||
cast: List[Dict[str, Any]] = []
|
||||
|
||||
if 'People' in self.item:
|
||||
self.get_people_artwork(self.item['People'])
|
||||
|
|
|
@ -6,6 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
import os
|
||||
import logging
|
||||
import traceback
|
||||
from typing import Dict, List
|
||||
|
||||
from six import ensure_text
|
||||
from kodi_six import xbmc, xbmcaddon
|
||||
|
@ -36,7 +37,7 @@ class LogHandler(logging.StreamHandler):
|
|||
logging.StreamHandler.__init__(self)
|
||||
self.setFormatter(MyFormatter())
|
||||
|
||||
self.sensitive = {'Token': [], 'Server': []}
|
||||
self.sensitive: Dict[str, List[str]] = {'Token': [], 'Server': []}
|
||||
|
||||
for server in database.get_credentials()['Servers']:
|
||||
|
||||
|
|
|
@ -153,7 +153,8 @@ def event(method, data=None, sender=None, hexlify=False):
|
|||
xbmc.executebuiltin('NotifyAll(%s, %s, %s)' % (sender, method, data))
|
||||
|
||||
|
||||
def dialog(dialog_type, *args, **kwargs):
|
||||
def dialog(dialog_type: str, *args: str, **kwargs):
|
||||
arg_list = list(args)
|
||||
|
||||
d = xbmcgui.Dialog()
|
||||
|
||||
|
@ -165,9 +166,8 @@ def dialog(dialog_type, *args, **kwargs):
|
|||
if "heading" in kwargs:
|
||||
kwargs['heading'] = kwargs['heading'].replace("{jellyfin}", translate('addon_name'))
|
||||
|
||||
if args:
|
||||
args = list(args)
|
||||
args[0] = args[0].replace("{jellyfin}", translate('addon_name'))
|
||||
if arg_list:
|
||||
arg_list[0] = arg_list[0].replace("{jellyfin}", translate('addon_name'))
|
||||
|
||||
types = {
|
||||
'yesno': d.yesno,
|
||||
|
@ -178,7 +178,7 @@ def dialog(dialog_type, *args, **kwargs):
|
|||
'numeric': d.numeric,
|
||||
'multi': d.multiselect
|
||||
}
|
||||
return types[dialog_type](*args, **kwargs)
|
||||
return types[dialog_type](*arg_list, **kwargs)
|
||||
|
||||
|
||||
def should_stop():
|
||||
|
|
|
@ -27,7 +27,7 @@ def tvtunes_nfo(path, urls):
|
|||
except Exception:
|
||||
xml = etree.Element('tvtunes')
|
||||
|
||||
for elem in xml.getiterator('tvtunes'):
|
||||
for elem in xml.iter('tvtunes'):
|
||||
for file in list(elem):
|
||||
elem.remove(file)
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ def clean_none_dict_values(obj):
|
|||
if mutable:
|
||||
# Remove keys with None value
|
||||
for key in remove:
|
||||
item.pop(key)
|
||||
item.pop(key) # typing: ignore [attr-defined]
|
||||
|
||||
elif isinstance(item, collections_abc.Iterable):
|
||||
for value in item:
|
||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
|
||||
import threading
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from six.moves import queue as Queue
|
||||
|
||||
|
@ -47,18 +48,18 @@ class Library(threading.Thread):
|
|||
self.monitor = monitor
|
||||
self.player = monitor.monitor.player
|
||||
self.server = Jellyfin().get_client()
|
||||
self.updated_queue = Queue.Queue()
|
||||
self.userdata_queue = Queue.Queue()
|
||||
self.removed_queue = Queue.Queue()
|
||||
self.updated_queue: Queue.Queue[str] = Queue.Queue()
|
||||
self.userdata_queue: Queue.Queue[str] = Queue.Queue()
|
||||
self.removed_queue: Queue.Queue[str] = Queue.Queue()
|
||||
self.updated_output = self.__new_queues__()
|
||||
self.userdata_output = self.__new_queues__()
|
||||
self.removed_output = self.__new_queues__()
|
||||
self.notify_output = Queue.Queue()
|
||||
self.notify_output: Queue.Queue[Tuple[str, str]] = Queue.Queue()
|
||||
|
||||
self.jellyfin_threads = []
|
||||
self.download_threads = []
|
||||
self.notify_threads = []
|
||||
self.writer_threads = {'updated': [], 'userdata': [], 'removed': []}
|
||||
self.writer_threads: Dict[str, List[BaseWorker]] = {'updated': [], 'userdata': [], 'removed': []}
|
||||
self.database_lock = threading.Lock()
|
||||
self.music_database_lock = threading.Lock()
|
||||
|
||||
|
@ -222,10 +223,10 @@ class Library(threading.Thread):
|
|||
|
||||
''' Get items from jellyfin and place them in the appropriate queues.
|
||||
'''
|
||||
for queue in ((self.updated_queue, self.updated_output), (self.userdata_queue, self.userdata_output)):
|
||||
if queue[0].qsize() and len(self.download_threads) < DTHREADS:
|
||||
for input_queue, output_queue in ((self.updated_queue, self.updated_output), (self.userdata_queue, self.userdata_output)):
|
||||
if input_queue.qsize() and len(self.download_threads) < DTHREADS:
|
||||
|
||||
new_thread = GetItemWorker(self.server, queue[0], queue[1])
|
||||
new_thread = GetItemWorker(self.server, input_queue, output_queue)
|
||||
new_thread.start()
|
||||
LOG.info("-->[ q:download/%s ]", id(new_thread))
|
||||
self.download_threads.append(new_thread)
|
||||
|
@ -591,7 +592,11 @@ class Library(threading.Thread):
|
|||
LOG.info("---[ removed:%s ]", len(data))
|
||||
|
||||
|
||||
class UpdateWorker(threading.Thread):
|
||||
class BaseWorker(threading.Thread):
|
||||
is_done: bool
|
||||
|
||||
|
||||
class UpdateWorker(BaseWorker):
|
||||
|
||||
is_done = False
|
||||
|
||||
|
@ -667,7 +672,7 @@ class UpdateWorker(threading.Thread):
|
|||
self.is_done = True
|
||||
|
||||
|
||||
class UserDataWorker(threading.Thread):
|
||||
class UserDataWorker(BaseWorker):
|
||||
|
||||
is_done = False
|
||||
|
||||
|
@ -730,7 +735,7 @@ class UserDataWorker(threading.Thread):
|
|||
self.is_done = True
|
||||
|
||||
|
||||
class SortWorker(threading.Thread):
|
||||
class SortWorker(BaseWorker):
|
||||
|
||||
is_done = False
|
||||
|
||||
|
@ -777,7 +782,7 @@ class SortWorker(threading.Thread):
|
|||
self.is_done = True
|
||||
|
||||
|
||||
class RemovedWorker(threading.Thread):
|
||||
class RemovedWorker(BaseWorker):
|
||||
|
||||
is_done = False
|
||||
|
||||
|
@ -838,7 +843,7 @@ class RemovedWorker(threading.Thread):
|
|||
self.is_done = True
|
||||
|
||||
|
||||
class NotifyWorker(threading.Thread):
|
||||
class NotifyWorker(BaseWorker):
|
||||
|
||||
is_done = False
|
||||
|
||||
|
|
|
@ -117,11 +117,11 @@ class Monitor(xbmc.Monitor):
|
|||
LOG.exception(error)
|
||||
server = Jellyfin()
|
||||
|
||||
server = server.get_client()
|
||||
server_client = server.get_client()
|
||||
|
||||
if method == 'Play':
|
||||
|
||||
items = server.jellyfin.get_items(data['ItemIds'])
|
||||
items = server_client.jellyfin.get_items(data['ItemIds'])
|
||||
|
||||
PlaylistWorker(data.get('ServerId'), items, data['PlayCommand'] == 'PlayNow',
|
||||
data.get('StartPositionTicks', 0), data.get('AudioStreamIndex'),
|
||||
|
@ -130,7 +130,7 @@ class Monitor(xbmc.Monitor):
|
|||
# TODO no clue if this is called by anything
|
||||
elif method == 'PlayPlaylist':
|
||||
|
||||
server.jellyfin.post_session(server.config.data['app.session'], "Playing", {
|
||||
server_client.jellyfin.post_session(server_client.config.data['app.session'], "Playing", {
|
||||
'PlayCommand': "PlayNow",
|
||||
'ItemIds': data['Id'],
|
||||
'StartPositionTicks': 0
|
||||
|
@ -149,14 +149,14 @@ class Monitor(xbmc.Monitor):
|
|||
self.server_instance(data['ServerId'])
|
||||
|
||||
elif method == 'AddUser':
|
||||
server.jellyfin.session_add_user(server.config.data['app.session'], data['Id'], data['Add'])
|
||||
self.additional_users(server)
|
||||
server_client.jellyfin.session_add_user(server_client.config.data['app.session'], data['Id'], data['Add'])
|
||||
self.additional_users(server_client)
|
||||
|
||||
elif method == 'Player.OnPlay':
|
||||
on_play(data, server)
|
||||
on_play(data, server_client)
|
||||
|
||||
elif method == 'VideoLibrary.OnUpdate':
|
||||
on_update(data, server)
|
||||
on_update(data, server_client)
|
||||
|
||||
def server_instance(self, server_id=None):
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import division, absolute_import, print_function, unicode_literals
|
||||
|
||||
from abc import ABCMeta
|
||||
from sqlite3 import Cursor
|
||||
|
||||
##################################################################################################
|
||||
|
||||
from ...helper import values, LazyLogger
|
||||
|
@ -15,7 +18,8 @@ LOG = LazyLogger(__name__)
|
|||
##################################################################################################
|
||||
|
||||
|
||||
class Kodi(object):
|
||||
class Kodi(metaclass=ABCMeta):
|
||||
cursor: Cursor
|
||||
|
||||
def __init__(self):
|
||||
self.artwork = artwork.Artwork(self.cursor)
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
##################################################################################################
|
||||
|
||||
import datetime
|
||||
from typing import List
|
||||
|
||||
from ..database import jellyfin_db, queries as QUEM
|
||||
from ..helper import api, stop, validate, jellyfin_item, values, Local, LazyLogger
|
||||
|
@ -551,7 +552,7 @@ class Music(KodiDb):
|
|||
''' Get all child elements from tv show jellyfin id.
|
||||
'''
|
||||
obj = {'Id': item_id}
|
||||
child = []
|
||||
child: List[str] = []
|
||||
|
||||
try:
|
||||
obj['KodiId'] = e_item[0]
|
||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
|
||||
import datetime
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
from six.moves.urllib.parse import urlencode
|
||||
from kodi_six.utils import py2_encode
|
||||
|
@ -122,7 +123,7 @@ class MusicVideos(KodiDb):
|
|||
if search:
|
||||
obj['Index'] = search.group()
|
||||
|
||||
tags = []
|
||||
tags: List[str] = []
|
||||
tags.extend(obj['Tags'] or [])
|
||||
tags.append(obj['LibraryName'])
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
|
||||
import sqlite3
|
||||
from ntpath import dirname
|
||||
from typing import List
|
||||
|
||||
from six.moves.urllib.parse import urlencode
|
||||
from kodi_six.utils import py2_encode
|
||||
|
@ -101,7 +102,7 @@ class TVShows(KodiDb):
|
|||
if obj['Premiere']:
|
||||
obj['Premiere'] = str(Local(obj['Premiere'])).split('.')[0].replace('T', " ")
|
||||
|
||||
tags = []
|
||||
tags: List[str] = []
|
||||
tags.extend(obj['Tags'] or [])
|
||||
tags.append(obj['LibraryName'])
|
||||
|
||||
|
@ -623,7 +624,7 @@ class TVShows(KodiDb):
|
|||
''' Get all child elements from tv show jellyfin id.
|
||||
'''
|
||||
obj = {'Id': item_id}
|
||||
child = []
|
||||
child: List[str] = []
|
||||
|
||||
try:
|
||||
obj['KodiId'] = e_item[0]
|
||||
|
|
4
mypy.ini
Normal file
4
mypy.ini
Normal file
|
@ -0,0 +1,4 @@
|
|||
[mypy]
|
||||
check_untyped_defs = True
|
||||
warn_unused_configs = True
|
||||
files = .
|
Loading…
Reference in a new issue