Another attempt to fix episode resume from widgets

- Tried to get as close as possible to emby DB
This commit is contained in:
croneter 2018-05-26 17:28:11 +02:00
parent f68b167c0d
commit 04044ac896
6 changed files with 74 additions and 43 deletions

View file

@ -428,6 +428,8 @@ class API(object):
provider = provider[0]
except IndexError:
provider = None
if provider and self.plex_type() == v.PLEX_TYPE_EPISODE:
provider = provider.replace('/', '')
return provider
def titles(self):
@ -500,8 +502,8 @@ class API(object):
resume = float(self.item.attrib['viewOffset'])
except (KeyError, ValueError):
resume = 0.0
runtime = int(runtime * v.PLEX_TO_KODI_TIMEFACTOR)
resume = int(resume * v.PLEX_TO_KODI_TIMEFACTOR)
runtime = runtime * v.PLEX_TO_KODI_TIMEFACTOR
resume = resume * v.PLEX_TO_KODI_TIMEFACTOR
return resume, runtime
def content_rating(self):
@ -531,9 +533,14 @@ class API(object):
def premiere_date(self):
"""
Returns the "originallyAvailableAt" or None
Returns the "originallyAvailableAt". If no time is present, 11pm will be
set. Example: string "2017-02-01 23:00:00"
Returns None if not found
"""
return self.item.get('originallyAvailableAt')
date = self.item.get('originallyAvailableAt')
if date and len(date) == 10:
date = '%s 23:00:00' % date
return date
def music_studio(self):
"""

View file

@ -555,13 +555,14 @@ def getOnDeck(viewid, mediatype, tagname, limit):
if directpaths:
url = api.file_path(force_first_media=True)
else:
url = ('plugin://%s.tvshows/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
url = ('plugin://%s.tvshows/%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (v.ADDON_ID,
api.grandparent_id(),
api.plex_id(),
api.plex_type(),
api.file_name(force_first_media=True)))
if api.resume_point():
listitem.setProperty('resumetime', str(api.resume_point()))
# if api.resume_point():
# listitem.setProperty('resumetime', str(api.resume_point()))
xbmcplugin.addDirectoryItem(
handle=HANDLE,
url=url,

View file

@ -584,10 +584,9 @@ class TVShows(Items):
# Set plugin path
toplevelpath = "plugin://%s.tvshows/" % v.ADDON_ID
path = "%s%s/" % (toplevelpath, itemid)
toppathid = self.kodi_db.get_path(toplevelpath)
toppathid = None
pathid = self.kodi_db.add_video_path(path,
date_added=api.date_created(),
id_parent_path=toppathid)
# UPDATE THE TVSHOW #####
if update_item:
@ -892,13 +891,13 @@ class TVShows(Items):
UPDATE episode
SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
c18 = ?, c19 = ?, idFile=?, idSeason = ?,
c19 = ?, idFile=?, idSeason = ?,
userrating = ?
WHERE idEpisode = ?
'''
kodicursor.execute(query, (title, plot, ratingid, writer,
premieredate, runtime, director, season, episode, title,
airs_before_season, airs_before_episode, playurl, pathid,
None, None, pathid,
fileid, seasonid, userdata['UserRating'], episodeid))
else:
# Kodi Jarvis
@ -911,7 +910,7 @@ class TVShows(Items):
'''
kodicursor.execute(query, (title, plot, rating, writer,
premieredate, runtime, director, season, episode, title,
airs_before_season, airs_before_episode, playurl, pathid,
None, None, playurl, pathid,
fileid, seasonid, episodeid))
# Update parentid reference
plex_db.updateParentId(itemid, seasonid)
@ -940,16 +939,16 @@ class TVShows(Items):
"tvdb")
query = '''
INSERT INTO episode( idEpisode, idFile, c00, c01, c03, c04,
c05, c09, c10, c12, c13, c14, idShow, c15, c16, c18,
c19, idSeason, userrating)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?)
c05, c09, c10, c12, c13, c14, idShow, c15, c16,
idSeason, userrating)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?)
'''
kodicursor.execute(query, (episodeid, fileid, title, plot,
rating_id, writer, premieredate, runtime, director, season,
episode, title, showid, airs_before_season,
airs_before_episode, playurl, pathid, seasonid,
userdata['UserRating']))
uniqueid, '', premieredate, runtime, director, season,
episode, title, showid, None,
None, seasonid,
None))
else:
# Kodi Jarvis
query = '''
@ -961,8 +960,8 @@ class TVShows(Items):
'''
kodicursor.execute(query, (episodeid, fileid, title, plot,
rating, writer, premieredate, runtime, director, season,
episode, title, showid, airs_before_season,
airs_before_episode, playurl, pathid, seasonid))
episode, title, showid, None,
None, playurl, pathid, seasonid))
# Create or update the reference in plex table Add reference is
# idempotent; the call here updates also fileid and pathid when item is
@ -985,11 +984,27 @@ class TVShows(Items):
kodicursor)
streams = api.mediastreams()
self.kodi_db.modify_streams(fileid, streams, runtime)
self.kodi_db.addPlaystate(fileid,
resume,
runtime,
playcount,
dateplayed)
if resume:
self.kodi_db.addPlaystate(fileid,
resume,
runtime,
playcount,
dateplayed)
filename = api.file_name(force_first_media=True)
path = 'plugin://%s.tvshows/' % v.ADDON_ID
filename = ('%s%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (path, series_id, itemid, v.PLEX_TYPE_EPISODE, filename))
# Root path tvshows/ already saved in Kodi DB
pathid = self.kodi_db.add_video_path(path)
# add/retrieve pathid and fileid
# if the path or file already exists, the calls return current value
fileid = self.kodi_db.add_file(filename, pathid, dateadded)
LOG.debug('pathid: %s, fileid: %s', pathid, fileid)
self.kodi_db.addPlaystate(fileid,
resume,
runtime,
playcount,
dateplayed)
@catch_exceptions(warnuser=True)
def remove(self, plex_id):

View file

@ -78,7 +78,7 @@ class KodiDBMethods(object):
'movies',
'metadata.local',
1,
0))
None))
# And TV shows
path_id = self.get_path('plugin://%s.tvshows/' % v.ADDON_ID)
if path_id is None:
@ -98,7 +98,7 @@ class KodiDBMethods(object):
'tvshows',
'metadata.local',
1,
0))
None))
def parent_path_id(self, path):
"""
@ -147,12 +147,12 @@ class KodiDBMethods(object):
pathid = self.cursor.fetchone()[0] + 1
query = '''
INSERT INTO path(idPath, strPath, dateAdded, idParentPath,
strContent, strScraper, noUpdate)
VALUES (?, ?, ?, ?, ?, ?, ?)
strContent, strScraper, noUpdate, exclude)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
'''
self.cursor.execute(query,
(pathid, path, date_added, id_parent_path,
content, scraper, 1))
content, scraper, 1, None))
return pathid
def add_music_path(self, path, strHash=None):
@ -733,9 +733,9 @@ class KodiDBMethods(object):
file_id,
resume_seconds,
total_seconds,
'',
'VideoPlayer',
'',
None,
'DVDPlayer',
None,
1))
def createTag(self, name):

