Centralized Logging

This commit is contained in:
angelblue05 2016-06-16 16:24:07 -05:00
parent e7bdfacd47
commit 9314c4a363
5 changed files with 67 additions and 81 deletions

View file

@ -279,7 +279,7 @@ class Artwork():
# add a new thread or wait and retry if we hit our limit # add a new thread or wait and retry if we hit our limit
if len(self.imageCacheThreads) < self.imageCacheLimitThreads: if len(self.imageCacheThreads) < self.imageCacheLimitThreads:
newThread = image_cache_thread.image_cache_thread() newThread = image_cache_thread.image_cache_thread()
newThread.setUrl(self.double_urlencode(urlToAdd)) newThread.setUrl(self.double_urlencode(url))
newThread.setHost(self.xbmc_host, self.xbmc_port) newThread.setHost(self.xbmc_host, self.xbmc_port)
newThread.setAuth(self.xbmc_username, self.xbmc_password) newThread.setAuth(self.xbmc_username, self.xbmc_password)
newThread.start() newThread.start()
@ -519,7 +519,7 @@ class Artwork():
% (self.server, item_id, item_type)) % (self.server, item_id, item_type))
return image return image
def getAllArtwork(self, item, parent_artwork=False): def getAllArtwork(self, item, parentInfo=False):
itemid = item['Id'] itemid = item['Id']
artworks = item['ImageTags'] artworks = item['ImageTags']
@ -566,7 +566,7 @@ class Artwork():
allartworks[art] = artwork allartworks[art] = artwork
# Process parent items if the main item is missing artwork # Process parent items if the main item is missing artwork
if parent_artwork: if parentInfo:
# Process parent backdrops # Process parent backdrops
if not allartworks['Backdrop']: if not allartworks['Backdrop']:

View file

@ -9,7 +9,7 @@ import xbmc
import xbmcaddon import xbmcaddon
import xbmcvfs import xbmcvfs
import utils from utils import Logging, window, settings
################################################################################################# #################################################################################################
@ -19,14 +19,12 @@ class ClientInfo():
def __init__(self): def __init__(self):
global log
log = Logging(self.__class__.__name__).log
self.addon = xbmcaddon.Addon() self.addon = xbmcaddon.Addon()
self.addonName = self.getAddonName() self.addonName = self.getAddonName()
def logMsg(self, msg, lvl=1):
className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, className), msg, lvl)
def getAddonName(self): def getAddonName(self):
# Used for logging # Used for logging
@ -42,11 +40,11 @@ class ClientInfo():
def getDeviceName(self): def getDeviceName(self):
if utils.settings('deviceNameOpt') == "false": if settings('deviceNameOpt') == "false":
# Use Kodi's deviceName # Use Kodi's deviceName
deviceName = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8') deviceName = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8')
else: else:
deviceName = utils.settings('deviceName') deviceName = settings('deviceName')
deviceName = deviceName.replace("\"", "_") deviceName = deviceName.replace("\"", "_")
deviceName = deviceName.replace("/", "_") deviceName = deviceName.replace("/", "_")
@ -71,15 +69,17 @@ class ClientInfo():
def getDeviceId(self, reset=False): def getDeviceId(self, reset=False):
clientId = utils.window('emby_deviceId') clientId = window('emby_deviceId')
if clientId: if clientId:
return clientId return clientId
addon_path = self.addon.getAddonInfo('path').decode('utf-8') addon_path = self.addon.getAddonInfo('path').decode('utf-8')
if os.path.supports_unicode_filenames: if os.path.supports_unicode_filenames:
GUID_file = xbmc.translatePath(os.path.join(addon_path, "machine_guid")).decode('utf-8') path = os.path.join(addon_path, "machine_guid")
else: else:
GUID_file = xbmc.translatePath(os.path.join(addon_path.encode("utf-8"), "machine_guid")).decode('utf-8') path = os.path.join(addon_path.encode('utf-8'), "machine_guid")
GUID_file = xbmc.translatePath(path).decode('utf-8')
if reset and xbmcvfs.exists(GUID_file): if reset and xbmcvfs.exists(GUID_file):
# Reset the file # Reset the file
@ -88,14 +88,14 @@ class ClientInfo():
GUID = xbmcvfs.File(GUID_file) GUID = xbmcvfs.File(GUID_file)
clientId = GUID.read() clientId = GUID.read()
if not clientId: if not clientId:
self.logMsg("Generating a new deviceid...", 1) log("Generating a new deviceid...", 1)
clientId = str("%012X" % uuid4()) clientId = str("%012X" % uuid4())
GUID = xbmcvfs.File(GUID_file, 'w') GUID = xbmcvfs.File(GUID_file, 'w')
GUID.write(clientId) GUID.write(clientId)
GUID.close() GUID.close()
self.logMsg("DeviceId loaded: %s" % clientId, 1) log("DeviceId loaded: %s" % clientId, 1)
utils.window('emby_deviceId', value=clientId) window('emby_deviceId', value=clientId)
return clientId return clientId

