Merge pull request #1365 from croneter/seasonnames

Sync name and user rating of a TV show season to Kodi
This commit is contained in:
croneter 2021-02-24 17:42:15 +01:00 committed by GitHub
commit 16cbe430af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 7 deletions

View file

@ -270,6 +270,7 @@ class Show(TvShowMixin, ItemBase):
unique_ids.get('imdb',
unique_ids.get('tmdb')))
class Season(TvShowMixin, ItemBase):
def add_update(self, xml, section_name=None, section_id=None,
children=None):
@ -279,7 +280,7 @@ class Season(TvShowMixin, ItemBase):
api = API(xml)
if not self.sync_this_item(section_id or api.library_section_id()):
LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
'Kodi', api.plex_type, api.plex_id, api.title(),
'Kodi', api.plex_type, api.plex_id, api.season_name(),
section_id or api.library_section_id())
return
plex_id = api.plex_id
@ -317,15 +318,24 @@ class Season(TvShowMixin, ItemBase):
if key in artwork and artwork[key] == parent_artwork[key]:
del artwork[key]
if update_item:
LOG.info('UPDATE season plex_id %s - %s', plex_id, api.title())
LOG.info('UPDATE season plex_id %s - %s',
plex_id, api.season_name())
kodi_id = season['kodi_id']
self.kodidb.update_season(kodi_id,
parent_id,
api.index(),
api.season_name(),
api.userrating() or None)
if app.SYNC.artwork:
self.kodidb.modify_artwork(artwork,
kodi_id,
v.KODI_TYPE_SEASON)
else:
LOG.info('ADD season plex_id %s - %s', plex_id, api.title())
kodi_id = self.kodidb.add_season(parent_id, api.index())
LOG.info('ADD season plex_id %s - %s', plex_id, api.season_name())
kodi_id = self.kodidb.add_season(parent_id,
api.index(),
api.season_name(),
api.userrating() or None)
if app.SYNC.artwork:
self.kodidb.add_artwork(artwork,
kodi_id,

View file

@ -718,15 +718,32 @@ class KodiVideoDB(common.KodiDBBase):
self.cursor.execute('DELETE FROM sets WHERE idSet = ?', (set_id,))
@db.catch_operationalerrors
def add_season(self, showid, seasonnumber):
def add_season(self, showid, seasonnumber, name, userrating):
"""
Adds a TV show season to the Kodi video DB or simply returns the ID,
if there already is an entry in the DB
"""
self.cursor.execute('INSERT INTO seasons(idShow, season) VALUES (?, ?)',
(showid, seasonnumber))
self.cursor.execute('''
INSERT INTO seasons(
idShow, season, name, userrating)
VALUES (?, ?, ?, ?)
''', (showid, seasonnumber, name, userrating))
return self.cursor.lastrowid
@db.catch_operationalerrors
def update_season(self, seasonid, showid, seasonnumber, name, userrating):
"""
Updates a TV show season with a certain seasonid
"""
self.cursor.execute('''
UPDATE seasons
SET idShow = ?,
season = ?,
name = ?,
userrating = ?
WHERE idSeason = ?
''', (showid, seasonnumber, name, userrating, seasonid))
@db.catch_operationalerrors
def add_uniqueid(self, *args):
"""

View file

@ -398,6 +398,12 @@ class Base(object):
"""
return self.parent_index()
def season_name(self):
"""
Returns the season's name/title or None
"""
return self.xml.get('title')
def artist_name(self):
"""
Returns the artist name for an album: first it attempts to return