From c61a17d48d2d9e4a525d7875b67d2f80820b7e0c Mon Sep 17 00:00:00 2001
From: angelblue05 <tamara.angel05@gmail.com>
Date: Tue, 21 Jul 2015 01:12:06 -0500
Subject: [PATCH] Resume fix

Forgot to remove old piece of code that interfered with resume point on
homescreen. Also added another verification to removed any Kodi created
bookmark as it messes with plugin paths bookmark.
---
 resources/lib/PlaybackUtils.py    |  5 +----
 resources/lib/WriteKodiVideoDB.py | 31 +++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/resources/lib/PlaybackUtils.py b/resources/lib/PlaybackUtils.py
index 71d36565..6a96ab75 100644
--- a/resources/lib/PlaybackUtils.py
+++ b/resources/lib/PlaybackUtils.py
@@ -57,10 +57,6 @@ class PlaybackUtils():
         if seekTime > jumpBackSec:
             # To avoid negative bookmark
             seekTime = seekTime - jumpBackSec
-        
-        if userData.get("PlaybackPositionTicks") != 0:
-            reasonableTicks = int(userData.get("PlaybackPositionTicks")) / 1000
-            seekTime = reasonableTicks / 10000
 
         itemsToPlay = []
         # Check for intros
@@ -137,6 +133,7 @@ class PlaybackUtils():
                 elif resume_result < 0:
                     # User cancelled dialog
                     xbmc.log("Emby player -> User cancelled resume dialog.")
+                    xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listItem)
                     return
 
         if result.get("Type")=="Episode":
diff --git a/resources/lib/WriteKodiVideoDB.py b/resources/lib/WriteKodiVideoDB.py
index 120997d1..e5279cef 100644
--- a/resources/lib/WriteKodiVideoDB.py
+++ b/resources/lib/WriteKodiVideoDB.py
@@ -153,13 +153,26 @@ class WriteKodiVideoDB():
                 filename = "plugin://plugin.video.emby/movies/%s/?filename=%s&id=%s&mode=play" % (embyId, fileext, embyId)
                 path = "plugin://plugin.video.emby/movies/%s/" % embyId
 
-                # Remove Kodi bookmark - messes with plugin path bookmark
+                # If the bookmark was created from widget
                 cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?", (fileext,))
-                try:
+                try: # Remove Kodi bookmark - messes with plugin path bookmark
                     result = cursor.fetchone()[0]
                     self.setKodiResumePoint(result, 0, 0, cursor)
                 except: pass
 
+                # If the bookmark was created within the library
+                plugindummy = "plugin://plugin.video.emby/"
+                cursor.execute("SELECT idPath FROM path WHERE strPath = ?", (plugindummy,))
+                try: 
+                    pathiddummy = cursor.fetchone()[0]
+                except: pass
+                else:
+                    cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathiddummy,))
+                    try: # Remove Kodi bookmark - creates a ghost bookmark for widgets
+                        result = cursor.fetchone()[0]
+                        self.setKodiResumePoint(result, 0, 0, cursor)
+                    except: pass
+
 
         # Validate the path in database
         cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?", (path,))
@@ -586,11 +599,25 @@ class WriteKodiVideoDB():
                 filename = "plugin://plugin.video.emby/tvshows/%s/?filename=%s&id=%s&mode=play" % (seriesId, fileext, embyId)
                 path = "plugin://plugin.video.emby/tvshows/%s/" % seriesId
 
+                # If the bookmark was created from widget
                 cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?", (fileext,))
                 try: # Remove Kodi bookmark - messes with plugin path bookmark
                     result = cursor.fetchone()[0]
                     self.setKodiResumePoint(result, 0, 0, cursor)
                 except: pass
+
+                # If the bookmark was created within the library
+                plugindummy = "plugin://plugin.video.emby/"
+                cursor.execute("SELECT idPath FROM path WHERE strPath = ?", (plugindummy,))
+                try: 
+                    pathiddummy = cursor.fetchone()[0]
+                except: pass
+                else:
+                    cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathiddummy,))
+                    try: # Remove Kodi bookmark - creates a ghost bookmark for widgets
+                        result = cursor.fetchone()[0]
+                        self.setKodiResumePoint(result, 0, 0, cursor)
+                    except: pass
         
         # Validate the path in database
         cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?", (path,))