Merge pull request #1617 from croneter/py3-reset-resume
Implement "Reset resume position" from the Kodi context menu
This commit is contained in:
commit
92a42a4529
2 changed files with 41 additions and 6 deletions
|
@ -602,6 +602,22 @@ class KodiVideoDB(common.KodiDBBase):
|
||||||
return
|
return
|
||||||
return movie_id, typus
|
return movie_id, typus
|
||||||
|
|
||||||
|
def file_id_from_id(self, kodi_id, kodi_type):
|
||||||
|
"""
|
||||||
|
Returns the Kodi file_id for the item with kodi_id and kodi_type or
|
||||||
|
None
|
||||||
|
"""
|
||||||
|
if kodi_type == v.KODI_TYPE_MOVIE:
|
||||||
|
identifier = 'idMovie'
|
||||||
|
elif kodi_type == v.KODI_TYPE_EPISODE:
|
||||||
|
identifier = 'idEpisode'
|
||||||
|
self.cursor.execute('SELECT idFile FROM %s WHERE %s = ? LIMIT 1'
|
||||||
|
% (kodi_type, identifier), (kodi_id, ))
|
||||||
|
try:
|
||||||
|
return self.cursor.fetchone()[0]
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def get_resume(self, file_id):
|
def get_resume(self, file_id):
|
||||||
"""
|
"""
|
||||||
Returns the first resume point in seconds (int) if found, else None for
|
Returns the first resume point in seconds (int) if found, else None for
|
||||||
|
|
|
@ -13,6 +13,7 @@ import xbmc
|
||||||
|
|
||||||
from .plex_api import API
|
from .plex_api import API
|
||||||
from .plex_db import PlexDB
|
from .plex_db import PlexDB
|
||||||
|
from .kodi_db import KodiVideoDB
|
||||||
from . import kodi_db
|
from . import kodi_db
|
||||||
from .downloadutils import DownloadUtils as DU
|
from .downloadutils import DownloadUtils as DU
|
||||||
from . import utils, timing, plex_functions as PF
|
from . import utils, timing, plex_functions as PF
|
||||||
|
@ -85,6 +86,7 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
with app.APP.lock_playqueues:
|
with app.APP.lock_playqueues:
|
||||||
self._playlist_onclear(data)
|
self._playlist_onclear(data)
|
||||||
elif method == "VideoLibrary.OnUpdate":
|
elif method == "VideoLibrary.OnUpdate":
|
||||||
|
with app.APP.lock_playqueues:
|
||||||
_videolibrary_onupdate(data)
|
_videolibrary_onupdate(data)
|
||||||
elif method == "VideoLibrary.OnRemove":
|
elif method == "VideoLibrary.OnRemove":
|
||||||
pass
|
pass
|
||||||
|
@ -651,17 +653,34 @@ def _videolibrary_onupdate(data):
|
||||||
A specific Kodi library item has been updated. This seems to happen if the
|
A specific Kodi library item has been updated. This seems to happen if the
|
||||||
user marks an item as watched/unwatched or if playback of the item just
|
user marks an item as watched/unwatched or if playback of the item just
|
||||||
stopped
|
stopped
|
||||||
|
|
||||||
|
2 kinds of messages possible, e.g.
|
||||||
|
Method: VideoLibrary.OnUpdate Data: ("Reset resume position" and also
|
||||||
|
fired just after stopping playback - BEFORE OnStop fires)
|
||||||
|
{'id': 1, 'type': 'movie'}
|
||||||
|
Method: VideoLibrary.OnUpdate Data: ("Mark as watched")
|
||||||
|
{'item': {'id': 1, 'type': 'movie'}, 'playcount': 1}
|
||||||
"""
|
"""
|
||||||
playcount = data.get('playcount')
|
item = data.get('item') if 'item' in data else data
|
||||||
item = data.get('item')
|
|
||||||
if playcount is None or item is None:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
kodi_id = item['id']
|
kodi_id = item['id']
|
||||||
kodi_type = item['type']
|
kodi_type = item['type']
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
LOG.info("Item is invalid for playstate update.")
|
LOG.debug("Item is invalid for a Plex playstate update")
|
||||||
return
|
return
|
||||||
|
playcount = data.get('playcount')
|
||||||
|
if playcount is None:
|
||||||
|
# "Reset resume position"
|
||||||
|
# Kodi might set as watched or unwatched!
|
||||||
|
with KodiVideoDB(lock=False) as kodidb:
|
||||||
|
file_id = kodidb.file_id_from_id(kodi_id, kodi_type)
|
||||||
|
if file_id is None:
|
||||||
|
return
|
||||||
|
if kodidb.get_resume(file_id):
|
||||||
|
# We do have an existing bookmark entry - not toggling to
|
||||||
|
# either watched or unwatched on the Plex side
|
||||||
|
return
|
||||||
|
playcount = kodidb.get_playcount(file_id) or 0
|
||||||
if app.PLAYSTATE.item and kodi_id == app.PLAYSTATE.item.kodi_id and \
|
if app.PLAYSTATE.item and kodi_id == app.PLAYSTATE.item.kodi_id and \
|
||||||
kodi_type == app.PLAYSTATE.item.kodi_type:
|
kodi_type == app.PLAYSTATE.item.kodi_type:
|
||||||
# Kodi updates an item immediately after playback. Hence we do NOT
|
# Kodi updates an item immediately after playback. Hence we do NOT
|
||||||
|
|
Loading…
Reference in a new issue