From cdd38c6ef77e5d8295fa765c629c89c4e512c1de Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sat, 9 Dec 2017 14:35:08 +0100 Subject: [PATCH] Optimize some imports --- resources/lib/PlexAPI.py | 4 ++-- resources/lib/PlexCompanion.py | 12 ++++++------ resources/lib/artwork.py | 4 ++-- resources/lib/clientinfo.py | 4 ++-- resources/lib/context_entry.py | 2 -- resources/lib/downloadutils.py | 7 +++---- resources/lib/entrypoint.py | 4 ++-- resources/lib/initialsetup.py | 4 ++-- resources/lib/itemtypes.py | 5 ++--- resources/lib/json_rpc.py | 3 +++ resources/lib/kodidb_functions.py | 5 ++--- resources/lib/kodimonitor.py | 1 - resources/lib/playback_starter.py | 4 ++-- resources/lib/playbackutils.py | 5 ++--- resources/lib/player.py | 24 ++++++++++++------------ resources/lib/playlist_func.py | 4 ++-- resources/lib/playqueue.py | 4 ++-- resources/lib/playutils.py | 4 ++-- resources/lib/plexdb_functions.py | 4 ++-- resources/lib/userclient.py | 10 +++++----- resources/lib/utils.py | 4 ++-- resources/lib/videonodes.py | 4 ++-- resources/lib/websocket_client.py | 4 ++-- 23 files changed, 61 insertions(+), 65 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index da08ea42..3dc6887d 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -30,7 +30,7 @@ http://stackoverflow.com/questions/111945/is-there-any-way-to-do-http-put-in-pyt (and others...) """ -import logging +from logging import getLogger from time import time import urllib2 import socket @@ -57,7 +57,7 @@ import state ############################################################################### -log = logging.getLogger("PLEX." + __name__) +log = getLogger("PLEX." + __name__) REGEX_IMDB = re_compile(r'''/(tt\d+)''') REGEX_TVDB = re_compile(r'''thetvdb:\/\/(.+?)\?''') diff --git a/resources/lib/PlexCompanion.py b/resources/lib/PlexCompanion.py index 88e472b4..237515af 100644 --- a/resources/lib/PlexCompanion.py +++ b/resources/lib/PlexCompanion.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -import logging +from logging import getLogger from threading import Thread -import Queue +from Queue import Queue, Empty from socket import SHUT_RDWR from urllib import urlencode @@ -19,7 +19,7 @@ import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### @@ -39,7 +39,7 @@ class PlexCompanion(Thread): log.debug("Registration string is:\n%s" % self.client.getClientDetails()) # kodi player instance - self.player = player.Player() + self.player = player.PKC_Player() Thread.__init__(self) @@ -199,7 +199,7 @@ class PlexCompanion(Thread): subscriptionManager = subscribers.SubscriptionManager( requestMgr, self.player, self.mgr) - queue = Queue.Queue(maxsize=100) + queue = Queue(maxsize=100) self.queue = queue if settings('plexCompanion') == 'true': @@ -276,7 +276,7 @@ class PlexCompanion(Thread): # See if there's anything we need to process try: task = queue.get(block=False) - except Queue.Empty: + except Empty: pass else: # Got instructions, process them diff --git a/resources/lib/artwork.py b/resources/lib/artwork.py index b6306c70..f2dffc7b 100644 --- a/resources/lib/artwork.py +++ b/resources/lib/artwork.py @@ -2,11 +2,11 @@ ############################################################################### from logging import getLogger -import requests +from Queue import Queue, Empty from shutil import rmtree from urllib import quote_plus, unquote from threading import Thread -from Queue import Queue, Empty +import requests import json_rpc as js from xbmc import sleep, translatePath diff --git a/resources/lib/clientinfo.py b/resources/lib/clientinfo.py index 4a1da15d..694b0e02 100644 --- a/resources/lib/clientinfo.py +++ b/resources/lib/clientinfo.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger from utils import window, settings import variables as v ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/context_entry.py b/resources/lib/context_entry.py index b818b851..c3aa0598 100644 --- a/resources/lib/context_entry.py +++ b/resources/lib/context_entry.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- - ############################################################################### - import logging import xbmc diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 7178a09d..d7078fe0 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- ############################################################################### - -import logging -import requests +from logging import getLogger import xml.etree.ElementTree as etree +import requests from utils import settings, window, language as lang, dialog import clientinfo as client @@ -17,7 +16,7 @@ import state import requests.packages.urllib3 requests.packages.urllib3.disable_warnings() -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index c96b9935..a4913489 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger from shutil import copyfile from os import walk, makedirs from os.path import basename, join @@ -22,7 +22,7 @@ import json_rpc as js import variables as v ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) try: HANDLE = int(argv[1]) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 730517e9..d1eb38f7 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################### +from logging import getLogger -import logging import xbmc import xbmcgui @@ -18,7 +18,7 @@ from migration import check_migration ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 4347be0f..d48612ce 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### - -import logging +from logging import getLogger from urllib import urlencode from ntpath import dirname from datetime import datetime @@ -20,7 +19,7 @@ import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/json_rpc.py b/resources/lib/json_rpc.py index 9cb0d679..7667fc89 100644 --- a/resources/lib/json_rpc.py +++ b/resources/lib/json_rpc.py @@ -2,10 +2,13 @@ Collection of functions using the Kodi JSON RPC interface. See http://kodi.wiki/view/JSON-RPC_API """ +from logging import getLogger from json import loads, dumps from utils import millis_to_kodi_time from xbmc import executeJSONRPC +log = getLogger("PLEX."+__name__) + class jsonrpc(object): """ diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 5f289dac..6d31faa0 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### - -import logging +from logging import getLogger from ntpath import dirname import artwork @@ -11,7 +10,7 @@ import variables as v ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index a9933924..6bc0639a 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################### - from logging import getLogger from json import loads diff --git a/resources/lib/playback_starter.py b/resources/lib/playback_starter.py index 5abba986..c097c4ca 100644 --- a/resources/lib/playback_starter.py +++ b/resources/lib/playback_starter.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger from threading import Thread from urlparse import parse_qsl @@ -21,7 +21,7 @@ from context_entry import ContextMenu import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index b302a4a2..ea8e9e27 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### - -import logging +from logging import getLogger from urllib import urlencode from threading import Thread @@ -26,7 +25,7 @@ import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/player.py b/resources/lib/player.py index 4bb51a83..85d971d2 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging -import json +from logging import getLogger +from json import loads -import xbmc +from xbmc import Player, sleep from utils import window, DateToKodi, getUnixTimestamp, tryDecode, tryEncode import downloadutils @@ -16,12 +16,12 @@ import state ############################################################################### -LOG = logging.getLogger("PLEX." + __name__) +LOG = getLogger("PLEX." + __name__) ############################################################################### -class Player(xbmc.Player): +class PKC_Player(Player): played_info = state.PLAYED_INFO playStats = state.PLAYER_STATES @@ -29,7 +29,7 @@ class Player(xbmc.Player): def __init__(self): self.doUtils = downloadutils.DownloadUtils - xbmc.Player.__init__(self) + Player.__init__(self) LOG.info("Started playback monitor.") def onPlayBackStarted(self): @@ -42,12 +42,12 @@ class Player(xbmc.Player): # Get current file (in utf-8!) try: currentFile = tryDecode(self.getPlayingFile()) - xbmc.sleep(300) + sleep(300) except: currentFile = "" count = 0 while not currentFile: - xbmc.sleep(100) + sleep(100) try: currentFile = tryDecode(self.getPlayingFile()) except: @@ -67,7 +67,7 @@ class Player(xbmc.Player): itemId = window("plex_%s.itemid" % tryEncode(currentFile)) count = 0 while not itemId: - xbmc.sleep(200) + sleep(200) itemId = window("plex_%s.itemid" % tryEncode(currentFile)) if count == 5: LOG.warn("Could not find itemId, cancelling playback report!") @@ -142,17 +142,17 @@ class Player(xbmc.Player): postdata['AudioStreamIndex'] = indexAudio + 1 # Postdata for the subtitles - if subsEnabled and len(xbmc.Player().getAvailableSubtitleStreams()) > 0: + if subsEnabled and len(Player().getAvailableSubtitleStreams()) > 0: # Number of audiotracks to help get plex Index - audioTracks = len(xbmc.Player().getAvailableAudioStreams()) + audioTracks = len(Player().getAvailableAudioStreams()) mapping = window("%s.indexMapping" % plexitem) if mapping: # Set in playbackutils.py LOG.debug("Mapping for external subtitles index: %s" % mapping) - externalIndex = json.loads(mapping) + externalIndex = loads(mapping) if externalIndex.get(str(indexSubs)): # If the current subtitle is in the mapping diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index cb4a1883..e13a6a07 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -1,7 +1,7 @@ """ Collection of functions associated with Kodi and Plex playlists and playqueues """ -import logging +from logging import getLogger from urllib import quote from urlparse import parse_qsl, urlsplit from re import compile as re_compile @@ -15,7 +15,7 @@ import json_rpc as js ############################################################################### -LOG = logging.getLogger("PLEX." + __name__) +LOG = getLogger("PLEX." + __name__) REGEX = re_compile(r'''metadata%2F(\d+)''') ############################################################################### diff --git a/resources/lib/playqueue.py b/resources/lib/playqueue.py index 4203349d..cf6a5250 100644 --- a/resources/lib/playqueue.py +++ b/resources/lib/playqueue.py @@ -1,7 +1,7 @@ """ Monitors the Kodi playqueue and adjusts the Plex playqueue accordingly """ -import logging +from logging import getLogger from threading import RLock, Thread from xbmc import sleep, Player, PlayList, PLAYLIST_MUSIC, PLAYLIST_VIDEO @@ -15,7 +15,7 @@ import json_rpc as js import variables as v ############################################################################### -LOG = logging.getLogger("PLEX." + __name__) +LOG = getLogger("PLEX." + __name__) # lock used for playqueue manipulations LOCK = RLock() diff --git a/resources/lib/playutils.py b/resources/lib/playutils.py index 3e268957..97ce2322 100644 --- a/resources/lib/playutils.py +++ b/resources/lib/playutils.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger from downloadutils import DownloadUtils from utils import window, settings, tryEncode, language as lang, dialog @@ -10,7 +10,7 @@ import PlexAPI ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/plexdb_functions.py b/resources/lib/plexdb_functions.py index 1fdbe07d..a08e0d40 100644 --- a/resources/lib/plexdb_functions.py +++ b/resources/lib/plexdb_functions.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- ############################################################################### +from logging import getLogger from utils import kodiSQL -import logging import variables as v ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index f9671263..17104d63 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging -import threading +from logging import getLogger +from threading import Thread import xbmc import xbmcgui @@ -19,13 +19,13 @@ import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### @thread_methods(add_suspends=['SUSPEND_USER_CLIENT']) -class UserClient(threading.Thread): +class UserClient(Thread): # Borg - multiple instances, shared state __shared_state = {} @@ -49,7 +49,7 @@ class UserClient(threading.Thread): self.addon = xbmcaddon.Addon() self.doUtils = downloadutils.DownloadUtils() - threading.Thread.__init__(self) + Thread.__init__(self) def getUsername(self): """ diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 9ccc80b9..fb24f0bb 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger from cProfile import Profile from pstats import Stats from sqlite3 import connect, OperationalError @@ -28,7 +28,7 @@ import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) WINDOW = xbmcgui.Window(10000) ADDON = xbmcaddon.Addon(id='plugin.video.plexkodiconnect') diff --git a/resources/lib/videonodes.py b/resources/lib/videonodes.py index 9f526175..659894e5 100644 --- a/resources/lib/videonodes.py +++ b/resources/lib/videonodes.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger from shutil import copytree import xml.etree.ElementTree as etree from os import makedirs @@ -14,7 +14,7 @@ import variables as v ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ############################################################################### # Paths are strings, NOT unicode! diff --git a/resources/lib/websocket_client.py b/resources/lib/websocket_client.py index 5a4466d9..aeb3385c 100644 --- a/resources/lib/websocket_client.py +++ b/resources/lib/websocket_client.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################### -import logging +from logging import getLogger import websocket from json import loads import xml.etree.ElementTree as etree @@ -17,7 +17,7 @@ import state ############################################################################### -log = logging.getLogger("PLEX."+__name__) +log = getLogger("PLEX."+__name__) ###############################################################################