mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
add episode watched push to MBS from Kodi
This commit is contained in:
parent
bc8037d686
commit
7bd7c10a0f
4 changed files with 60 additions and 44 deletions
|
@ -39,11 +39,11 @@ 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
|
||||
if not xbmcvfs.exists(strmFile):
|
||||
changes = True
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -25,37 +25,51 @@ movieLibrary = os.path.join(dataPath,'movies')
|
|||
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()
|
||||
|
||||
print "updateplaycount called!"
|
||||
|
||||
# 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","")
|
||||
class WriteKodiDB():
|
||||
|
||||
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 updatePlayCountFromKodi(self, id, type, playcount=0):
|
||||
#when user marks item watched from kodi interface update this in MB3
|
||||
xbmc.log("WriteKodiDB -> updatePlayCountFromKodi 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","")
|
||||
|
||||
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]
|
||||
|
||||
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 ):
|
||||
|
||||
|
|
Loading…
Reference in a new issue