Fix linting, flake8 and sonarcloud issues

This commit is contained in:
Odd Stråbø 2020-04-19 12:07:55 +02:00
parent 87af711c94
commit 3f63e7c213
27 changed files with 162 additions and 169 deletions

View file

@ -20,6 +20,8 @@ from helper import LazyLogger
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)
ADDON_DATA = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/")
################################################################################################# #################################################################################################
@ -67,8 +69,8 @@ class Database(object):
contents = query.fetchall() contents = query.fetchall()
if contents: if contents:
for item in contents: for item in contents:
newPath = item[1].replace('/emby/', '/') new_path = item[1].replace('/emby/', '/')
self.conn.execute('UPDATE path SET strPath = "{}" WHERE idPath = "{}"'.format(newPath, item[0])) self.conn.execute('UPDATE path SET strPath = "{}" WHERE idPath = "{}"'.format(new_path, item[0]))
return self return self
@ -249,16 +251,14 @@ def reset():
if dialog("yesno", heading="{jellyfin}", line1=translate(33086)): if dialog("yesno", heading="{jellyfin}", line1=translate(33086)):
reset_artwork() reset_artwork()
addon_data = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/")
if dialog("yesno", heading="{jellyfin}", line1=translate(33087)): if dialog("yesno", heading="{jellyfin}", line1=translate(33087)):
xbmcvfs.delete(os.path.join(addon_data, "settings.xml")) xbmcvfs.delete(os.path.join(ADDON_DATA, "settings.xml"))
xbmcvfs.delete(os.path.join(addon_data, "data.json")) xbmcvfs.delete(os.path.join(ADDON_DATA, "data.json"))
LOG.info("[ reset settings ]") LOG.info("[ reset settings ]")
if xbmcvfs.exists(os.path.join(addon_data, "sync.json")): if xbmcvfs.exists(os.path.join(ADDON_DATA, "sync.json")):
xbmcvfs.delete(os.path.join(addon_data, "sync.json")) xbmcvfs.delete(os.path.join(ADDON_DATA, "sync.json"))
settings('enableMusic.bool', False) settings('enableMusic.bool', False)
settings('MinimumSetup', "") settings('MinimumSetup', "")
@ -341,13 +341,11 @@ def reset_artwork():
def get_sync(): def get_sync():
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/") if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(ADDON_DATA)
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
try: try:
with open(os.path.join(path, 'sync.json'), 'rb') as infile: with open(os.path.join(ADDON_DATA, 'sync.json'), 'rb') as infile:
sync = json.load(infile, encoding='utf-8') sync = json.load(infile, encoding='utf-8')
except Exception: except Exception:
sync = {} sync = {}
@ -362,14 +360,12 @@ def get_sync():
def save_sync(sync): def save_sync(sync):
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/") if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(ADDON_DATA)
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
sync['Date'] = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') sync['Date'] = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
with open(os.path.join(path, 'sync.json'), 'wb') as outfile: with open(os.path.join(ADDON_DATA, 'sync.json'), 'wb') as outfile:
data = json.dumps(sync, sort_keys=True, indent=4, ensure_ascii=False) data = json.dumps(sync, sort_keys=True, indent=4, ensure_ascii=False)
if isinstance(data, text_type): if isinstance(data, text_type):
data = data.encode('utf-8') data = data.encode('utf-8')
@ -378,22 +374,20 @@ def save_sync(sync):
def get_credentials(): def get_credentials():
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/") if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(ADDON_DATA)
if not xbmcvfs.exists(path):
xbmcvfs.mkdirs(path)
try: try:
with open(os.path.join(path, 'data.json'), 'rb') as infile: with open(os.path.join(ADDON_DATA, 'data.json'), 'rb') as infile:
credentials = json.load(infile, encoding='utf8') credentials = json.load(infile, encoding='utf8')
except Exception: except Exception:
try: try:
with open(os.path.join(path, 'data.txt'), 'rb') as infile: with open(os.path.join(ADDON_DATA, 'data.txt'), 'rb') as infile:
credentials = json.load(infile, encoding='utf-8') credentials = json.load(infile, encoding='utf-8')
save_credentials(credentials) save_credentials(credentials)
xbmcvfs.delete(os.path.join(path, 'data.txt')) xbmcvfs.delete(os.path.join(ADDON_DATA, 'data.txt'))
except Exception: except Exception:
credentials = {} credentials = {}
@ -422,12 +416,11 @@ def get_credentials():
def save_credentials(credentials): def save_credentials(credentials):
credentials = credentials or {} credentials = credentials or {}
path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/")
if not xbmcvfs.exists(path): if not xbmcvfs.exists(ADDON_DATA):
xbmcvfs.mkdirs(path) xbmcvfs.mkdirs(ADDON_DATA)
try: try:
with open(os.path.join(path, 'data.json'), 'wb') as outfile: with open(os.path.join(ADDON_DATA, 'data.json'), 'wb') as outfile:
data = json.dumps(credentials, sort_keys=True, indent=4, ensure_ascii=False) data = json.dumps(credentials, sort_keys=True, indent=4, ensure_ascii=False)
if isinstance(data, text_type): if isinstance(data, text_type):
data = data.encode('utf-8') data = data.encode('utf-8')

View file

@ -34,8 +34,11 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs) xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
def set_options(self, options=[]): def set_options(self, options=None):
self._options = options if options is None:
self._options = []
else:
self._options = options
def is_selected(self): def is_selected(self):
return True if self.selected_option else False return True if self.selected_option else False

View file

@ -3,12 +3,10 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################## ##################################################################################################
import os
from six import iteritems from six import iteritems
from kodi_six import xbmcgui, xbmcaddon from kodi_six import xbmcgui
from helper import translate, addon_id from helper import translate
from helper import LazyLogger from helper import LazyLogger
################################################################################################## ##################################################################################################
@ -97,9 +95,8 @@ class LoginManual(xbmcgui.WindowXMLDialog):
if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU): if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU):
self.close() self.close()
def _add_editcontrol(self, x, y, height, width, password=0): def _add_editcontrol(self, x, y, height, width, password=False):
media = os.path.join(xbmcaddon.Addon(addon_id()).getAddonInfo('path'), 'resources', 'skins', 'default', 'media')
control = xbmcgui.ControlEdit(0, 0, 0, 0, control = xbmcgui.ControlEdit(0, 0, 0, 0,
label="User", label="User",
font="font13", font="font13",

View file

@ -46,12 +46,12 @@ class ResumeDialog(xbmcgui.WindowXMLDialog):
if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU): if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU):
self.close() self.close()
def onClick(self, controlID): def onClick(self, control_id):
if controlID == RESUME: if control_id == RESUME:
self.selected_option = 1 self.selected_option = 1
self.close() self.close()
if controlID == START_BEGINNING: if control_id == START_BEGINNING:
self.selected_option = 0 self.selected_option = 0
self.close() self.close()

View file

@ -3,13 +3,12 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################## ##################################################################################################
import os
import re import re
from six import iteritems from six import iteritems
from kodi_six import xbmcgui, xbmcaddon from kodi_six import xbmcgui
from helper import translate, addon_id from helper import translate
from jellyfin.connection_manager import CONNECTION_STATE from jellyfin.connection_manager import CONNECTION_STATE
from helper import LazyLogger from helper import LazyLogger
@ -98,7 +97,6 @@ class ServerManual(xbmcgui.WindowXMLDialog):
def _add_editcontrol(self, x, y, height, width): def _add_editcontrol(self, x, y, height, width):
media = os.path.join(xbmcaddon.Addon(addon_id()).getAddonInfo('path'), 'resources', 'skins', 'default', 'media')
control = xbmcgui.ControlEdit(0, 0, 0, 0, control = xbmcgui.ControlEdit(0, 0, 0, 0,
label="User", label="User",
font="font13", font="font13",

View file

@ -43,7 +43,11 @@ def browse_info():
) )
def _http(action, url, request={}, server_id=None): def _http(action, url, request=None, server_id=None):
if request is None:
request = {}
request.update({'url': url, 'type': action}) request.update({'url': url, 'type': action})
return Jellyfin(server_id).http.request(request) return Jellyfin(server_id).http.request(request)
@ -268,8 +272,11 @@ def _get_items(query, server_id=None):
params_copy['Limit'] = count params_copy['Limit'] = count
return params_copy return params_copy
query_params = [get_query_params(params, offset, LIMIT) \ query_params = [
for offset in range(params['StartIndex'], items['TotalRecordCount'], LIMIT)] get_query_params(params, offset, LIMIT)
for offset
in range(params['StartIndex'], items['TotalRecordCount'], LIMIT)
]
# multiprocessing.dummy.Pool completes all requests in multiple threads but has to # multiprocessing.dummy.Pool completes all requests in multiple threads but has to
# complete all tasks before allowing any results to be processed. ThreadPoolExecutor # complete all tasks before allowing any results to be processed. ThreadPoolExecutor

View file

@ -22,6 +22,10 @@ from helper import LazyLogger
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)
ADDON_BASE_URL = sys.argv[0]
PROCESS_HANDLE = int(sys.argv[1])
QUERY_STRING = sys.argv[2]
################################################################################################# #################################################################################################
@ -32,8 +36,8 @@ class Events(object):
''' Parse the parameters. Reroute to our service.py ''' Parse the parameters. Reroute to our service.py
where user is fully identified already. where user is fully identified already.
''' '''
base_url = sys.argv[0] base_url = ADDON_BASE_URL
path = sys.argv[2] path = QUERY_STRING
try: try:
params = dict(parse_qsl(path[1:])) params = dict(parse_qsl(path[1:]))
@ -183,8 +187,8 @@ def listing():
if settings('backupPath'): if settings('backupPath'):
directory(translate(33092), "plugin://plugin.video.jellyfin/?mode=backup", False) directory(translate(33092), "plugin://plugin.video.jellyfin/?mode=backup", False)
xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.setContent(PROCESS_HANDLE, 'files')
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def directory(label, path, folder=True, artwork=None, fanart=None, context=None): def directory(label, path, folder=True, artwork=None, fanart=None, context=None):
@ -196,7 +200,7 @@ def directory(label, path, folder=True, artwork=None, fanart=None, context=None)
if context: if context:
li.addContextMenuItems(context) li.addContextMenuItems(context)
xbmcplugin.addDirectoryItem(int(sys.argv[1]), path, li, folder) xbmcplugin.addDirectoryItem(PROCESS_HANDLE, path, li, folder)
return li return li
@ -224,8 +228,8 @@ def manage_libraries():
directory(translate(33184), "plugin://plugin.video.jellyfin/?mode=removelibs", False) directory(translate(33184), "plugin://plugin.video.jellyfin/?mode=removelibs", False)
directory(translate(33060), "plugin://plugin.video.jellyfin/?mode=thememedia", False) directory(translate(33060), "plugin://plugin.video.jellyfin/?mode=thememedia", False)
xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.setContent(PROCESS_HANDLE, 'files')
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def browse(media, view_id=None, folder=None, server_id=None): def browse(media, view_id=None, folder=None, server_id=None):
@ -259,7 +263,7 @@ def browse(media, view_id=None, folder=None, server_id=None):
if view_id: if view_id:
view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get() view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get()
xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name']) xbmcplugin.setPluginCategory(PROCESS_HANDLE, view['Name'])
content_type = "files" content_type = "files"
@ -381,16 +385,16 @@ def browse(media, view_id=None, folder=None, server_id=None):
list_li.append((li.getProperty('path'), li, False)) list_li.append((li.getProperty('path'), li, False))
xbmcplugin.addDirectoryItems(int(sys.argv[1]), list_li, len(list_li)) xbmcplugin.addDirectoryItems(PROCESS_HANDLE, list_li, len(list_li))
if content_type == 'images': if content_type == 'images':
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_VIDEO_TITLE)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RATING) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_VIDEO_RATING)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RUNTIME) xbmcplugin.addSortMethod(PROCESS_HANDLE, xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
xbmcplugin.setContent(int(sys.argv[1]), content_type) xbmcplugin.setContent(PROCESS_HANDLE, content_type)
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def browse_subfolders(media, view_id, server_id=None): def browse_subfolders(media, view_id, server_id=None):
@ -400,7 +404,7 @@ def browse_subfolders(media, view_id, server_id=None):
from views import DYNNODES from views import DYNNODES
view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get() view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get()
xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name']) xbmcplugin.setPluginCategory(PROCESS_HANDLE, view['Name'])
nodes = DYNNODES[media] nodes = DYNNODES[media]
for node in nodes: for node in nodes:
@ -415,8 +419,8 @@ def browse_subfolders(media, view_id, server_id=None):
path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params))
directory(node[1] or view['Name'], path) directory(node[1] or view['Name'], path)
xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.setContent(PROCESS_HANDLE, 'files')
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def browse_letters(media, view_id, server_id=None): def browse_letters(media, view_id, server_id=None):
@ -426,7 +430,7 @@ def browse_letters(media, view_id, server_id=None):
letters = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ" letters = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ"
view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get() view = TheVoid('GetItem', {'ServerId': server_id, 'Id': view_id}).get()
xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name']) xbmcplugin.setPluginCategory(PROCESS_HANDLE, view['Name'])
for node in letters: for node in letters:
@ -440,8 +444,8 @@ def browse_letters(media, view_id, server_id=None):
path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params)) path = "%s?%s" % ("plugin://plugin.video.jellyfin/", urlencode(params))
directory(node, path) directory(node, path)
xbmcplugin.setContent(int(sys.argv[1]), 'files') xbmcplugin.setContent(PROCESS_HANDLE, 'files')
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def get_folder_type(item, content_type=None): def get_folder_type(item, content_type=None):
@ -521,8 +525,8 @@ def get_fanart(item_id, path, server_id=None):
li = xbmcgui.ListItem(file, path=fanart) li = xbmcgui.ListItem(file, path=fanart)
list_li.append((fanart, li, False)) list_li.append((fanart, li, False))
xbmcplugin.addDirectoryItems(int(sys.argv[1]), list_li, len(list_li)) xbmcplugin.addDirectoryItems(PROCESS_HANDLE, list_li, len(list_li))
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def get_video_extras(item_id, path, server_id=None): def get_video_extras(item_id, path, server_id=None):
@ -536,8 +540,8 @@ def get_video_extras(item_id, path, server_id=None):
if not item_id: if not item_id:
return return
item = TheVoid('GetItem', {'ServerId': server_id, 'Id': item_id}).get() TheVoid('GetItem', {'ServerId': server_id, 'Id': item_id}).get()
# TODO # TODO: Investigate the void (issue #228)
""" """
def getVideoFiles(jellyfinId,jellyfinPath): def getVideoFiles(jellyfinId,jellyfinPath):
@ -558,12 +562,12 @@ def get_video_extras(item_id, path, server_id=None):
for file in files: for file in files:
file = filelocation + file file = filelocation + file
li = xbmcgui.ListItem(file, path=file) li = xbmcgui.ListItem(file, path=file)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=file, listitem=li) xbmcplugin.addDirectoryItem(handle=PROCESS_HANDLE, url=file, listitem=li)
for dir in dirs: for dir in dirs:
dir = filelocation + dir dir = filelocation + dir
li = xbmcgui.ListItem(dir, path=dir) li = xbmcgui.ListItem(dir, path=dir)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=dir, listitem=li, isFolder=True) xbmcplugin.addDirectoryItem(handle=PROCESS_HANDLE, url=dir, listitem=li, isFolder=True)
#xbmcplugin.endOfDirectory(int(sys.argv[1])) #xbmcplugin.endOfDirectory(PROCESS_HANDLE)
""" """
@ -643,9 +647,9 @@ def get_next_episodes(item_id, limit):
if len(list_li) == limit: if len(list_li) == limit:
break break
xbmcplugin.addDirectoryItems(int(sys.argv[1]), list_li, len(list_li)) xbmcplugin.addDirectoryItems(PROCESS_HANDLE, list_li, len(list_li))
xbmcplugin.setContent(int(sys.argv[1]), 'episodes') xbmcplugin.setContent(PROCESS_HANDLE, 'episodes')
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(PROCESS_HANDLE)
def create_listitem(item): def create_listitem(item):

View file

@ -12,9 +12,9 @@ from kodi_six import xbmc, xbmcvfs
import client import client
import requests import requests
from downloader import TheVoid from downloader import TheVoid
from helper import LazyLogger
from . import translate, settings, window, dialog, api from . import translate, settings, window, dialog, api
from helper import LazyLogger
################################################################################################# #################################################################################################
@ -152,7 +152,7 @@ class PlayUtils(object):
def is_file_exists(self, source): def is_file_exists(self, source):
path = self.direct_play(source) self.direct_play(source)
if xbmcvfs.exists(self.info['Path']): if xbmcvfs.exists(self.info['Path']):
LOG.info("Path exists.") LOG.info("Path exists.")

View file

@ -244,8 +244,6 @@ def validate(path):
if window('jellyfin_pathverified.bool'): if window('jellyfin_pathverified.bool'):
return True return True
path = path if os.path.supports_unicode_filenames else path
if not xbmcvfs.exists(path): if not xbmcvfs.exists(path):
LOG.info("Could not find %s", path) LOG.info("Could not find %s", path)

View file

@ -5,9 +5,10 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import logging import logging
from .client import JellyfinClient
from helper import has_attribute, LazyLogger from helper import has_attribute, LazyLogger
from .client import JellyfinClient
################################################################################################# #################################################################################################
LOG = LazyLogger() LOG = LazyLogger()

View file

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals from __future__ import division, absolute_import, print_function, unicode_literals
import requests
import json import json
import requests
from helper.utils import settings from helper.utils import settings
from helper import LazyLogger from helper import LazyLogger
@ -46,7 +48,10 @@ class API(object):
self.config = client.config self.config = client.config
self.default_timeout = 5 self.default_timeout = 5
def _http(self, action, url, request={}): def _http(self, action, url, request=None):
if request is None:
request = {}
request.update({'type': action, 'handler': url}) request.update({'type': action, 'handler': url})
return self.client.request(request) return self.client.request(request)
@ -392,7 +397,7 @@ class API(object):
def login(self, server_url, username, password=""): def login(self, server_url, username, password=""):
path = "Users/AuthenticateByName" path = "Users/AuthenticateByName"
authData = { auth_data = {
"username": username, "username": username,
"Pw": password "Pw": password
} }
@ -402,7 +407,7 @@ class API(object):
try: try:
LOG.info("Trying to login to %s/%s as %s" % (server_url, path, username)) LOG.info("Trying to login to %s/%s as %s" % (server_url, path, username))
response = self.send_request(server_url, path, method="post", headers=headers, data=json.dumps(authData)) response = self.send_request(server_url, path, method="post", headers=headers, data=json.dumps(auth_data))
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()
@ -418,13 +423,11 @@ class API(object):
return {} return {}
def validate_authentication_token(self, server): def validate_authentication_token(self, server):
auth_token_header = {
url = "%s/%s" % (server['address'], "system/info")
authTokenHeader = {
'X-MediaBrowser-Token': server['AccessToken'] 'X-MediaBrowser-Token': server['AccessToken']
} }
headers = self.get_default_headers() headers = self.get_default_headers()
headers.update(authTokenHeader) headers.update(auth_token_header)
response = self.send_request(server['address'], "system/info", headers=headers) response = self.send_request(server['address'], "system/info", headers=headers)
return response.json() if response.status_code == 200 else {} return response.json() if response.status_code == 200 else {}

View file

@ -5,18 +5,17 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json import json
import socket import socket
import time
from datetime import datetime from datetime import datetime
from operator import itemgetter from operator import itemgetter
import traceback
import urllib3 import urllib3
from .credentials import Credentials
from .http import HTTP # noqa: I201,I100
from .api import API
import traceback
from helper import LazyLogger from helper import LazyLogger
from .credentials import Credentials
from .api import API
################################################################################################# #################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)
@ -29,6 +28,7 @@ CONNECTION_STATE = {
################################################################################################# #################################################################################################
class ConnectionManager(object): class ConnectionManager(object):
user = {} user = {}
@ -88,7 +88,7 @@ class ConnectionManager(object):
if not server_url: if not server_url:
raise AttributeError("server url cannot be empty") raise AttributeError("server url cannot be empty")
data = self.API.login(server_url, username, password) # returns empty dict on failure data = self.API.login(server_url, username, password) # returns empty dict on failure
if not data: if not data:
LOG.info("Failed to login as `"+username+"`") LOG.info("Failed to login as `"+username+"`")
@ -106,7 +106,7 @@ class ConnectionManager(object):
found_server = server found_server = server
break break
else: else:
return {} # No server found return {} # No server found
found_server['DateLastAccessed'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') found_server['DateLastAccessed'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
found_server['UserId'] = data['User']['Id'] found_server['UserId'] = data['User']['Id']
@ -124,7 +124,6 @@ class ConnectionManager(object):
return data return data
def connect_to_address(self, address, options={}): def connect_to_address(self, address, options={}):
if not address: if not address:
@ -143,14 +142,13 @@ class ConnectionManager(object):
server = self.connect_to_server(server, options) server = self.connect_to_server(server, options)
if server is False: if server is False:
LOG.error("connectToAddress %s failed", address) LOG.error("connectToAddress %s failed", address)
return { 'State': CONNECTION_STATE['Unavailable'] } return {'State': CONNECTION_STATE['Unavailable']}
return server return server
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception(error)
LOG.error("connectToAddress %s failed", address) LOG.error("connectToAddress %s failed", address)
return { 'State': CONNECTION_STATE['Unavailable'] } return {'State': CONNECTION_STATE['Unavailable']}
def connect_to_server(self, server, options={}): def connect_to_server(self, server, options={}):
@ -161,7 +159,7 @@ class ConnectionManager(object):
if not result: if not result:
LOG.error("Failed to connect to server: %s" % server.get('address')) LOG.error("Failed to connect to server: %s" % server.get('address'))
return { 'State': CONNECTION_STATE['Unavailable'] } return {'State': CONNECTION_STATE['Unavailable']}
LOG.info("calling onSuccessfulConnection with server %s", server.get('Name')) LOG.info("calling onSuccessfulConnection with server %s", server.get('Name'))
@ -172,7 +170,7 @@ class ConnectionManager(object):
except Exception as e: except Exception as e:
LOG.error(traceback.format_exc()) LOG.error(traceback.format_exc())
LOG.error("Failing server connection. ERROR msg: {}".format(e)) LOG.error("Failing server connection. ERROR msg: {}".format(e))
return { 'State': CONNECTION_STATE['Unavailable'] } return {'State': CONNECTION_STATE['Unavailable']}
def connect(self, options={}): def connect(self, options={}):
@ -181,7 +179,7 @@ class ConnectionManager(object):
servers = self.get_available_servers() servers = self.get_available_servers()
LOG.info("connect has %s servers", len(servers)) LOG.info("connect has %s servers", len(servers))
if not (len(servers)): # No servers provided if not (len(servers)): # No servers provided
return { return {
'State': ['ServerSelection'] 'State': ['ServerSelection']
} }
@ -191,7 +189,7 @@ class ConnectionManager(object):
return result return result
def jellyfin_token(self): # Called once monitor.py#163 def jellyfin_token(self): # Called once monitor.py#163
return self.get_server_info(self.server_id)['AccessToken'] return self.get_server_info(self.server_id)['AccessToken']
def get_server_info(self, server_id): def get_server_info(self, server_id):
@ -321,7 +319,7 @@ class ConnectionManager(object):
server['UserId'] = None server['UserId'] = None
server['AccessToken'] = None server['AccessToken'] = None
return { 'State': CONNECTION_STATE['Unavailable'] } return {'State': CONNECTION_STATE['Unavailable']}
self._update_server_info(server, system_info) self._update_server_info(server, system_info)

View file

@ -3,16 +3,16 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################# #################################################################################################
import json
import time import time
import requests import requests
from six import string_types from six import string_types
from .exceptions import HTTPException
from helper.utils import JsonDebugPrinter from helper.utils import JsonDebugPrinter
from helper import LazyLogger from helper import LazyLogger
from .exceptions import HTTPException
################################################################################################# #################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)
@ -154,9 +154,6 @@ class HTTP(object):
LOG.error("Request missing Schema. " + str(error)) LOG.error("Request missing Schema. " + str(error))
raise HTTPException("MissingSchema", {'Id': self.config.data.get('auth.server', "None")}) raise HTTPException("MissingSchema", {'Id': self.config.data.get('auth.server', "None")})
except Exception as error:
raise
else: else:
try: try:
self.config.data['server-time'] = r.headers['Date'] self.config.data['server-time'] = r.headers['Date']

View file

@ -727,7 +727,7 @@ class WebSocket(object):
try: try:
self.sock.shutdown(socket.SHUT_RDWR) self.sock.shutdown(socket.SHUT_RDWR)
except: # noqa: E722 except Exception:
pass pass
''' '''
@ -813,7 +813,7 @@ class WebSocketApp(object):
Higher level of APIs are provided. Higher level of APIs are provided.
The interface is like JavaScript WebSocket object. The interface is like JavaScript WebSocket object.
""" """
def __init__(self, url, header=[], def __init__(self, url, header=None,
on_open=None, on_message=None, on_error=None, on_open=None, on_message=None, on_error=None,
on_close=None, keep_running=True, get_mask_key=None): on_close=None, keep_running=True, get_mask_key=None):
""" """
@ -837,7 +837,10 @@ class WebSocketApp(object):
docstring for more information docstring for more information
""" """
self.url = url self.url = url
self.header = header if header is None:
self.header = []
else:
self.header = header
self.on_open = on_open self.on_open = on_open
self.on_message = on_message self.on_message = on_message
self.on_error = on_error self.on_error = on_error

View file

@ -90,7 +90,7 @@ class Library(threading.Thread):
try: try:
self.service() self.service()
except LibraryException as error: except LibraryException:
break break
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception(error)
@ -662,20 +662,19 @@ class UserDataWorker(threading.Thread):
except Queue.Empty: except Queue.Empty:
break break
try: try:
if item['Type'] == 'Movie': if item['Type'] == 'Movie':
obj = Movies(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item) Movies(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item)
elif item['Type'] in ['Series', 'Season', 'Episode']: elif item['Type'] in ['Series', 'Season', 'Episode']:
obj = TVShows(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item) TVShows(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item)
elif item['Type'] == 'MusicAlbum': elif item['Type'] == 'MusicAlbum':
obj = Music(self.args[0], jellyfindb, kodidb, self.args[1]).album(item) Music(self.args[0], jellyfindb, kodidb, self.args[1]).album(item)
elif item['Type'] == 'MusicArtist': elif item['Type'] == 'MusicArtist':
obj = Music(self.args[0], jellyfindb, kodidb, self.args[1]).artist(item) Music(self.args[0], jellyfindb, kodidb, self.args[1]).artist(item)
elif item['Type'] == 'AlbumArtist': elif item['Type'] == 'AlbumArtist':
obj = Music(self.args[0], jellyfindb, kodidb, self.args[1]).albumartist(item) Music(self.args[0], jellyfindb, kodidb, self.args[1]).albumartist(item)
elif item['Type'] == 'Audio': elif item['Type'] == 'Audio':
obj = Music(self.args[0], jellyfindb, kodidb, self.args[1]).song(item) Music(self.args[0], jellyfindb, kodidb, self.args[1]).song(item)
except LibraryException as error: except LibraryException as error:
if error.status == 'StopCalled': if error.status == 'StopCalled':
break break

View file

@ -11,11 +11,12 @@ from kodi_six import xbmc, xbmcgui, xbmcplugin, xbmcaddon
import database import database
from downloader import TheVoid from downloader import TheVoid
from .obj import Objects
from helper import translate, playutils, api, window, settings, dialog from helper import translate, playutils, api, window, settings, dialog
from dialogs import resume from dialogs import resume
from helper import LazyLogger from helper import LazyLogger
from .obj import Objects
################################################################################################# #################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)
@ -133,7 +134,7 @@ class Actions(object):
LOG.info("[ intro/%s ] %s", intro['Id'], intro['Name']) LOG.info("[ intro/%s ] %s", intro['Id'], intro['Name'])
play = playutils.PlayUtils(intro, False, self.server_id, self.server) play = playutils.PlayUtils(intro, False, self.server_id, self.server)
source = play.select_source(play.get_sources()) play.select_source(play.get_sources())
self.set_listitem(intro, listitem, intro=True) self.set_listitem(intro, listitem, intro=True)
listitem.setPath(intro['PlaybackInfo']['Path']) listitem.setPath(intro['PlaybackInfo']['Path'])
playutils.set_properties(intro, intro['PlaybackInfo']['Method'], self.server_id) playutils.set_properties(intro, intro['PlaybackInfo']['Method'], self.server_id)
@ -797,10 +798,10 @@ def special_listener():
This is run in a loop within monitor.py This is run in a loop within monitor.py
''' '''
player = xbmc.Player() player = xbmc.Player()
isPlaying = player.isPlaying() is_playing = player.isPlaying()
count = int(window('jellyfin.external_count') or 0) count = int(window('jellyfin.external_count') or 0)
if (not isPlaying and xbmc.getCondVisibility('Window.IsVisible(DialogContextMenu.xml)') and xbmc.getInfoLabel('Control.GetLabel(1002)') == xbmc.getLocalizedString(12021)): if (not is_playing and xbmc.getCondVisibility('Window.IsVisible(DialogContextMenu.xml)') and xbmc.getInfoLabel('Control.GetLabel(1002)') == xbmc.getLocalizedString(12021)):
control = int(xbmcgui.Window(10106).getFocusId()) control = int(xbmcgui.Window(10106).getFocusId())
@ -812,7 +813,7 @@ def special_listener():
LOG.info("Resume dialog: Resume selected.") LOG.info("Resume dialog: Resume selected.")
window('jellyfin.resume.bool', True) window('jellyfin.resume.bool', True)
elif isPlaying and not window('jellyfin.external_check'): elif is_playing and not window('jellyfin.external_check'):
time = player.getTime() time = player.getTime()
if time > 1: # Not external player. if time > 1: # Not external player.

View file

@ -3,18 +3,9 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################# #################################################################################################
import threading from helper import LazyLogger
from six.moves import queue as Queue
from six.moves.urllib.parse import urlencode
from kodi_six import xbmc, xbmcvfs
from . import queries as QU from . import queries as QU
from . import queries_texture as QUTEX
from helper import settings
import requests
from helper import LazyLogger
################################################################################################## ##################################################################################################

View file

@ -3,11 +3,13 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################## ##################################################################################################
from sqlite3 import IntegrityError
from helper import values
from helper import LazyLogger
from . import artwork from . import artwork
from . import queries as QU from . import queries as QU
from helper import values
from sqlite3 import IntegrityError
from helper import LazyLogger
################################################################################################## ##################################################################################################
@ -23,7 +25,7 @@ class Kodi(object):
try: try:
self.cursor.execute(QU.get_all_people) self.cursor.execute(QU.get_all_people)
except: except Exception:
# Failed to load the table. Has the table been created? # Failed to load the table. Has the table been created?
self._people_cache = {} self._people_cache = {}
else: else:
@ -276,7 +278,7 @@ class Kodi(object):
self.cursor.execute(QU.delete_tags, args) self.cursor.execute(QU.delete_tags, args)
for tag in tags: for tag in tags:
tag_id = self.get_tag(tag, *args) self.get_tag(tag, *args)
def add_tag(self, *args): def add_tag(self, *args):

View file

@ -61,15 +61,15 @@ class Music(Kodi):
try: try:
self.cursor.execute(QU.get_artist, (musicbrainz,)) self.cursor.execute(QU.get_artist, (musicbrainz,))
result = self.cursor.fetchone() result = self.cursor.fetchone()
artist_id = result[0] artist_id_res = result[0]
artist_name = result[1] artist_name = result[1]
except TypeError: except TypeError:
artist_id = self.add_artist(artist_id, name, musicbrainz) artist_id_res = self.add_artist(artist_id, name, musicbrainz)
else: else:
if artist_name != name: if artist_name != name:
self.update_artist_name(artist_id, name) self.update_artist_name(artist_id, name)
return artist_id return artist_id_res
def add_artist(self, artist_id, name, *args): def add_artist(self, artist_id, name, *args):
@ -77,12 +77,12 @@ class Music(Kodi):
''' '''
try: try:
self.cursor.execute(QU.get_artist_by_name, (name,)) self.cursor.execute(QU.get_artist_by_name, (name,))
artist_id = self.cursor.fetchone()[0] artist_id_res = self.cursor.fetchone()[0]
except TypeError: except TypeError:
artist_id = artist_id or self.create_entry() artist_id_res = artist_id or self.create_entry()
self.cursor.execute(QU.add_artist, (artist_id, name,) + args) self.cursor.execute(QU.add_artist, (artist_id, name,) + args)
return artist_id return artist_id_res
def update_artist_name(self, *args): def update_artist_name(self, *args):
self.cursor.execute(QU.update_artist_name, args) self.cursor.execute(QU.update_artist_name, args)

View file

@ -7,11 +7,12 @@ from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode from kodi_six.utils import py2_encode
import downloader as server import downloader as server
from database import jellyfin_db, queries as QUEM
from helper import api, stop, validate, jellyfin_item, library_check, values, Local
from helper import LazyLogger
from .obj import Objects from .obj import Objects
from .kodi import Movies as KodiDb, queries as QU from .kodi import Movies as KodiDb, queries as QU
from database import jellyfin_db, queries as QUEM
from helper import api, stop, validate, jellyfin_item, library_check, values, settings, Local
from helper import LazyLogger
################################################################################################## ##################################################################################################

View file

@ -5,12 +5,12 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import datetime import datetime
from .obj import Objects
from .kodi import Music as KodiDb, queries_music as QU
from database import jellyfin_db, queries as QUEM from database import jellyfin_db, queries as QUEM
from helper import api, stop, validate, jellyfin_item, values, library_check, Local from helper import api, stop, validate, jellyfin_item, values, library_check, Local
from helper import LazyLogger from helper import LazyLogger
from .obj import Objects
from .kodi import Music as KodiDb, queries_music as QU
################################################################################################## ##################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)

View file

@ -5,15 +5,17 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import datetime import datetime
import re import re
from six.moves.urllib.parse import urlencode from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode from kodi_six.utils import py2_encode
from .obj import Objects
from .kodi import MusicVideos as KodiDb, queries as QU
from database import jellyfin_db, queries as QUEM from database import jellyfin_db, queries as QUEM
from helper import api, stop, validate, library_check, jellyfin_item, values, Local from helper import api, stop, validate, library_check, jellyfin_item, values, Local
from helper import LazyLogger from helper import LazyLogger
from .obj import Objects
from .kodi import MusicVideos as KodiDb, queries as QU
################################################################################################## ##################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)

View file

@ -86,9 +86,7 @@ class Objects(object):
for d in self.__recursiveloop__(obj, obj_param): for d in self.__recursiveloop__(obj, obj_param):
if obj_filters and self.__filters__(d, obj_filters): if not obj_filters or self.__filters__(d, obj_filters):
result.append(d)
elif not obj_filters:
result.append(d) result.append(d)
obj = result obj = result

View file

@ -286,7 +286,6 @@
"DatePlayed": "UserData/LastPlayedDate", "DatePlayed": "UserData/LastPlayedDate",
"Artists": "Artists", "Artists": "Artists",
"Album": "Album", "Album": "Album",
"Votes": "VoteCount",
"Path": "Path", "Path": "Path",
"LocalTrailer": "LocalTrailerCount", "LocalTrailer": "LocalTrailerCount",
"Trailer": "RemoteTrailers/0/Url", "Trailer": "RemoteTrailers/0/Url",

View file

@ -9,13 +9,14 @@ from ntpath import dirname
from six.moves.urllib.parse import urlencode from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode from kodi_six.utils import py2_encode
from .obj import Objects
from .kodi import TVShows as KodiDb, queries as QU
import downloader as server import downloader as server
from database import jellyfin_db, queries as QUEM from database import jellyfin_db, queries as QUEM
from helper import api, stop, validate, jellyfin_item, library_check, settings, values, Local from helper import api, stop, validate, jellyfin_item, library_check, values, Local
from helper import LazyLogger from helper import LazyLogger
from .obj import Objects
from .kodi import TVShows as KodiDb, queries as QU
################################################################################################## ##################################################################################################
LOG = LazyLogger(__name__) LOG = LazyLogger(__name__)

View file

@ -290,7 +290,7 @@ class Player(xbmc.Player):
self.report_playback() self.report_playback()
LOG.debug("--<[ paused ]") LOG.debug("--<[ paused ]")
def onPlayBackSeek(self, time, seekOffset): def onPlayBackSeek(self, time, seek_offset):
''' Does not seem to work in Leia?? ''' Does not seem to work in Leia??
''' '''

View file

@ -3,9 +3,10 @@ from __future__ import division, absolute_import, print_function, unicode_litera
################################################################################################# #################################################################################################
import threading
from six.moves import BaseHTTPServer from six.moves import BaseHTTPServer
from six.moves import http_client as httplib from six.moves import http_client as httplib
import threading
from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import parse_qsl
from kodi_six import xbmc from kodi_six import xbmc
@ -112,8 +113,6 @@ class requestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
return
def do_GET(self): def do_GET(self):
''' Return plugin path ''' Return plugin path
@ -143,5 +142,3 @@ class requestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
LOG.exception(error) LOG.exception(error)
self.send_error(500, "Exception occurred: %s" % error) self.send_error(500, "Exception occurred: %s" % error)
return