Another attempt to fix episode resume from widgets
- Tried to get as close as possible to emby DB
This commit is contained in:
parent
f68b167c0d
commit
04044ac896
6 changed files with 74 additions and 43 deletions
|
@ -428,6 +428,8 @@ class API(object):
|
||||||
provider = provider[0]
|
provider = provider[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
provider = None
|
provider = None
|
||||||
|
if provider and self.plex_type() == v.PLEX_TYPE_EPISODE:
|
||||||
|
provider = provider.replace('/', '')
|
||||||
return provider
|
return provider
|
||||||
|
|
||||||
def titles(self):
|
def titles(self):
|
||||||
|
@ -500,8 +502,8 @@ class API(object):
|
||||||
resume = float(self.item.attrib['viewOffset'])
|
resume = float(self.item.attrib['viewOffset'])
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
resume = 0.0
|
resume = 0.0
|
||||||
runtime = int(runtime * v.PLEX_TO_KODI_TIMEFACTOR)
|
runtime = runtime * v.PLEX_TO_KODI_TIMEFACTOR
|
||||||
resume = int(resume * v.PLEX_TO_KODI_TIMEFACTOR)
|
resume = resume * v.PLEX_TO_KODI_TIMEFACTOR
|
||||||
return resume, runtime
|
return resume, runtime
|
||||||
|
|
||||||
def content_rating(self):
|
def content_rating(self):
|
||||||
|
@ -531,9 +533,14 @@ class API(object):
|
||||||
|
|
||||||
def premiere_date(self):
|
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):
|
def music_studio(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -555,13 +555,14 @@ def getOnDeck(viewid, mediatype, tagname, limit):
|
||||||
if directpaths:
|
if directpaths:
|
||||||
url = api.file_path(force_first_media=True)
|
url = api.file_path(force_first_media=True)
|
||||||
else:
|
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,
|
% (v.ADDON_ID,
|
||||||
|
api.grandparent_id(),
|
||||||
api.plex_id(),
|
api.plex_id(),
|
||||||
api.plex_type(),
|
api.plex_type(),
|
||||||
api.file_name(force_first_media=True)))
|
api.file_name(force_first_media=True)))
|
||||||
if api.resume_point():
|
# if api.resume_point():
|
||||||
listitem.setProperty('resumetime', str(api.resume_point()))
|
# listitem.setProperty('resumetime', str(api.resume_point()))
|
||||||
xbmcplugin.addDirectoryItem(
|
xbmcplugin.addDirectoryItem(
|
||||||
handle=HANDLE,
|
handle=HANDLE,
|
||||||
url=url,
|
url=url,
|
||||||
|
|
|
@ -584,10 +584,9 @@ class TVShows(Items):
|
||||||
# Set plugin path
|
# Set plugin path
|
||||||
toplevelpath = "plugin://%s.tvshows/" % v.ADDON_ID
|
toplevelpath = "plugin://%s.tvshows/" % v.ADDON_ID
|
||||||
path = "%s%s/" % (toplevelpath, itemid)
|
path = "%s%s/" % (toplevelpath, itemid)
|
||||||
toppathid = self.kodi_db.get_path(toplevelpath)
|
toppathid = None
|
||||||
|
|
||||||
pathid = self.kodi_db.add_video_path(path,
|
pathid = self.kodi_db.add_video_path(path,
|
||||||
date_added=api.date_created(),
|
|
||||||
id_parent_path=toppathid)
|
id_parent_path=toppathid)
|
||||||
# UPDATE THE TVSHOW #####
|
# UPDATE THE TVSHOW #####
|
||||||
if update_item:
|
if update_item:
|
||||||
|
@ -892,13 +891,13 @@ class TVShows(Items):
|
||||||
UPDATE episode
|
UPDATE episode
|
||||||
SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
|
SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?,
|
||||||
c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
|
c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?,
|
||||||
c18 = ?, c19 = ?, idFile=?, idSeason = ?,
|
c19 = ?, idFile=?, idSeason = ?,
|
||||||
userrating = ?
|
userrating = ?
|
||||||
WHERE idEpisode = ?
|
WHERE idEpisode = ?
|
||||||
'''
|
'''
|
||||||
kodicursor.execute(query, (title, plot, ratingid, writer,
|
kodicursor.execute(query, (title, plot, ratingid, writer,
|
||||||
premieredate, runtime, director, season, episode, title,
|
premieredate, runtime, director, season, episode, title,
|
||||||
airs_before_season, airs_before_episode, playurl, pathid,
|
None, None, pathid,
|
||||||
fileid, seasonid, userdata['UserRating'], episodeid))
|
fileid, seasonid, userdata['UserRating'], episodeid))
|
||||||
else:
|
else:
|
||||||
# Kodi Jarvis
|
# Kodi Jarvis
|
||||||
|
@ -911,7 +910,7 @@ class TVShows(Items):
|
||||||
'''
|
'''
|
||||||
kodicursor.execute(query, (title, plot, rating, writer,
|
kodicursor.execute(query, (title, plot, rating, writer,
|
||||||
premieredate, runtime, director, season, episode, title,
|
premieredate, runtime, director, season, episode, title,
|
||||||
airs_before_season, airs_before_episode, playurl, pathid,
|
None, None, playurl, pathid,
|
||||||
fileid, seasonid, episodeid))
|
fileid, seasonid, episodeid))
|
||||||
# Update parentid reference
|
# Update parentid reference
|
||||||
plex_db.updateParentId(itemid, seasonid)
|
plex_db.updateParentId(itemid, seasonid)
|
||||||
|
@ -940,16 +939,16 @@ class TVShows(Items):
|
||||||
"tvdb")
|
"tvdb")
|
||||||
query = '''
|
query = '''
|
||||||
INSERT INTO episode( idEpisode, idFile, c00, c01, c03, c04,
|
INSERT INTO episode( idEpisode, idFile, c00, c01, c03, c04,
|
||||||
c05, c09, c10, c12, c13, c14, idShow, c15, c16, c18,
|
c05, c09, c10, c12, c13, c14, idShow, c15, c16,
|
||||||
c19, idSeason, userrating)
|
idSeason, userrating)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
?, ?)
|
?)
|
||||||
'''
|
'''
|
||||||
kodicursor.execute(query, (episodeid, fileid, title, plot,
|
kodicursor.execute(query, (episodeid, fileid, title, plot,
|
||||||
rating_id, writer, premieredate, runtime, director, season,
|
uniqueid, '', premieredate, runtime, director, season,
|
||||||
episode, title, showid, airs_before_season,
|
episode, title, showid, None,
|
||||||
airs_before_episode, playurl, pathid, seasonid,
|
None, seasonid,
|
||||||
userdata['UserRating']))
|
None))
|
||||||
else:
|
else:
|
||||||
# Kodi Jarvis
|
# Kodi Jarvis
|
||||||
query = '''
|
query = '''
|
||||||
|
@ -961,8 +960,8 @@ class TVShows(Items):
|
||||||
'''
|
'''
|
||||||
kodicursor.execute(query, (episodeid, fileid, title, plot,
|
kodicursor.execute(query, (episodeid, fileid, title, plot,
|
||||||
rating, writer, premieredate, runtime, director, season,
|
rating, writer, premieredate, runtime, director, season,
|
||||||
episode, title, showid, airs_before_season,
|
episode, title, showid, None,
|
||||||
airs_before_episode, playurl, pathid, seasonid))
|
None, playurl, pathid, seasonid))
|
||||||
|
|
||||||
# Create or update the reference in plex table Add reference is
|
# Create or update the reference in plex table Add reference is
|
||||||
# idempotent; the call here updates also fileid and pathid when item is
|
# idempotent; the call here updates also fileid and pathid when item is
|
||||||
|
@ -985,11 +984,27 @@ class TVShows(Items):
|
||||||
kodicursor)
|
kodicursor)
|
||||||
streams = api.mediastreams()
|
streams = api.mediastreams()
|
||||||
self.kodi_db.modify_streams(fileid, streams, runtime)
|
self.kodi_db.modify_streams(fileid, streams, runtime)
|
||||||
self.kodi_db.addPlaystate(fileid,
|
if resume:
|
||||||
resume,
|
self.kodi_db.addPlaystate(fileid,
|
||||||
runtime,
|
resume,
|
||||||
playcount,
|
runtime,
|
||||||
dateplayed)
|
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)
|
@catch_exceptions(warnuser=True)
|
||||||
def remove(self, plex_id):
|
def remove(self, plex_id):
|
||||||
|
|
|
@ -78,7 +78,7 @@ class KodiDBMethods(object):
|
||||||
'movies',
|
'movies',
|
||||||
'metadata.local',
|
'metadata.local',
|
||||||
1,
|
1,
|
||||||
0))
|
None))
|
||||||
# And TV shows
|
# And TV shows
|
||||||
path_id = self.get_path('plugin://%s.tvshows/' % v.ADDON_ID)
|
path_id = self.get_path('plugin://%s.tvshows/' % v.ADDON_ID)
|
||||||
if path_id is None:
|
if path_id is None:
|
||||||
|
@ -98,7 +98,7 @@ class KodiDBMethods(object):
|
||||||
'tvshows',
|
'tvshows',
|
||||||
'metadata.local',
|
'metadata.local',
|
||||||
1,
|
1,
|
||||||
0))
|
None))
|
||||||
|
|
||||||
def parent_path_id(self, path):
|
def parent_path_id(self, path):
|
||||||
"""
|
"""
|
||||||
|
@ -147,12 +147,12 @@ class KodiDBMethods(object):
|
||||||
pathid = self.cursor.fetchone()[0] + 1
|
pathid = self.cursor.fetchone()[0] + 1
|
||||||
query = '''
|
query = '''
|
||||||
INSERT INTO path(idPath, strPath, dateAdded, idParentPath,
|
INSERT INTO path(idPath, strPath, dateAdded, idParentPath,
|
||||||
strContent, strScraper, noUpdate)
|
strContent, strScraper, noUpdate, exclude)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
self.cursor.execute(query,
|
self.cursor.execute(query,
|
||||||
(pathid, path, date_added, id_parent_path,
|
(pathid, path, date_added, id_parent_path,
|
||||||
content, scraper, 1))
|
content, scraper, 1, None))
|
||||||
return pathid
|
return pathid
|
||||||
|
|
||||||
def add_music_path(self, path, strHash=None):
|
def add_music_path(self, path, strHash=None):
|
||||||
|
@ -733,9 +733,9 @@ class KodiDBMethods(object):
|
||||||
file_id,
|
file_id,
|
||||||
resume_seconds,
|
resume_seconds,
|
||||||
total_seconds,
|
total_seconds,
|
||||||
'',
|
None,
|
||||||
'VideoPlayer',
|
'DVDPlayer',
|
||||||
'',
|
None,
|
||||||
1))
|
1))
|
||||||
|
|
||||||
def createTag(self, name):
|
def createTag(self, name):
|
||||||
|
|
|
@ -465,11 +465,11 @@ def _playback_cleanup(ended=False):
|
||||||
DU().downloadUrl(
|
DU().downloadUrl(
|
||||||
'{server}/video/:/transcode/universal/stop',
|
'{server}/video/:/transcode/universal/stop',
|
||||||
parameters={'session': v.PKC_MACHINE_IDENTIFIER})
|
parameters={'session': v.PKC_MACHINE_IDENTIFIER})
|
||||||
if playerid == 1:
|
# if playerid == 1:
|
||||||
# Bookmarks might not be pickup up correctly, so let's do them
|
# Bookmarks might not be pickup up correctly, so let's do them
|
||||||
# manually. Applies to addon paths, but direct paths might have
|
# manually. Applies to addon paths, but direct paths might have
|
||||||
# started playback via PMS
|
# started playback via PMS
|
||||||
_record_playstate(status, ended)
|
# _record_playstate(status, ended)
|
||||||
# Reset the player's status
|
# Reset the player's status
|
||||||
state.PLAYER_STATES[playerid] = copy.deepcopy(state.PLAYSTATE)
|
state.PLAYER_STATES[playerid] = copy.deepcopy(state.PLAYSTATE)
|
||||||
# As all playback has halted, reset the players that have been active
|
# As all playback has halted, reset the players that have been active
|
||||||
|
@ -531,7 +531,7 @@ def _record_playstate(status, ended):
|
||||||
xbmc.executebuiltin('ReloadSkin()')
|
xbmc.executebuiltin('ReloadSkin()')
|
||||||
thread = Thread(target=_clean_file_table)
|
thread = Thread(target=_clean_file_table)
|
||||||
thread.setDaemon(True)
|
thread.setDaemon(True)
|
||||||
thread.start()
|
# thread.start()
|
||||||
|
|
||||||
|
|
||||||
def _clean_file_table():
|
def _clean_file_table():
|
||||||
|
|
|
@ -241,11 +241,19 @@ def _prep_playlist_stack(xml):
|
||||||
api.set_part_number(part)
|
api.set_part_number(part)
|
||||||
if kodi_id is None:
|
if kodi_id is None:
|
||||||
# Need to redirect again to PKC to conclude playback
|
# Need to redirect again to PKC to conclude playback
|
||||||
path = ('plugin://%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
|
if api.plex_type() == v.PLEX_TYPE_EPISODE:
|
||||||
% (v.ADDON_TYPE[api.plex_type()],
|
path = ('plugin://%s/%s/?plex_id=%s&plex_type=%s&mode=play&filename=%s'
|
||||||
api.plex_id(),
|
% (v.ADDON_TYPE[api.plex_type()],
|
||||||
api.plex_type(),
|
api.grandparent_id(),
|
||||||
api.file_name(force_first_media=True)))
|
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 = api.create_listitem()
|
||||||
listitem.setPath(try_encode(path))
|
listitem.setPath(try_encode(path))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue