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.remapSMBphotoNew = utils.settings('remapSMBphotoNew')
|
||||
# Shall we replace custom user ratings with the number of versions available?
|
||||
self.indicate_media_versions = True \
|
||||
if utils.settings('indicate_media_versions') == "true" else False
|
||||
self.indicate_media_versions = utils.settings('indicate_media_versions') == "true"
|
||||
# Will sync movie trailer differently: either play trailer directly or show
|
||||
# all the Plex extras for the user to choose
|
||||
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
||||
|
|
|
@ -95,30 +95,6 @@ class ItemBase(object):
|
|||
kodi_id,
|
||||
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,
|
||||
kodi_fileid, lastViewedAt, plex_type):
|
||||
"""
|
||||
|
|
|
@ -126,7 +126,7 @@ class Movie(ItemBase):
|
|||
rating,
|
||||
api.votecount())
|
||||
if api.provider('imdb') is not None:
|
||||
uniqueid = self.kodidb.add_uniqueid()
|
||||
uniqueid = self.kodidb.add_uniqueid_id()
|
||||
self.kodidb.add_uniqueid(uniqueid,
|
||||
kodi_id,
|
||||
v.KODI_TYPE_MOVIE,
|
||||
|
@ -253,3 +253,27 @@ class Movie(ItemBase):
|
|||
self.kodidb.remove_uniqueid(kodi_id, kodi_type)
|
||||
self.kodidb.remove_ratings(kodi_id, kodi_type)
|
||||
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)
|
||||
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):
|
||||
"""
|
||||
Remove the entire music object, including all associated entries from
|
||||
|
|
|
@ -11,6 +11,30 @@ LOG = getLogger('PLEX.tvshows')
|
|||
|
||||
|
||||
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):
|
||||
"""
|
||||
Remove the entire TV shows object (show, season or episode) including
|
||||
|
@ -167,7 +191,6 @@ class Show(ItemBase, TvShowMixin):
|
|||
api.audience_rating(),
|
||||
api.votecount(),
|
||||
rating_id)
|
||||
# update new uniqueid Kodi 17
|
||||
if api.provider('tvdb') is not None:
|
||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
||||
v.KODI_TYPE_SHOW)
|
||||
|
@ -209,9 +232,8 @@ class Show(ItemBase, TvShowMixin):
|
|||
"default",
|
||||
api.audience_rating(),
|
||||
api.votecount())
|
||||
if api.provider('tvdb') is not None:
|
||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
||||
v.KODI_TYPE_SHOW)
|
||||
if api.provider('tvdb'):
|
||||
uniqueid = self.kodidb.add_uniqueid_id()
|
||||
self.kodidb.add_uniqueid(uniqueid,
|
||||
kodi_id,
|
||||
v.KODI_TYPE_SHOW,
|
||||
|
@ -423,7 +445,7 @@ class Episode(ItemBase, TvShowMixin):
|
|||
userdata['Rating'],
|
||||
api.votecount(),
|
||||
ratingid)
|
||||
# update new uniqueid Kodi 17
|
||||
if api.provider('tvdb'):
|
||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
||||
v.KODI_TYPE_EPISODE)
|
||||
self.kodidb.update_uniqueid(kodi_id,
|
||||
|
@ -431,6 +453,9 @@ class Episode(ItemBase, TvShowMixin):
|
|||
api.provider('tvdb'),
|
||||
"tvdb",
|
||||
uniqueid)
|
||||
else:
|
||||
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_EPISODE)
|
||||
uniqueid = -1
|
||||
self.kodidb.modify_people(kodi_id,
|
||||
v.KODI_TYPE_EPISODE,
|
||||
api.people_list())
|
||||
|
@ -471,9 +496,8 @@ class Episode(ItemBase, TvShowMixin):
|
|||
"default",
|
||||
userdata['Rating'],
|
||||
api.votecount())
|
||||
# add new uniqueid Kodi 17
|
||||
uniqueid = self.kodidb.get_uniqueid(kodi_id,
|
||||
v.KODI_TYPE_EPISODE)
|
||||
if api.provider('tvdb'):
|
||||
uniqueid = self.kodidb.add_uniqueid_id()
|
||||
self.kodidb.add_uniqueid(uniqueid,
|
||||
kodi_id,
|
||||
v.KODI_TYPE_EPISODE,
|
||||
|
|
|
@ -468,6 +468,17 @@ class KodiMusicDB(common.KodiDBBase):
|
|||
VALUES (?, ?, ?, ?, ?)
|
||||
''', (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):
|
||||
"""
|
||||
Kodi 17 only
|
||||
|
|
|
@ -755,7 +755,7 @@ class KodiVideoDB(common.KodiDBBase):
|
|||
VALUES (?, ?, ?, ?, ?)
|
||||
''', (args))
|
||||
|
||||
def add_uniqueid(self):
|
||||
def add_uniqueid_id(self):
|
||||
self.cursor.execute('SELECT COALESCE(MAX(uniqueid_id), 0) FROM uniqueid')
|
||||
return self.cursor.fetchone()[0] + 1
|
||||
|
||||
|
@ -768,7 +768,7 @@ class KodiVideoDB(common.KodiDBBase):
|
|||
try:
|
||||
return self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
return self.add_uniqueid()
|
||||
return self.add_uniqueid_id()
|
||||
|
||||
def update_uniqueid(self, *args):
|
||||
"""
|
||||
|
@ -994,10 +994,16 @@ class KodiVideoDB(common.KodiDBBase):
|
|||
Updates userrating
|
||||
"""
|
||||
if kodi_type == v.KODI_TYPE_MOVIE:
|
||||
table = kodi_type
|
||||
identifier = 'idMovie'
|
||||
elif kodi_type == v.KODI_TYPE_EPISODE:
|
||||
table = kodi_type
|
||||
identifier = 'idEpisode'
|
||||
elif kodi_type == v.KODI_TYPE_SONG:
|
||||
identifier = 'idSong'
|
||||
self.cursor.execute('''UPDATE %s SET userrating = ? WHERE ? = ?''' % kodi_type,
|
||||
elif kodi_type == v.KODI_TYPE_SEASON:
|
||||
table = 'seasons'
|
||||
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))
|
||||
|
|
|
@ -136,6 +136,7 @@ class FullSync(common.libsync_mixin):
|
|||
# Ensure that the DB connection is closed to commit the
|
||||
# changes above - avoids "Item not yet synced" error
|
||||
self.queue.join()
|
||||
if self.plex_type != v.PLEX_TYPE_ARTIST:
|
||||
self.process_playstate(iterator)
|
||||
except RuntimeError:
|
||||
LOG.error('Could not process playstate for section %s', section)
|
||||
|
|
|
@ -303,7 +303,8 @@ class API(object):
|
|||
except (KeyError, ValueError):
|
||||
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
|
||||
for _ in self.item.findall('./Media'):
|
||||
userrating += 1
|
||||
|
|
Loading…
Reference in a new issue