Fix some TypeErrors
This commit is contained in:
parent
c8b0e203ef
commit
fddd374b79
9 changed files with 120 additions and 54 deletions
|
@ -48,8 +48,7 @@ class Sync(object):
|
||||||
self.remapSMBphotoOrg = utils.settings('remapSMBphotoOrg')
|
self.remapSMBphotoOrg = utils.settings('remapSMBphotoOrg')
|
||||||
self.remapSMBphotoNew = utils.settings('remapSMBphotoNew')
|
self.remapSMBphotoNew = utils.settings('remapSMBphotoNew')
|
||||||
# Shall we replace custom user ratings with the number of versions available?
|
# Shall we replace custom user ratings with the number of versions available?
|
||||||
self.indicate_media_versions = True \
|
self.indicate_media_versions = utils.settings('indicate_media_versions') == "true"
|
||||||
if utils.settings('indicate_media_versions') == "true" else False
|
|
||||||
# Will sync movie trailer differently: either play trailer directly or show
|
# Will sync movie trailer differently: either play trailer directly or show
|
||||||
# all the Plex extras for the user to choose
|
# all the Plex extras for the user to choose
|
||||||
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
||||||
|
|
|
@ -95,30 +95,6 @@ class ItemBase(object):
|
||||||
kodi_id,
|
kodi_id,
|
||||||
kodi_type)
|
kodi_type)
|
||||||
|
|
||||||
def update_userdata(self, xml_element, plex_type):
|
|
||||||
"""
|
|
||||||
Updates the Kodi watched state of the item from PMS. Also retrieves
|
|
||||||
Plex resume points for movies in progress.
|
|
||||||
"""
|
|
||||||
api = API(xml_element)
|
|
||||||
# Get key and db entry on the Kodi db side
|
|
||||||
db_item = self.plexdb.item_by_id(api.plex_id(), plex_type)
|
|
||||||
if not db_item:
|
|
||||||
LOG.error('Item not yet synced: %s', xml_element.attrib)
|
|
||||||
return
|
|
||||||
# Grab the user's viewcount, resume points etc. from PMS' answer
|
|
||||||
userdata = api.userdata()
|
|
||||||
# Write to Kodi DB
|
|
||||||
self.kodidb.set_resume(db_item['kodi_fileid'],
|
|
||||||
userdata['Resume'],
|
|
||||||
userdata['Runtime'],
|
|
||||||
userdata['PlayCount'],
|
|
||||||
userdata['LastPlayedDate'],
|
|
||||||
plex_type)
|
|
||||||
self.kodidb.update_userrating(db_item['kodi_id'],
|
|
||||||
db_item['kodi_type'],
|
|
||||||
userdata['UserRating'])
|
|
||||||
|
|
||||||
def update_playstate(self, mark_played, view_count, resume, duration,
|
def update_playstate(self, mark_played, view_count, resume, duration,
|
||||||
kodi_fileid, lastViewedAt, plex_type):
|
kodi_fileid, lastViewedAt, plex_type):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -126,7 +126,7 @@ class Movie(ItemBase):
|
||||||
rating,
|
rating,
|
||||||
api.votecount())
|
api.votecount())
|
||||||
if api.provider('imdb') is not None:
|
if api.provider('imdb') is not None:
|
||||||
uniqueid = self.kodidb.add_uniqueid()
|
uniqueid = self.kodidb.add_uniqueid_id()
|
||||||
self.kodidb.add_uniqueid(uniqueid,
|
self.kodidb.add_uniqueid(uniqueid,
|
||||||
kodi_id,
|
kodi_id,
|
||||||
v.KODI_TYPE_MOVIE,
|
v.KODI_TYPE_MOVIE,
|
||||||
|
@ -253,3 +253,27 @@ class Movie(ItemBase):
|
||||||
self.kodidb.remove_uniqueid(kodi_id, kodi_type)
|
self.kodidb.remove_uniqueid(kodi_id, kodi_type)
|
||||||
self.kodidb.remove_ratings(kodi_id, kodi_type)
|
self.kodidb.remove_ratings(kodi_id, kodi_type)
|
||||||
LOG.debug('Deleted movie %s from kodi database', plex_id)
|
LOG.debug('Deleted movie %s from kodi database', plex_id)
|
||||||
|
|
||||||
|
def update_userdata(self, xml_element, plex_type):
|
||||||
|
"""
|
||||||
|
Updates the Kodi watched state of the item from PMS. Also retrieves
|
||||||
|
Plex resume points for movies in progress.
|
||||||
|
"""
|
||||||
|
api = API(xml_element)
|
||||||
|
# Get key and db entry on the Kodi db side
|
||||||
|
db_item = self.plexdb.item_by_id(api.plex_id(), plex_type)
|
||||||
|
if not db_item:
|
||||||
|
LOG.error('Item not yet synced: %s', xml_element.attrib)
|
||||||
|
return
|
||||||
|
# Grab the user's viewcount, resume points etc. from PMS' answer
|
||||||
|
userdata = api.userdata()
|
||||||
|
# Write to Kodi DB
|
||||||
|
self.kodidb.set_resume(db_item['kodi_fileid'],
|
||||||
|
userdata['Resume'],
|
||||||
|
userdata['Runtime'],
|
||||||
|
userdata['PlayCount'],
|
||||||
|
userdata['LastPlayedDate'],
|
||||||
|
plex_type)
|
||||||
|
self.kodidb.update_userrating(db_item['kodi_id'],
|
||||||
|
db_item['kodi_type'],
|
||||||
|
userdata['UserRating'])
|
||||||
|
|
|
@ -29,6 +29,30 @@ class MusicMixin(object):
|
||||||
artcursor=self.artcursor)
|
artcursor=self.artcursor)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def update_userdata(self, xml_element, plex_type):
|
||||||
|
"""
|
||||||
|
Updates the Kodi watched state of the item from PMS. Also retrieves
|
||||||
|
Plex resume points for movies in progress.
|
||||||
|
"""
|
||||||
|
api = API(xml_element)
|
||||||
|
# Get key and db entry on the Kodi db side
|
||||||
|
db_item = self.plexdb.item_by_id(api.plex_id(), plex_type)
|
||||||
|
if not db_item:
|
||||||
|
LOG.error('Item not yet synced: %s', xml_element.attrib)
|
||||||
|
return
|
||||||
|
# Grab the user's viewcount, resume points etc. from PMS' answer
|
||||||
|
userdata = api.userdata()
|
||||||
|
self.kodidb.update_userrating(db_item['kodi_id'],
|
||||||
|
db_item['kodi_type'],
|
||||||
|
userdata['UserRating'])
|
||||||
|
if plex_type == v.PLEX_TYPE_SONG:
|
||||||
|
self.kodidb.set_resume(db_item['kodi_fileid'],
|
||||||
|
userdata['Resume'],
|
||||||
|
userdata['Runtime'],
|
||||||
|
userdata['PlayCount'],
|
||||||
|
userdata['LastPlayedDate'],
|
||||||
|
plex_type)
|
||||||
|
|
||||||
def remove(self, plex_id, plex_type=None):
|
def remove(self, plex_id, plex_type=None):
|
||||||
"""
|
"""
|
||||||
Remove the entire music object, including all associated entries from
|
Remove the entire music object, including all associated entries from
|
||||||
|
|
|
@ -11,6 +11,30 @@ LOG = getLogger('PLEX.tvshows')
|
||||||
|
|
||||||
|
|
||||||
class TvShowMixin(object):
|
class TvShowMixin(object):
|
||||||
|
def update_userdata(self, xml_element, plex_type):
|
||||||
|
"""
|
||||||
|
Updates the Kodi watched state of the item from PMS. Also retrieves
|
||||||
|
Plex resume points for movies in progress.
|
||||||
|
"""
|
||||||
|
api = API(xml_element)
|
||||||
|
# Get key and db entry on the Kodi db side
|
||||||
|
db_item = self.plexdb.item_by_id(api.plex_id(), plex_type)
|
||||||
|
if not db_item:
|
||||||
|
LOG.error('Item not yet synced: %s', xml_element.attrib)
|
||||||
|
return
|
||||||
|
# Grab the user's viewcount, resume points etc. from PMS' answer
|
||||||
|
userdata = api.userdata()
|
||||||
|
self.kodidb.update_userrating(db_item['kodi_id'],
|
||||||
|
db_item['kodi_type'],
|
||||||
|
userdata['UserRating'])
|
||||||
|
if plex_type == v.PLEX_TYPE_EPISODE:
|
||||||
|
self.kodidb.set_resume(db_item['kodi_fileid'],
|
||||||
|
userdata['Resume'],
|
||||||
|
userdata['Runtime'],
|
||||||
|
userdata['PlayCount'],
|
||||||
|
userdata['LastPlayedDate'],
|
||||||
|
plex_type)
|
||||||
|
|
||||||
def remove(self, plex_id, plex_type=None):
|
def remove(self, plex_id, plex_type=None):
|
||||||
"""
|
"""
|
||||||
Remove the entire TV shows object (show, season or episode) including
|
Remove the entire TV shows object (show, season or episode) including
|
||||||
|
@ -167,7 +191,6 @@ class Show(ItemBase, TvShowMixin):
|
||||||
api.audience_rating(),
|
api.audience_rating(),
|
||||||
api.votecount(),
|
api.votecount(),
|
||||||
rating_id)
|
rating_id)
|
||||||
# update new uniqueid Kodi 17
|
|
||||||
if api.provider('tvdb') is not None:
|
if api.provider('tvdb') is not None:
|
||||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
||||||
v.KODI_TYPE_SHOW)
|
v.KODI_TYPE_SHOW)
|
||||||
|
@ -209,9 +232,8 @@ class Show(ItemBase, TvShowMixin):
|
||||||
"default",
|
"default",
|
||||||
api.audience_rating(),
|
api.audience_rating(),
|
||||||
api.votecount())
|
api.votecount())
|
||||||
if api.provider('tvdb') is not None:
|
if api.provider('tvdb'):
|
||||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
uniqueid = self.kodidb.add_uniqueid_id()
|
||||||
v.KODI_TYPE_SHOW)
|
|
||||||
self.kodidb.add_uniqueid(uniqueid,
|
self.kodidb.add_uniqueid(uniqueid,
|
||||||
kodi_id,
|
kodi_id,
|
||||||
v.KODI_TYPE_SHOW,
|
v.KODI_TYPE_SHOW,
|
||||||
|
@ -423,14 +445,17 @@ class Episode(ItemBase, TvShowMixin):
|
||||||
userdata['Rating'],
|
userdata['Rating'],
|
||||||
api.votecount(),
|
api.votecount(),
|
||||||
ratingid)
|
ratingid)
|
||||||
# update new uniqueid Kodi 17
|
if api.provider('tvdb'):
|
||||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
||||||
v.KODI_TYPE_EPISODE)
|
v.KODI_TYPE_EPISODE)
|
||||||
self.kodidb.update_uniqueid(kodi_id,
|
self.kodidb.update_uniqueid(kodi_id,
|
||||||
v.KODI_TYPE_EPISODE,
|
v.KODI_TYPE_EPISODE,
|
||||||
api.provider('tvdb'),
|
api.provider('tvdb'),
|
||||||
"tvdb",
|
"tvdb",
|
||||||
uniqueid)
|
uniqueid)
|
||||||
|
else:
|
||||||
|
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_EPISODE)
|
||||||
|
uniqueid = -1
|
||||||
self.kodidb.modify_people(kodi_id,
|
self.kodidb.modify_people(kodi_id,
|
||||||
v.KODI_TYPE_EPISODE,
|
v.KODI_TYPE_EPISODE,
|
||||||
api.people_list())
|
api.people_list())
|
||||||
|
@ -471,14 +496,13 @@ class Episode(ItemBase, TvShowMixin):
|
||||||
"default",
|
"default",
|
||||||
userdata['Rating'],
|
userdata['Rating'],
|
||||||
api.votecount())
|
api.votecount())
|
||||||
# add new uniqueid Kodi 17
|
if api.provider('tvdb'):
|
||||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
uniqueid = self.kodidb.add_uniqueid_id()
|
||||||
v.KODI_TYPE_EPISODE)
|
self.kodidb.add_uniqueid(uniqueid,
|
||||||
self.kodidb.add_uniqueid(uniqueid,
|
kodi_id,
|
||||||
kodi_id,
|
v.KODI_TYPE_EPISODE,
|
||||||
v.KODI_TYPE_EPISODE,
|
api.provider('tvdb'),
|
||||||
api.provider('tvdb'),
|
"tvdb")
|
||||||
"tvdb")
|
|
||||||
self.kodidb.add_people(kodi_id,
|
self.kodidb.add_people(kodi_id,
|
||||||
v.KODI_TYPE_EPISODE,
|
v.KODI_TYPE_EPISODE,
|
||||||
api.people_list())
|
api.people_list())
|
||||||
|
|
|
@ -468,6 +468,17 @@ class KodiMusicDB(common.KodiDBBase):
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
''', (song_id, album_id, track_no, track_title, runtime))
|
''', (song_id, album_id, track_no, track_title, runtime))
|
||||||
|
|
||||||
|
def update_userrating(self, kodi_id, kodi_type, userrating):
|
||||||
|
"""
|
||||||
|
Updates userrating for songs and albums
|
||||||
|
"""
|
||||||
|
if kodi_type == v.KODI_TYPE_SONG:
|
||||||
|
identifier = 'idSong'
|
||||||
|
elif kodi_type == v.KODI_TYPE_ALBUM:
|
||||||
|
identifier = 'idAlbum'
|
||||||
|
self.cursor.execute('''UPDATE %s SET userrating = ? WHERE ? = ?''' % kodi_type,
|
||||||
|
(userrating, identifier, kodi_id))
|
||||||
|
|
||||||
def remove_albuminfosong(self, kodi_id):
|
def remove_albuminfosong(self, kodi_id):
|
||||||
"""
|
"""
|
||||||
Kodi 17 only
|
Kodi 17 only
|
||||||
|
|
|
@ -755,7 +755,7 @@ class KodiVideoDB(common.KodiDBBase):
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
''', (args))
|
''', (args))
|
||||||
|
|
||||||
def add_uniqueid(self):
|
def add_uniqueid_id(self):
|
||||||
self.cursor.execute('SELECT COALESCE(MAX(uniqueid_id), 0) FROM uniqueid')
|
self.cursor.execute('SELECT COALESCE(MAX(uniqueid_id), 0) FROM uniqueid')
|
||||||
return self.cursor.fetchone()[0] + 1
|
return self.cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
|
@ -768,7 +768,7 @@ class KodiVideoDB(common.KodiDBBase):
|
||||||
try:
|
try:
|
||||||
return self.cursor.fetchone()[0]
|
return self.cursor.fetchone()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return self.add_uniqueid()
|
return self.add_uniqueid_id()
|
||||||
|
|
||||||
def update_uniqueid(self, *args):
|
def update_uniqueid(self, *args):
|
||||||
"""
|
"""
|
||||||
|
@ -994,10 +994,16 @@ class KodiVideoDB(common.KodiDBBase):
|
||||||
Updates userrating
|
Updates userrating
|
||||||
"""
|
"""
|
||||||
if kodi_type == v.KODI_TYPE_MOVIE:
|
if kodi_type == v.KODI_TYPE_MOVIE:
|
||||||
|
table = kodi_type
|
||||||
identifier = 'idMovie'
|
identifier = 'idMovie'
|
||||||
elif kodi_type == v.KODI_TYPE_EPISODE:
|
elif kodi_type == v.KODI_TYPE_EPISODE:
|
||||||
|
table = kodi_type
|
||||||
identifier = 'idEpisode'
|
identifier = 'idEpisode'
|
||||||
elif kodi_type == v.KODI_TYPE_SONG:
|
elif kodi_type == v.KODI_TYPE_SEASON:
|
||||||
identifier = 'idSong'
|
table = 'seasons'
|
||||||
self.cursor.execute('''UPDATE %s SET userrating = ? WHERE ? = ?''' % kodi_type,
|
identifier = 'idSeason'
|
||||||
|
elif kodi_type == v.KODI_TYPE_SHOW:
|
||||||
|
table = kodi_type
|
||||||
|
identifier = 'idShow'
|
||||||
|
self.cursor.execute('''UPDATE %s SET userrating = ? WHERE ? = ?''' % table,
|
||||||
(userrating, identifier, kodi_id))
|
(userrating, identifier, kodi_id))
|
||||||
|
|
|
@ -136,7 +136,8 @@ class FullSync(common.libsync_mixin):
|
||||||
# Ensure that the DB connection is closed to commit the
|
# Ensure that the DB connection is closed to commit the
|
||||||
# changes above - avoids "Item not yet synced" error
|
# changes above - avoids "Item not yet synced" error
|
||||||
self.queue.join()
|
self.queue.join()
|
||||||
self.process_playstate(iterator)
|
if self.plex_type != v.PLEX_TYPE_ARTIST:
|
||||||
|
self.process_playstate(iterator)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
LOG.error('Could not process playstate for section %s', section)
|
LOG.error('Could not process playstate for section %s', section)
|
||||||
successful = False
|
successful = False
|
||||||
|
|
|
@ -303,7 +303,8 @@ class API(object):
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
last_played = None
|
last_played = None
|
||||||
|
|
||||||
if app.SYNC.indicate_media_versions is True:
|
if (app.SYNC.indicate_media_versions is True and
|
||||||
|
self.plex_type() in (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_EPISODE)):
|
||||||
userrating = 0
|
userrating = 0
|
||||||
for _ in self.item.findall('./Media'):
|
for _ in self.item.findall('./Media'):
|
||||||
userrating += 1
|
userrating += 1
|
||||||
|
|
Loading…
Reference in a new issue