add episode watched push to MBS from Kodi

This commit is contained in:
faush01 2015-03-18 13:45:15 +11:00
parent bc8037d686
commit 7bd7c10a0f
4 changed files with 60 additions and 44 deletions

View file

@ -39,9 +39,9 @@ class CreateFiles():
if item_type == "Episode":
itemPath = os.path.join(tvLibrary,parentId)
if str(item.get("IndexNumber")) != None:
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + ".strm"
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").strm"
else:
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S0E0 " + item["Name"].decode('utf-8') + ".strm"
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S0E0 " + self.CleanName(item["Name"].decode('utf-8')) + " (" + item["Id"] + ").strm"
strmFile = os.path.join(itemPath,filenamestr)
changes = False
@ -81,12 +81,13 @@ class CreateFiles():
if item_type == "Episode":
itemPath = os.path.join(tvLibrary,parentId)
if str(item.get("ParentIndexNumber")) != None:
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + ".nfo"
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").nfo"
else:
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S0E0 " + item["Name"].decode('utf-8') + ".nfo"
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S0E0 " + self.CleanName(item["Name"].decode('utf-8')) + " (" + item["Id"] + ").nfo"
nfoFile = os.path.join(itemPath,filenamestr)
rootelement = "episodedetails"
changes = False
if not xbmcvfs.exists(nfoFile):
changes = True
@ -212,4 +213,6 @@ class CreateFiles():
def CleanName(self, name):
name = name.replace(":", "-")
name = name.replace("\\", "-")
name = name.replace("/", "-")
return name

View file

@ -9,11 +9,7 @@ import xbmcaddon
import json
import Utils as utils
from LibrarySync import LibrarySync
librarySync = LibrarySync()
WINDOW = xbmcgui.Window( 10000 )
from WriteKodiDB import WriteKodiDB
class Kodi_Monitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
@ -27,14 +23,16 @@ class Kodi_Monitor(xbmc.Monitor):
if method == "VideoLibrary.OnUpdate":
#check windowprop if the sync is busy to prevent any false updates
WINDOW = xbmcgui.Window( 10000 )
if WINDOW.getProperty("librarysync") != "busy":
xbmc.log("Kodi_Monitor -> onNotification -> VideoLibrary.OnUpdate : " + str(data))
jsondata = json.loads(data)
if jsondata != None:
playcount = None
playcount = jsondata.get("playcount")
item = jsondata.get("item").get("id")
type = jsondata.get("item").get("type")
if playcount != None:
librarySync.updatePlayCountFromKodi(item, playcount)
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount)

View file

@ -94,11 +94,12 @@ class ReadEmbyDB():
viewsUrl = server + "/mediabrowser/Users/" + userid + "/Views?format=json&ImageTypeLimit=1"
jsonData = DownloadUtils().downloadUrl(viewsUrl, suppress=True, popup=0 )
collections=[]
if(jsonData != ""):
views = json.loads(jsonData)
views = views.get("Items")
collections=[]
for view in views:
if view.get("Type") == 'UserView': # Need to grab the real main node
newViewsUrl = server + '/mediabrowser/Users/' + userid + '/items?ParentId=' + view.get("Id") + '&SortBy=SortName&SortOrder=Ascending&format=json&ImageTypeLimit=1'

View file

@ -26,36 +26,50 @@ tvLibrary = os.path.join(dataPath,'tvshows')
sleepVal = 10
class WriteKodiDB():
def updatePlayCountFromKodi(self, id, playcount=0):
#when user marks item watched from kodi interface update this to MB3
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
port = addon.getSetting('port')
host = addon.getSetting('ipaddress')
server = host + ":" + port
downloadUtils = DownloadUtils()
userid = downloadUtils.getUserId()
def updatePlayCountFromKodi(self, id, type, playcount=0):
#when user marks item watched from kodi interface update this in MB3
xbmc.log("WriteKodiDB -> updatePlayCountFromKodi Called")
print "updateplaycount called!"
mb3Id = None
if(type == "movie"):
mb3Id = None
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
if json_response != None:
jsonobject = json.loads(json_response.decode('utf-8','replace'))
if(jsonobject.has_key('result')):
result = jsonobject['result']
if(result.has_key('moviedetails')):
moviedetails = result['moviedetails']
filename = moviedetails.get("file").rpartition('\\')[2]
mb3Id = filename.replace(".strm","")
# TODO --> extend support for episodes
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
if json_response != None:
jsonobject = json.loads(json_response.decode('utf-8','replace'))
movie = None
if(jsonobject.has_key('result')):
result = jsonobject['result']
if(result.has_key('moviedetails')):
moviedetails = result['moviedetails']
filename = moviedetails.get("file").rpartition('\\')[2]
mb3Id = filename.replace(".strm","")
elif(type == "episode"):
mb3Id = None
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "episodeid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
if json_response != None:
jsonobject = json.loads(json_response.decode('utf-8','replace'))
if(jsonobject.has_key('result')):
result = jsonobject['result']
if(result.has_key('episodedetails')):
episodedetails = result['episodedetails']
filename = episodedetails.get("file").rpartition('\\')[2]
mb3Id = filename[-38:-6]
watchedurl = 'http://' + server + '/mediabrowser/Users/' + userid + '/PlayedItems/' + mb3Id
utils.logMsg("MB3 Sync","watchedurl -->" + watchedurl)
if playcount != 0:
downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
else:
downloadUtils.downloadUrl(watchedurl, type="DELETE")
if(mb3Id != None):
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
port = addon.getSetting('port')
host = addon.getSetting('ipaddress')
server = host + ":" + port
downloadUtils = DownloadUtils()
userid = downloadUtils.getUserId()
watchedurl = 'http://' + server + '/mediabrowser/Users/' + userid + '/PlayedItems/' + mb3Id
utils.logMsg("MB3 Sync","watchedurl -->" + watchedurl)
if playcount != 0:
downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
else:
downloadUtils.downloadUrl(watchedurl, type="DELETE")
def updateMovieToKodiLibrary( self, MBitem, KodiItem ):