View file

@ -271,7 +271,7 @@ class PlaybackUtils():
def setArtwork(self, listItem): def setArtwork(self, listItem):
# Set up item and item info # Set up item and item info
allartwork = self.artwork.getAllArtwork(self.item, parent_artwork=True) allartwork = self.artwork.getAllArtwork(self.item, parentInfo=True)
# Set artwork for listitem # Set artwork for listitem
arttypes = { arttypes = {

View file

@ -13,7 +13,7 @@ import playutils
import playbackutils import playbackutils
import embydb_functions as embydb import embydb_functions as embydb
import read_embyserver as embyserver import read_embyserver as embyserver
import utils from utils import Logging, window, settings, language as lang, kodiSQL
################################################################################################# #################################################################################################
@ -23,25 +23,21 @@ class Playlist():
def __init__(self): def __init__(self):
global log
log = Logging(self.__class__.__name__).log
self.clientInfo = clientinfo.ClientInfo() self.clientInfo = clientinfo.ClientInfo()
self.addonName = self.clientInfo.getAddonName() self.addonName = self.clientInfo.getAddonName()
self.userid = utils.window('emby_currUser') self.userid = window('emby_currUser')
self.server = utils.window('emby_server%s' % self.userid) self.server = window('emby_server%s' % self.userid)
self.emby = embyserver.Read_EmbyServer() self.emby = embyserver.Read_EmbyServer()
def logMsg(self, msg, lvl=1):
self.className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, self.className), msg, lvl)
def playAll(self, itemids, startat): def playAll(self, itemids, startat):
window = utils.window embyconn = kodiSQL('emby')
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor() embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor) emby_db = embydb.Embydb_Functions(embycursor)
@ -49,8 +45,8 @@ class Playlist():
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear() playlist.clear()
self.logMsg("---*** PLAY ALL ***---", 1) log("---*** PLAY ALL ***---", 1)
self.logMsg("Items: %s and start at: %s" % (itemids, startat), 1) log("Items: %s and start at: %s" % (itemids, startat), 1)
started = False started = False
window('emby_customplaylist', value="true") window('emby_customplaylist', value="true")
@ -66,14 +62,14 @@ class Playlist():
mediatype = embydb_item[4] mediatype = embydb_item[4]
except TypeError: except TypeError:
# Item is not found in our database, add item manually # Item is not found in our database, add item manually
self.logMsg("Item was not found in the database, manually adding item.", 1) log("Item was not found in the database, manually adding item.", 1)
item = self.emby.getItem(itemid) item = self.emby.getItem(itemid)
self.addtoPlaylist_xbmc(playlist, item) self.addtoPlaylist_xbmc(playlist, item)
else: else:
# Add to playlist # Add to playlist
self.addtoPlaylist(dbid, mediatype) self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1) log("Adding %s to playlist." % itemid, 1)
if not started: if not started:
started = True started = True
@ -84,12 +80,12 @@ class Playlist():
def modifyPlaylist(self, itemids): def modifyPlaylist(self, itemids):
embyconn = utils.kodiSQL('emby') embyconn = kodiSQL('emby')
embycursor = embyconn.cursor() embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor) emby_db = embydb.Embydb_Functions(embycursor)
self.logMsg("---*** ADD TO PLAYLIST ***---", 1) log("---*** ADD TO PLAYLIST ***---", 1)
self.logMsg("Items: %s" % itemids, 1) log("Items: %s" % itemids, 1)
player = xbmc.Player() player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
@ -107,7 +103,7 @@ class Playlist():
# Add to playlist # Add to playlist
self.addtoPlaylist(dbid, mediatype) self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1) log("Adding %s to playlist." % itemid, 1)
self.verifyPlaylist() self.verifyPlaylist()
embycursor.close() embycursor.close()
@ -130,17 +126,17 @@ class Playlist():
else: else:
pl['params']['item'] = {'file': url} pl['params']['item'] = {'file': url}
self.logMsg(xbmc.executeJSONRPC(json.dumps(pl)), 2) log(xbmc.executeJSONRPC(json.dumps(pl)), 2)
def addtoPlaylist_xbmc(self, playlist, item): def addtoPlaylist_xbmc(self, playlist, item):
playurl = playutils.PlayUtils(item).getPlayUrl() playurl = playutils.PlayUtils(item).getPlayUrl()
if not playurl: if not playurl:
# Playurl failed # Playurl failed
self.logMsg("Failed to retrieve playurl.", 1) log("Failed to retrieve playurl.", 1)
return return
self.logMsg("Playurl: %s" % playurl) log("Playurl: %s" % playurl)
listitem = xbmcgui.ListItem() listitem = xbmcgui.ListItem()
playbackutils.PlaybackUtils(item).setProperties(playurl, listitem) playbackutils.PlaybackUtils(item).setProperties(playurl, listitem)
@ -164,7 +160,7 @@ class Playlist():
else: else:
pl['params']['item'] = {'file': url} pl['params']['item'] = {'file': url}
self.logMsg(xbmc.executeJSONRPC(json.dumps(pl)), 2) log(xbmc.executeJSONRPC(json.dumps(pl)), 2)
def verifyPlaylist(self): def verifyPlaylist(self):
@ -178,7 +174,7 @@ class Playlist():
'playlistid': 1 'playlistid': 1
} }
} }
self.logMsg(xbmc.executeJSONRPC(json.dumps(pl)), 2) log(xbmc.executeJSONRPC(json.dumps(pl)), 2)
def removefromPlaylist(self, position): def removefromPlaylist(self, position):
@ -193,4 +189,4 @@ class Playlist():
'position': position 'position': position
} }
} }
self.logMsg(xbmc.executeJSONRPC(json.dumps(pl)), 2) log(xbmc.executeJSONRPC(json.dumps(pl)), 2)

