Fix userratings for Kodi Krypton

This commit is contained in:
tomkat83 2017-02-02 15:23:54 +01:00
parent 15a39f9e64
commit 1343edc0d0
2 changed files with 100 additions and 89 deletions

View file

@ -1245,33 +1245,28 @@ class API():
item = self.item.attrib item = self.item.attrib
# Default - attributes not found with Plex # Default - attributes not found with Plex
favorite = False favorite = False
try: try:
playcount = int(item['viewCount']) playcount = int(item['viewCount'])
except: except KeyError:
playcount = None playcount = None
played = True if playcount else False
if playcount:
played = True
else:
played = False
try: try:
lastPlayedDate = DateToKodi(int(item['lastViewedAt'])) lastPlayedDate = DateToKodi(int(item['lastViewedAt']))
except: except KeyError:
lastPlayedDate = None lastPlayedDate = None
try: try:
userrating = float(item['userRating']) userrating = int(float(item['userRating']))
except: except KeyError:
userrating = 0.0 userrating = 0
try: try:
rating = float(item['audienceRating']) rating = float(item['audienceRating'])
except: except KeyError:
try: try:
rating = float(item['rating']) rating = float(item['rating'])
except: except KeyError:
rating = 0.0 rating = 0.0
resume, runtime = self.getRuntime() resume, runtime = self.getRuntime()

View file

