From ced36a8de5c6472dafd9383f398fdefba33a9774 Mon Sep 17 00:00:00 2001
From: angelblue05 <tamara.angel05@gmail.com>
Date: Sun, 24 May 2015 00:56:31 -0500
Subject: [PATCH] Switch order for watched

I have been testing for the past two days. it seems to work better this
way.  That is until marcelveldt has time to go over this :) Thanks, and
I'm off!
---
 resources/lib/WriteKodiVideoDB.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/resources/lib/WriteKodiVideoDB.py b/resources/lib/WriteKodiVideoDB.py
index 78bb5e48..5d2a6cae 100644
--- a/resources/lib/WriteKodiVideoDB.py
+++ b/resources/lib/WriteKodiVideoDB.py
@@ -39,13 +39,6 @@ class WriteKodiVideoDB():
         cursor.close
 
         if(emby_id != None):
-            addon = xbmcaddon.Addon(id='plugin.video.emby')   
-            downloadUtils = DownloadUtils()       
-            watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
-            if playcount != 0:
-                downloadUtils.downloadUrl(watchedurl, type="POST")
-            else:
-                downloadUtils.downloadUrl(watchedurl, type="DELETE")
             # Erase resume point when user marks watched/unwatched to follow Emby behavior
             # Also force sets the playcount to instantly reflect the appropriate playstate.
             if type == "episode":
@@ -53,6 +46,14 @@ class WriteKodiVideoDB():
             elif type == "movie":
                 resume = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": %d, "playcount": %d, "resume": {"position": 0}}, "id": "setResumePoint"}' % (id, playcount)
             xbmc.executeJSONRPC(resume)
+            
+            addon = xbmcaddon.Addon(id='plugin.video.emby')   
+            downloadUtils = DownloadUtils()       
+            watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
+            if playcount != 0:
+                downloadUtils.downloadUrl(watchedurl, type="POST")
+            else:
+                downloadUtils.downloadUrl(watchedurl, type="DELETE")
         
     def addOrUpdateMovieToKodiLibrary( self, embyId ,connection, cursor, viewTag):