View file

@ -7,7 +7,7 @@ import xbmcgui
import xbmcvfs import xbmcvfs
import clientinfo import clientinfo
import utils from utils import Logging, window, settings, language as lang
################################################################################################# #################################################################################################
@ -17,41 +17,37 @@ class PlayUtils():
def __init__(self, item): def __init__(self, item):
global log
log = Logging(self.__class__.__name__).log
self.item = item self.item = item
self.clientInfo = clientinfo.ClientInfo() self.clientInfo = clientinfo.ClientInfo()
self.addonName = self.clientInfo.getAddonName() self.addonName = self.clientInfo.getAddonName()
self.userid = utils.window('emby_currUser') self.userid = window('emby_currUser')
self.server = utils.window('emby_server%s' % self.userid) self.server = window('emby_server%s' % self.userid)
def logMsg(self, msg, lvl=1):
self.className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, self.className), msg, lvl)
def getPlayUrl(self): def getPlayUrl(self):
window = utils.window
playurl = None playurl = None
if (self.item.get('Type') in ("Recording", "TvChannel") and if (self.item.get('Type') in ("Recording", "TvChannel") and self.item.get('MediaSources')
self.item.get('MediaSources') and self.item['MediaSources'][0]['Protocol'] == "Http"): and self.item['MediaSources'][0]['Protocol'] == "Http"):
# Play LiveTV or recordings # Play LiveTV or recordings
self.logMsg("File protocol is http (livetv).", 1) log("File protocol is http (livetv).", 1)
playurl = "%s/emby/Videos/%s/live.m3u8?static=true" % (self.server, self.item['Id']) playurl = "%s/emby/Videos/%s/live.m3u8?static=true" % (self.server, self.item['Id'])
window('emby_%s.playmethod' % playurl, value="Transcode") window('emby_%s.playmethod' % playurl, value="Transcode")
elif self.item.get('MediaSources') and self.item['MediaSources'][0]['Protocol'] == "Http": elif self.item.get('MediaSources') and self.item['MediaSources'][0]['Protocol'] == "Http":
# Only play as http, used for channels, or online hosting of content # Only play as http, used for channels, or online hosting of content
self.logMsg("File protocol is http.", 1) log("File protocol is http.", 1)
playurl = self.httpPlay() playurl = self.httpPlay()
window('emby_%s.playmethod' % playurl, value="DirectStream") window('emby_%s.playmethod' % playurl, value="DirectStream")
elif self.isDirectPlay(): elif self.isDirectPlay():
self.logMsg("File is direct playing.", 1) log("File is direct playing.", 1)
playurl = self.directPlay() playurl = self.directPlay()
playurl = playurl.encode('utf-8') playurl = playurl.encode('utf-8')
# Set playmethod property # Set playmethod property
@ -59,14 +55,14 @@ class PlayUtils():
elif self.isDirectStream(): elif self.isDirectStream():
self.logMsg("File is direct streaming.", 1) log("File is direct streaming.", 1)
playurl = self.directStream() playurl = self.directStream()
# Set playmethod property # Set playmethod property
window('emby_%s.playmethod' % playurl, value="DirectStream") window('emby_%s.playmethod' % playurl, value="DirectStream")
elif self.isTranscoding(): elif self.isTranscoding():
self.logMsg("File is transcoding.", 1) log("File is transcoding.", 1)
playurl = self.transcoding() playurl = self.transcoding()
# Set playmethod property # Set playmethod property
window('emby_%s.playmethod' % playurl, value="Transcode") window('emby_%s.playmethod' % playurl, value="Transcode")
@ -88,21 +84,18 @@ class PlayUtils():
def isDirectPlay(self): def isDirectPlay(self):
lang = utils.language
settings = utils.settings
dialog = xbmcgui.Dialog() dialog = xbmcgui.Dialog()
# Requirement: Filesystem, Accessible path # Requirement: Filesystem, Accessible path
if settings('playFromStream') == "true": if settings('playFromStream') == "true":
# User forcing to play via HTTP # User forcing to play via HTTP
self.logMsg("Can't direct play, play from HTTP enabled.", 1) log("Can't direct play, play from HTTP enabled.", 1)
return False return False
videotrack = self.item['MediaSources'][0]['Name'] videotrack = self.item['MediaSources'][0]['Name']
transcodeH265 = settings('transcodeH265') transcodeH265 = settings('transcodeH265')
videoprofiles = [x['Profile'] for x in self.item['MediaSources'][0]['MediaStreams'] if 'Profile' in x] videoprofiles = [x['Profile'] for x in self.item['MediaSources'][0]['MediaStreams'] if 'Profile' in x]
transcodeHi10P = utils.settings('transcodeHi10P') transcodeHi10P = settings('transcodeHi10P')
if transcodeHi10P == "true" and "H264" in videotrack and "High 10" in videoprofiles: if transcodeHi10P == "true" and "H264" in videotrack and "High 10" in videoprofiles:
return False return False
@ -116,7 +109,7 @@ class PlayUtils():
'2': 720, '2': 720,
'3': 1080 '3': 1080
} }
self.logMsg("Resolution is: %sP, transcode for resolution: %sP+" log("Resolution is: %sP, transcode for resolution: %sP+"
% (resolution, res[transcodeH265]), 1) % (resolution, res[transcodeH265]), 1)
if res[transcodeH265] <= resolution: if res[transcodeH265] <= resolution:
return False return False
@ -124,19 +117,19 @@ class PlayUtils():
canDirectPlay = self.item['MediaSources'][0]['SupportsDirectPlay'] canDirectPlay = self.item['MediaSources'][0]['SupportsDirectPlay']
# Make sure direct play is supported by the server # Make sure direct play is supported by the server
if not canDirectPlay: if not canDirectPlay:
self.logMsg("Can't direct play, server doesn't allow/support it.", 1) log("Can't direct play, server doesn't allow/support it.", 1)
return False return False
location = self.item['LocationType'] location = self.item['LocationType']
if location == "FileSystem": if location == "FileSystem":
# Verify the path # Verify the path
if not self.fileExists(): if not self.fileExists():
self.logMsg("Unable to direct play.") log("Unable to direct play.", 1)
try: try:
count = int(settings('failCount')) count = int(settings('failCount'))
except ValueError: except ValueError:
count = 0 count = 0
self.logMsg("Direct play failed: %s times." % count, 1) log("Direct play failed: %s times." % count, 1)
if count < 2: if count < 2:
# Let the user know that direct play failed # Let the user know that direct play failed
@ -192,23 +185,22 @@ class PlayUtils():
# Convert path to direct play # Convert path to direct play
path = self.directPlay() path = self.directPlay()
self.logMsg("Verifying path: %s" % path, 1) log("Verifying path: %s" % path, 1)
if xbmcvfs.exists(path): if xbmcvfs.exists(path):
self.logMsg("Path exists.", 1) log("Path exists.", 1)
return True return True
elif ":" not in path: elif ":" not in path:
self.logMsg("Can't verify path, assumed linux. Still try to direct play.", 1) log("Can't verify path, assumed linux. Still try to direct play.", 1)
return True return True
else: else:
self.logMsg("Failed to find file.", 1) log("Failed to find file.", 1)
return False return False
def isDirectStream(self): def isDirectStream(self):
videotrack = self.item['MediaSources'][0]['Name'] videotrack = self.item['MediaSources'][0]['Name']
transcodeH265 = utils.settings('transcodeH265') transcodeH265 = utils.settings('transcodeH265')
videoprofiles = [x['Profile'] for x in self.item['MediaSources'][0]['MediaStreams'] if 'Profile' in x] videoprofiles = [x['Profile'] for x in self.item['MediaSources'][0]['MediaStreams'] if 'Profile' in x]
@ -226,7 +218,7 @@ class PlayUtils():
'2': 720, '2': 720,
'3': 1080 '3': 1080
} }
self.logMsg("Resolution is: %sP, transcode for resolution: %sP+" log("Resolution is: %sP, transcode for resolution: %sP+"
% (resolution, res[transcodeH265]), 1) % (resolution, res[transcodeH265]), 1)
if res[transcodeH265] <= resolution: if res[transcodeH265] <= resolution:
return False return False
@ -239,7 +231,7 @@ class PlayUtils():
# Verify the bitrate # Verify the bitrate
if not self.isNetworkSufficient(): if not self.isNetworkSufficient():
self.logMsg("The network speed is insufficient to direct stream file.", 1) log("The network speed is insufficient to direct stream file.", 1)
return False return False
return True return True
@ -258,15 +250,14 @@ class PlayUtils():
def isNetworkSufficient(self): def isNetworkSufficient(self):
settings = self.getBitrate()*1000 settings = self.getBitrate()*1000
try: try:
sourceBitrate = int(self.item['MediaSources'][0]['Bitrate']) sourceBitrate = int(self.item['MediaSources'][0]['Bitrate'])
except (KeyError, TypeError): except (KeyError, TypeError):
self.logMsg("Bitrate value is missing.", 1) log("Bitrate value is missing.", 1)
else: else:
self.logMsg("The add-on settings bitrate is: %s, the video bitrate required is: %s" log("The add-on settings bitrate is: %s, the video bitrate required is: %s"
% (settings, sourceBitrate), 1) % (settings, sourceBitrate), 1)
if settings < sourceBitrate: if settings < sourceBitrate:
return False return False
@ -329,7 +320,6 @@ class PlayUtils():
def audioSubsPref(self, url, listitem): def audioSubsPref(self, url, listitem):
lang = utils.language
dialog = xbmcgui.Dialog() dialog = xbmcgui.Dialog()
# For transcoding only # For transcoding only
# Present the list of audio to select from # Present the list of audio to select from