View file

@ -465,11 +465,11 @@ def _playback_cleanup(ended=False):
DU().downloadUrl(
'{server}/video/:/transcode/universal/stop',
parameters={'session': v.PKC_MACHINE_IDENTIFIER})
if playerid == 1:
# if playerid == 1:
# Bookmarks might not be pickup up correctly, so let's do them
# manually. Applies to addon paths, but direct paths might have
# started playback via PMS
_record_playstate(status, ended)
# _record_playstate(status, ended)
# Reset the player's status
state.PLAYER_STATES[playerid] = copy.deepcopy(state.PLAYSTATE)
# As all playback has halted, reset the players that have been active
@ -531,7 +531,7 @@ def _record_playstate(status, ended):
xbmc.executebuiltin('ReloadSkin()')
thread = Thread(target=_clean_file_table)
thread.setDaemon(True)
thread.start()
# thread.start()
def _clean_file_table():

View file

@ -241,11 +241,19 @@ def _prep_playlist_stack(xml):
api.set_part_number(part)
if kodi_id is None:
# Need to redirect again to PKC to conclude playback
path = ('plugin://%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (v.ADDON_TYPE[api.plex_type()],
api.plex_id(),
api.plex_type(),
api.file_name(force_first_media=True)))
if api.plex_type() == v.PLEX_TYPE_EPISODE:
path = ('plugin://%s/%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (v.ADDON_TYPE[api.plex_type()],
api.grandparent_id(),
api.plex_id(),
api.plex_type(),
api.file_name(force_first_media=True)))
else:
path = ('plugin://%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
% (v.ADDON_TYPE[api.plex_type()],
api.plex_id(),
api.plex_type(),
api.file_name(force_first_media=True)))
listitem = api.create_listitem()
listitem.setPath(try_encode(path))
else: