diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 465c7174..592e02ae 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -952,6 +952,24 @@ class Kodidb_Functions(): return None return int(runtime) + def get_resume(self, file_id): + """ + Returns the first resume point in seconds (int) if found, else None for + the Kodi file_id provided + """ + query = ''' + SELECT timeInSeconds + FROM bookmark + WHERE idFile = ? + ''' + self.cursor.execute(query, (file_id,)) + resume = self.cursor.fetchone() + try: + resume = resume[0] + except TypeError: + resume = None + return resume + def addPlaystate(self, fileid, resume_seconds, total_seconds, playcount, dateplayed): # Delete existing resume point query = ' '.join(( diff --git a/resources/lib/playback.py b/resources/lib/playback.py index 68f223dd..bc6b66d5 100644 --- a/resources/lib/playback.py +++ b/resources/lib/playback.py @@ -11,6 +11,7 @@ from PlexAPI import API from PlexFunctions import GetPlexMetadata, init_plex_playqueue from downloadutils import DownloadUtils as DU import plexdb_functions as plexdb +import kodidb_functions as kodidb import playlist_func as PL import playqueue as PQ from playutils import PlayUtils @@ -287,6 +288,13 @@ def conclude_playback(playqueue, pos): playutils.audio_subtitle_prefs(listitem) if state.RESUME_PLAYBACK is True: state.RESUME_PLAYBACK = False + if (item.offset is None and + item.plex_type not in (v.PLEX_TYPE_SONG, v.PLEX_TYPE_CLIP)): + with plexdb.Get_Plex_DB() as plex_db: + plex_dbitem = plex_db.getItem_byId(item.plex_id) + file_id = plex_dbitem[1] if plex_dbitem else None + with kodidb.GetKodiDB('video') as kodi_db: + item.offset = kodi_db.get_resume(file_id) LOG.info('Resuming playback at %s', item.offset) listitem.setProperty('StartOffset', str(item.offset)) listitem.setProperty('resumetime', str(item.offset))