@ -306,7 +306,6 @@ class Movies(Items):
if update_item: if update_item:
log.info("UPDATE movie itemid: %s - Title: %s" log.info("UPDATE movie itemid: %s - Title: %s"
% (itemid, title)) % (itemid, title))
# Update the movie entry # Update the movie entry
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
# update new ratings Kodi 17 # update new ratings Kodi 17
@ -324,79 +323,71 @@ class Movies(Items):
imdb, imdb,
"imdb", "imdb",
uniqueid) uniqueid)
query = '''
query = ' '.join(( UPDATE movie
"UPDATE movie", SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?,
"SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?," c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?,
"c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?," c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?,
"c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?," c22 = ?, c23 = ?, idFile=?, premiered = ?,
"c22 = ?, c23 = ?, idFile=?, premiered = ?", userrating = ?
"WHERE idMovie = ?" WHERE idMovie = ?
)) '''
kodicursor.execute(query, (title, plot, shortplot, tagline, kodicursor.execute(query, (title, plot, shortplot, tagline,
votecount, rating, writer, year, imdb, sorttitle, runtime, votecount, rating, writer, year, imdb, sorttitle, runtime,
mpaa, genre, director, title, studio, trailer, country, mpaa, genre, director, title, studio, trailer, country,
playurl, pathid, fileid, year, movieid)) playurl, pathid, fileid, year, userdata['UserRating'],
movieid))
else: else:
query = ' '.join(( query = '''
"UPDATE movie", UPDATE movie
"SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?," SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?,
"c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?," c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?,
"c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?," c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?,
"c22 = ?, c23 = ?, idFile=?", c22 = ?, c23 = ?, idFile=?
"WHERE idMovie = ?" WHERE idMovie = ?
)) '''
kodicursor.execute(query, (title, plot, shortplot, tagline, kodicursor.execute(query, (title, plot, shortplot, tagline,
votecount, rating, writer, year, imdb, sorttitle, runtime, votecount, rating, writer, year, imdb, sorttitle, runtime,
mpaa, genre, director, title, studio, trailer, country, mpaa, genre, director, title, studio, trailer, country,
playurl, pathid, fileid, movieid)) playurl, pathid, fileid, movieid))
# OR ADD THE MOVIE #####
##### OR ADD THE MOVIE #####
else: else:
log.info("ADD movie itemid: %s - Title: %s" % (itemid, title)) log.info("ADD movie itemid: %s - Title: %s" % (itemid, title))
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
# add new ratings Kodi 17 # add new ratings Kodi 17
ratingid = self.kodi_db.create_entry_rating() self.kodi_db.add_ratings(self.kodi_db.create_entry_rating(),
self.kodi_db.add_ratings(ratingid,
movieid, movieid,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
"default", "default",
rating, rating,
votecount) votecount)
# add new uniqueid Kodi 17 # add new uniqueid Kodi 17
uniqueid = self.kodi_db.create_entry_uniqueid() self.kodi_db.add_uniqueid(self.kodi_db.create_entry_uniqueid(),
self.kodi_db.add_uniqueid(uniqueid,
movieid, movieid,
v.KODI_TYPE_MOVIE, v.KODI_TYPE_MOVIE,
imdb, imdb,
"imdb") "imdb")
query = '''
query = ( INSERT INTO movie(idMovie, idFile, c00, c01, c02, c03,
'''
INSERT INTO movie( idMovie, idFile, c00, c01, c02, c03,
c04, c05, c06, c07, c09, c10, c11, c12, c14, c15, c16, c04, c05, c06, c07, c09, c10, c11, c12, c14, c15, c16,
c18, c19, c21, c22, c23, premiered) c18, c19, c21, c22, c23, premiered, userrating)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?) ?, ?, ?, ?, ?, ?, ?)
''' '''
)
kodicursor.execute(query, (movieid, fileid, title, plot, kodicursor.execute(query, (movieid, fileid, title, plot,
shortplot, tagline, votecount, rating, writer, year, imdb, shortplot, tagline, votecount, rating, writer, year, imdb,
sorttitle, runtime, mpaa, genre, director, title, studio, sorttitle, runtime, mpaa, genre, director, title, studio,
trailer, country, playurl, pathid, year)) trailer, country, playurl, pathid, year,
userdata['UserRating']))
else: else:
query = ( query = '''
''' INSERT INTO movie(idMovie, idFile, c00, c01, c02, c03,
INSERT INTO movie( idMovie, idFile, c00, c01, c02, c03,
c04, c05, c06, c07, c09, c10, c11, c12, c14, c15, c16, c04, c05, c06, c07, c09, c10, c11, c12, c14, c15, c16,
c18, c19, c21, c22, c23) c18, c19, c21, c22, c23)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?) ?, ?, ?, ?, ?)
''' '''
)
kodicursor.execute(query, (movieid, fileid, title, plot, kodicursor.execute(query, (movieid, fileid, title, plot,
shortplot, tagline, votecount, rating, writer, year, imdb, shortplot, tagline, votecount, rating, writer, year, imdb,
sorttitle, runtime, mpaa, genre, director, title, studio, sorttitle, runtime, mpaa, genre, director, title, studio,
@ -916,30 +907,42 @@ class TVShows(Items):
# UPDATE THE EPISODE ##### # UPDATE THE EPISODE #####
if update_item: if update_item:
log.info("UPDATE episode itemid: %s" % (itemid)) log.info("UPDATE episode itemid: %s" % (itemid))
# Update the movie entry # Update the movie entry
if v.KODIVERSION >= 16: if v.KODIVERSION >= 17:
# Kodi Jarvis, Krypton # Kodi Krypton
query = ' '.join(( query = '''
"UPDATE episode", UPDATE episode
"SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?," SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
"c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?," c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
"c18 = ?, c19 = ?, idFile=?, idSeason = ?", c18 = ?, c19 = ?, idFile=?, idSeason = ?,
"WHERE idEpisode = ?" userrating = ?
)) WHERE idEpisode = ?"
'''
kodicursor.execute(query, (title, plot, rating, writer,
premieredate, runtime, director, season, episode, title,
airsBeforeSeason, airsBeforeEpisode, playurl, pathid,
fileid, seasonid, userdata['UserRating'], episodeid))
elif v.KODIVERSION == 16:
# Kodi Jarvis
query = '''
UPDATE episode
SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
c18 = ?, c19 = ?, idFile=?, idSeason = ?
WHERE idEpisode = ?
'''
kodicursor.execute(query, (title, plot, rating, writer, kodicursor.execute(query, (title, plot, rating, writer,
premieredate, runtime, director, season, episode, title, premieredate, runtime, director, season, episode, title,
airsBeforeSeason, airsBeforeEpisode, playurl, pathid, airsBeforeSeason, airsBeforeEpisode, playurl, pathid,
fileid, seasonid, episodeid)) fileid, seasonid, episodeid))
else: else:
query = ' '.join(( query = '''
UPDATE episode
"UPDATE episode", SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
"SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?," c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
"c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?," c18 = ?, c19 = ?, idFile = ?
"c18 = ?, c19 = ?, idFile = ?", WHERE idEpisode = ?
"WHERE idEpisode = ?" '''
))
kodicursor.execute(query, (title, plot, rating, writer, kodicursor.execute(query, (title, plot, rating, writer,
premieredate, runtime, director, season, episode, title, premieredate, runtime, director, season, episode, title,
airsBeforeSeason, airsBeforeEpisode, playurl, pathid, airsBeforeSeason, airsBeforeEpisode, playurl, pathid,
@ -947,24 +950,37 @@ class TVShows(Items):
# Update parentid reference # Update parentid reference
plex_db.updateParentId(itemid, seasonid) plex_db.updateParentId(itemid, seasonid)
##### OR ADD THE EPISODE ##### # OR ADD THE EPISODE #####
else: else:
log.info("ADD episode itemid: %s - Title: %s" % (itemid, title)) log.info("ADD episode itemid: %s - Title: %s" % (itemid, title))
# Create the episode entry # Create the episode entry
if v.KODIVERSION >= 16: if v.KODIVERSION >= 17:
# Kodi Jarvis, Krypton # Kodi Krypton
query = ( query = '''
INSERT INTO episode( idEpisode, idFile, c00, c01, c03, c04,
c05, c09, c10, c12, c13, c14, idShow, c15, c16, c18,
c19, idSeason, userrating)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?)
'''
kodicursor.execute(query, (episodeid, fileid, title, plot,
rating, writer, premieredate, runtime, director, season,
episode, title, showid, airsBeforeSeason,
airsBeforeEpisode, playurl, pathid, seasonid,
userdata['UserRating']))
elif v.KODIVERSION == 16:
# Kodi Jarvis
query = '''
INSERT INTO episode( idEpisode, idFile, c00, c01, c03, c04,
c05, c09, c10, c12, c13, c14, idShow, c15, c16, c18,
c19, idSeason)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?)
''' '''
INSERT INTO episode( kodicursor.execute(query, (episodeid, fileid, title, plot,
idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14, rating, writer, premieredate, runtime, director, season,
idShow, c15, c16, c18, c19, idSeason) episode, title, showid, airsBeforeSeason,
airsBeforeEpisode, playurl, pathid, seasonid))
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''
)
kodicursor.execute(query, (episodeid, fileid, title, plot, rating, writer,
premieredate, runtime, director, season, episode, title, showid,
airsBeforeSeason, airsBeforeEpisode, playurl, pathid, seasonid))
else: else:
query = ( query = (
''' '''
@ -1539,7 +1555,7 @@ class Music(Items):
track = disc*2**16 + tracknumber track = disc*2**16 + tracknumber
year = API.getYear() year = API.getYear()
resume, duration = API.getRuntime() resume, duration = API.getRuntime()
rating = int(userdata['UserRating']) rating = userdata['UserRating']
hasEmbeddedCover = False hasEmbeddedCover = False
comment = None comment = None