add library monitor to assist with embyskinhelper for data such as critcrating etc

This commit is contained in:
im85288 2015-09-15 18:03:52 +01:00
parent 0546dcc2f6
commit 0a6dd94eff
7 changed files with 159 additions and 10 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.emby"
name="Emby"
version="1.1.39"
version="1.1.40"
provider-name="Emby.media">
<requires>
<import addon="xbmc.python" version="2.1.0"/>

View file

@ -0,0 +1,89 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from traceback import print_exc
import xbmc
import xbmcgui
import threading
import Utils as utils
from ReadKodiDB import ReadKodiDB
from ClientInformation import ClientInformation
class LibraryMonitor(threading.Thread):
event = None
exit = False
liPath = None
liPathLast = None
WINDOW = xbmcgui.Window(10000)
clientInfo = ClientInformation()
addonName = clientInfo.getAddonName()
def __init__(self, *args):
self.event = threading.Event()
threading.Thread.__init__(self, *args)
def logMsg(self, msg, lvl=1):
className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, className), msg, int(lvl))
def stop(self):
self.logMsg("LibraryMonitor - stop called",0)
self.exit = True
self.event.set()
def run(self):
self.logMsg("LIBRARY MONITOR running ")
WINDOW = self.WINDOW
lastListItemLabel = None
while (self.exit != True):
# monitor listitem props when videolibrary is active
if (xbmc.getCondVisibility("[Window.IsActive(videolibrary) | Window.IsActive(movieinformation)] + !Window.IsActive(fullscreenvideo)")):
self.liPath = xbmc.getInfoLabel("ListItem.Path")
liLabel = xbmc.getInfoLabel("ListItem.Label")
if ((liLabel != lastListItemLabel) and xbmc.getCondVisibility("!Container.Scrolling")):
self.liPathLast = self.liPath
lastListItemLabel = liLabel
# update the listitem stuff
try:
self.setRatingsInfo()
except Exception as e:
self.logMsg("ERROR in LibraryMonitor ! --> " + str(e), 0)
else:
#reset window props
WINDOW.clearProperty("EmbySkinHelper.ListItemRottenTomatoes")
WINDOW.clearProperty('EmbySkinHelper.ListItemRottenTomatoesSummary')
WINDOW.clearProperty('EmbySkinHelper.ListItemMetaScore')
xbmc.sleep(150)
def setRatingsInfo(self):
WINDOW = self.WINDOW
embyId = self.liPath.split("/")[-2]
criticrating = ReadKodiDB().getCriticRatingByEmbyId(embyId)
if criticrating:
WINDOW.setProperty('EmbySkinHelper.ListItemRottenTomatoes', criticrating)
else:
WINDOW.clearProperty('EmbySkinHelper.ListItemRottenTomatoes')
criticratingsummary = ReadKodiDB().getCriticRatingSummaryByEmbyId(embyId)
if criticratingsummary:
WINDOW.setProperty('EmbySkinHelper.ListItemRottenTomatoesSummary', criticratingsummary)
else:
WINDOW.clearProperty('EmbySkinHelper.ListItemRottenTomatoesSummary')
metascore = ReadKodiDB().getMetaScoreRatingByEmbyId(embyId)
if metascore:
WINDOW.setProperty('EmbySkinHelper.ListItemMetaScore', metascore)
else:
WINDOW.clearProperty('EmbySkinHelper.ListItemMetaScore')

View file

@ -137,9 +137,12 @@ class LibrarySync(threading.Thread):
cursor = connection.cursor()
#Add the special emby table
cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER, kodi_file_id INTEGER)")
cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER, kodi_file_id INTEGER, rotten_tomatoes TEXT, rotten_tomatoes_summary TEXT, metascore TEXT)")
try:
cursor.execute("ALTER TABLE emby ADD COLUMN kodi_file_id INTEGER")
cursor.execute("ALTER TABLE emby ADD COLUMN rotten_tomatoes TEXT")
cursor.execute("ALTER TABLE emby ADD COLUMN rotten_tomatoes_summary TEXT")
cursor.execute("ALTER TABLE emby ADD COLUMN metascore TEXT")
except: pass
connection.commit()

View file

@ -269,7 +269,7 @@ class ReadEmbyDB():
def getFullItem(self, id):
result = {}
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview" % id
url = "{server}/mediabrowser/Users/{UserId}/Items/%s?format=json&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview,CriticRating,CriticRatingSummary" % id
jsondata = self.doUtils.downloadUrl(url)
if jsondata:

View file

@ -129,4 +129,52 @@ class ReadKodiDB():
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='song'")
allsongs = cursor.fetchall()
#this will return a list with tuples of all items returned from the database
return allsongs
return allsongs
def getCriticRatingByEmbyId(self, id, connection=None, cursor=None):
if not connection:
connection = utils.KodiSQL()
cursor = connection.cursor()
closeCon = True
else:
closeCon = False
cursor.execute("SELECT rotten_tomatoes FROM emby WHERE emby_id=?",(id,))
result = cursor.fetchone()
if closeCon:
connection.close()
if result:
return result[0]
else:
return None
def getCriticRatingSummaryByEmbyId(self, id, connection=None, cursor=None):
if not connection:
connection = utils.KodiSQL()
cursor = connection.cursor()
closeCon = True
else:
closeCon = False
cursor.execute("SELECT rotten_tomatoes_summary FROM emby WHERE emby_id=?",(id,))
result = cursor.fetchone()
if closeCon:
connection.close()
if result:
return result[0]
else:
return None
def getMetaScoreRatingByEmbyId(self, id, connection=None, cursor=None):
if not connection:
connection = utils.KodiSQL()
cursor = connection.cursor()
closeCon = True
else:
closeCon = False
cursor.execute("SELECT metascore FROM emby WHERE emby_id=?",(id,))
result = cursor.fetchone()
if closeCon:
connection.close()
if result:
return result[0]
else:
return None

View file

@ -107,6 +107,9 @@ class WriteKodiVideoDB():
tagline = API().getTagline(MBitem)
votecount = MBitem.get('VoteCount')
rating = MBitem.get('CommunityRating')
criticrating = MBitem.get('CriticRating')
criticratingsummary = MBitem.get('CriticRatingSummary')
metascorerating = MBitem.get('Metascore')
writer = " / ".join(people.get('Writer'))
year = MBitem.get('ProductionYear')
imdb = API().getProvider(MBitem, "imdb")
@ -177,9 +180,9 @@ class WriteKodiVideoDB():
query = "UPDATE movie SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ? WHERE idMovie = ?"
cursor.execute(query, (title, plot, shortplot, tagline, votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailerUrl, country, movieid))
# Update the checksum in emby table
query = "UPDATE emby SET checksum = ? WHERE emby_id = ?"
cursor.execute(query, (checksum, embyId))
# Update the checksum in emby table and critic ratings
query = "UPDATE emby SET checksum = ?, rotten_tomatoes = ?, rotten_tomatoes_summary = ?, metascore = ? WHERE emby_id = ?"
cursor.execute(query, (checksum, criticrating, criticratingsummary, metascorerating, embyId))
##### OR ADD THE MOVIE #####
else:
@ -220,8 +223,8 @@ class WriteKodiVideoDB():
self.AddTagToMedia(movieid, viewTag, "movie", cursor)
# Create the reference in emby table
query = "INSERT INTO emby(emby_id, kodi_id, kodi_file_id, media_type, checksum) values(?, ?, ?, ?, ?)"
cursor.execute(query, (embyId, movieid, fileid, "movie", checksum))
query = "INSERT INTO emby(emby_id, kodi_id, kodi_file_id, media_type, checksum, rotten_tomatoes, rotten_tomatoes_summary, metascore) values(?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(query, (embyId, movieid, fileid, "movie", checksum, criticrating, criticratingsummary, metascorerating))
# Update or insert actors

View file

@ -23,7 +23,7 @@ from UserClient import UserClient
from Player import Player
from WebSocketClient import WebSocketThread
from LibrarySync import LibrarySync
from LibraryMonitor import LibraryMonitor
class Service():
@ -103,6 +103,9 @@ class Service():
player = Player()
ws = WebSocketThread()
library = LibrarySync()
librarymonitor = LibraryMonitor()
xbmc.log("START LIBRARY MONITOR")
librarymonitor.start()
# Sync and progress report
lastProgressUpdate = datetime.today()
@ -264,6 +267,9 @@ class Service():
if (self.newUserClient is not None):
user.stopClient()
xbmc.log("STOP LIBRARY MONITOR")
librarymonitor.stop()
self.logMsg("======== STOP %s ========" % self.addonName, 0)
#start the service