2015-03-13 21:24:59 +00:00
|
|
|
#################################################################################################
|
|
|
|
# LibrarySync
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
import json
|
2015-03-14 00:46:54 +00:00
|
|
|
import sqlite3
|
2015-03-16 17:51:49 +00:00
|
|
|
import inspect
|
2015-03-13 21:24:59 +00:00
|
|
|
import threading
|
|
|
|
import urllib
|
|
|
|
from datetime import datetime, timedelta, time
|
|
|
|
import urllib2
|
|
|
|
import os
|
2015-03-13 22:39:35 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
from xml.dom import minidom
|
|
|
|
import xml.etree.cElementTree as ET
|
|
|
|
|
|
|
|
from API import API
|
|
|
|
import Utils as utils
|
|
|
|
from DownloadUtils import DownloadUtils
|
2015-03-17 17:51:45 +00:00
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-14 22:33:16 +00:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
|
2015-03-13 21:24:59 +00:00
|
|
|
dataPath = os.path.join(addondir,"library")
|
2015-03-14 22:33:16 +00:00
|
|
|
movieLibrary = os.path.join(dataPath,'movies')
|
|
|
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-16 23:54:30 +00:00
|
|
|
sleepVal = 10
|
2015-03-16 07:43:20 +00:00
|
|
|
showProgress = True
|
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
processMovies = True
|
|
|
|
processTvShows = True
|
|
|
|
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
class LibrarySync():
|
|
|
|
|
|
|
|
def syncDatabase(self):
|
2015-03-14 22:33:16 +00:00
|
|
|
|
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
2015-03-16 02:32:45 +00:00
|
|
|
WINDOW.setProperty("librarysync", "busy")
|
|
|
|
pDialog = None
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
try:
|
2015-03-14 21:25:08 +00:00
|
|
|
|
2015-03-16 07:43:20 +00:00
|
|
|
if(showProgress):
|
|
|
|
pDialog = xbmcgui.DialogProgressBG()
|
2015-03-16 02:32:45 +00:00
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.create('Sync DB', 'Sync DB')
|
|
|
|
|
|
|
|
updateNeeded = False
|
2015-03-14 21:25:08 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
#process full movies sync
|
2015-03-16 23:04:29 +00:00
|
|
|
if processMovies:
|
|
|
|
allMovies = list()
|
|
|
|
|
2015-03-17 17:51:45 +00:00
|
|
|
views = ReadEmbyDB().getCollections("movies")
|
2015-03-16 23:04:29 +00:00
|
|
|
for view in views:
|
2015-03-16 03:10:41 +00:00
|
|
|
|
2015-03-17 17:51:45 +00:00
|
|
|
movieData = ReadEmbyDB().getMovies(view.get('id'), True)
|
2015-03-16 23:04:29 +00:00
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
|
|
|
|
|
|
|
if(movieData == None):
|
|
|
|
return False
|
|
|
|
|
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.update(0, "Sync DB : Processing " + view.get('title'))
|
|
|
|
total = len(movieData) + 1
|
|
|
|
count = 1
|
|
|
|
|
|
|
|
for item in movieData:
|
2015-03-16 23:54:30 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:04:29 +00:00
|
|
|
if not item.get('IsFolder'):
|
|
|
|
kodiItem = self.getKodiMovie(item["Id"])
|
|
|
|
allMovies.append(item["Id"])
|
|
|
|
progMessage = "Processing"
|
|
|
|
item['Tag'] = []
|
|
|
|
item['Tag'].append(view.get('title'))
|
|
|
|
if kodiItem == None:
|
|
|
|
self.addMovieToKodiLibrary(item)
|
|
|
|
updateNeeded = True
|
|
|
|
progMessage = "Adding"
|
|
|
|
else:
|
|
|
|
self.updateMovieToKodiLibrary(item, kodiItem)
|
|
|
|
progMessage = "Updating"
|
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# update progress bar
|
|
|
|
if(pDialog != None):
|
|
|
|
percentage = int(((float(count) / float(total)) * 100))
|
|
|
|
pDialog.update(percentage, message=progMessage + " Movie: " + str(count))
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
#process full tv shows sync
|
|
|
|
if processTvShows:
|
|
|
|
allTVShows = list()
|
|
|
|
allEpisodes = list()
|
2015-03-17 17:51:45 +00:00
|
|
|
tvShowData = ReadEmbyDB().getTVShows(True)
|
2015-03-16 23:04:29 +00:00
|
|
|
|
2015-03-16 14:29:31 +00:00
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
if (tvShowData == None):
|
|
|
|
return
|
|
|
|
|
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.update(0, "Sync DB : Processing TV Shows")
|
|
|
|
total = len(tvShowData) + 1
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
for item in tvShowData:
|
2015-03-16 23:54:30 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:04:29 +00:00
|
|
|
if item.get('IsFolder'):
|
|
|
|
kodiItem = self.getKodiTVShow(item["Id"])
|
|
|
|
allTVShows.append(item["Id"])
|
2015-03-16 14:29:31 +00:00
|
|
|
progMessage = "Processing"
|
|
|
|
if kodiItem == None:
|
2015-03-16 23:04:29 +00:00
|
|
|
self.addTVShowToKodiLibrary(item)
|
2015-03-16 14:29:31 +00:00
|
|
|
updateNeeded = True
|
|
|
|
progMessage = "Adding"
|
|
|
|
else:
|
2015-03-16 23:04:29 +00:00
|
|
|
self.updateTVShowToKodiLibrary(item, kodiItem)
|
2015-03-16 14:29:31 +00:00
|
|
|
progMessage = "Updating"
|
2015-03-16 23:04:29 +00:00
|
|
|
|
2015-03-16 14:29:31 +00:00
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
2015-03-16 23:04:29 +00:00
|
|
|
|
2015-03-16 14:29:31 +00:00
|
|
|
# update progress bar
|
|
|
|
if(pDialog != None):
|
|
|
|
percentage = int(((float(count) / float(total)) * 100))
|
2015-03-16 23:04:29 +00:00
|
|
|
pDialog.update(percentage, message=progMessage + " Tv Show: " + str(count))
|
|
|
|
count += 1
|
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
#process episodes (will only be possible when tv show is scanned to library)
|
|
|
|
#TODO --> maybe pull full info only when needed ?
|
|
|
|
allEpisodes = list()
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
for tvshow in allTVShows:
|
|
|
|
|
2015-03-17 17:51:45 +00:00
|
|
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
2015-03-16 23:04:29 +00:00
|
|
|
kodiEpisodes = self.getKodiEpisodes(tvshow)
|
|
|
|
|
2015-03-16 03:10:41 +00:00
|
|
|
if(self.ShouldStop()):
|
2015-03-16 23:04:29 +00:00
|
|
|
return True
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.update(0, "Sync DB : Processing Episodes")
|
|
|
|
total = len(episodeData) + 1
|
|
|
|
count = 0
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
#we have to compare the lists somehow
|
|
|
|
for item in episodeData:
|
2015-03-16 23:54:30 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:04:29 +00:00
|
|
|
comparestring1 = str(item.get("ParentIndexNumber")) + "-" + str(item.get("IndexNumber"))
|
|
|
|
matchFound = False
|
|
|
|
progMessage = "Processing"
|
|
|
|
if kodiEpisodes != None:
|
|
|
|
for KodiItem in kodiEpisodes:
|
|
|
|
|
|
|
|
allEpisodes.append(KodiItem["episodeid"])
|
|
|
|
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
|
|
|
if comparestring1 == comparestring2:
|
|
|
|
#match found - update episode
|
|
|
|
self.updateEpisodeToKodiLibrary(item,KodiItem,tvshow)
|
|
|
|
matchFound = True
|
|
|
|
progMessage = "Updating"
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
if not matchFound:
|
|
|
|
#no match so we have to create it
|
|
|
|
print "episode not found...creating it: "
|
|
|
|
self.addEpisodeToKodiLibrary(item,tvshow)
|
|
|
|
updateNeeded = True
|
|
|
|
progMessage = "Adding"
|
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# update progress bar
|
|
|
|
if(pDialog != None):
|
|
|
|
percentage = int(((float(count) / float(total)) * 100))
|
|
|
|
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
|
|
|
count += 1
|
2015-03-16 05:27:23 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
|
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.update(0, message="Removing Deleted Items")
|
|
|
|
|
2015-03-16 03:10:41 +00:00
|
|
|
if(self.ShouldStop()):
|
2015-03-16 07:43:20 +00:00
|
|
|
return True
|
2015-03-16 03:10:41 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
cleanNeeded = False
|
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
# process deletes for movies
|
|
|
|
if processMovies:
|
|
|
|
allLocaldirs, filesMovies = xbmcvfs.listdir(movieLibrary)
|
|
|
|
allMB3Movies = set(allMovies)
|
|
|
|
for dir in allLocaldirs:
|
|
|
|
if not dir in allMB3Movies:
|
|
|
|
self.deleteMovieFromKodiLibrary(dir)
|
|
|
|
cleanneeded = True
|
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
2015-03-16 03:10:41 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
# process deletes for episodes
|
|
|
|
if processTvShows:
|
|
|
|
# TODO --> process deletes for episodes !!!
|
|
|
|
allLocaldirs, filesTVShows = xbmcvfs.listdir(tvLibrary)
|
|
|
|
allMB3TVShows = set(allTVShows)
|
|
|
|
for dir in allLocaldirs:
|
|
|
|
if not dir in allMB3TVShows:
|
|
|
|
self.deleteTVShowFromKodiLibrary(dir)
|
|
|
|
cleanneeded = True
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 03:10:41 +00:00
|
|
|
if(self.ShouldStop()):
|
2015-03-16 07:43:20 +00:00
|
|
|
return True
|
2015-03-16 03:10:41 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
if cleanNeeded:
|
2015-03-16 05:27:23 +00:00
|
|
|
WINDOW.setProperty("cleanNeeded", "true")
|
2015-03-16 02:32:45 +00:00
|
|
|
|
|
|
|
if updateNeeded:
|
2015-03-16 05:27:23 +00:00
|
|
|
WINDOW.setProperty("updateNeeded", "true")
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
finally:
|
|
|
|
WINDOW.clearProperty("librarysync")
|
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.close()
|
2015-03-14 22:33:16 +00:00
|
|
|
|
|
|
|
return True
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
def updatePlayCounts(self):
|
|
|
|
#update all playcounts from MB3 to Kodi library
|
|
|
|
|
2015-03-14 22:33:16 +00:00
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
2015-03-13 21:24:59 +00:00
|
|
|
WINDOW.setProperty("librarysync", "busy")
|
2015-03-16 02:32:45 +00:00
|
|
|
pDialog = None
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
try:
|
2015-03-16 07:43:20 +00:00
|
|
|
if(showProgress):
|
|
|
|
pDialog = xbmcgui.DialogProgressBG()
|
2015-03-16 02:32:45 +00:00
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.create('Sync PlayCounts', 'Sync PlayCounts')
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
#process movies
|
2015-03-16 23:04:29 +00:00
|
|
|
if processMovies:
|
2015-03-17 17:51:45 +00:00
|
|
|
views = ReadEmbyDB().getCollections("movies")
|
2015-03-16 23:04:29 +00:00
|
|
|
for view in views:
|
2015-03-17 17:51:45 +00:00
|
|
|
movieData = ReadEmbyDB().getMovies(view.get('id'),False)
|
2015-03-16 23:04:29 +00:00
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
if(movieData == None):
|
|
|
|
return False
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 07:43:20 +00:00
|
|
|
if(pDialog != None):
|
2015-03-16 23:04:29 +00:00
|
|
|
pDialog.update(0, "Sync PlayCounts: Processing Movies")
|
|
|
|
totalCount = len(movieData) + 1
|
|
|
|
count = 1
|
2015-03-16 07:43:20 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
for item in movieData:
|
2015-03-17 17:25:52 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:04:29 +00:00
|
|
|
if not item.get('IsFolder'):
|
|
|
|
kodiItem = self.getKodiMovie(item["Id"])
|
|
|
|
userData=API().getUserData(item)
|
|
|
|
timeInfo = API().getTimeInfo(item)
|
|
|
|
if kodiItem != None:
|
|
|
|
self.updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"movie")
|
|
|
|
|
|
|
|
kodiresume = int(round(kodiItem['resume'].get("position")))
|
|
|
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
|
|
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
|
|
|
if kodiresume != resume:
|
|
|
|
print "updating resumepoint for movie " + str(kodiItem['movieid'])
|
|
|
|
self.setKodiResumePoint(kodiItem['movieid'],resume,total,"movie")
|
2015-03-16 02:32:45 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# update progress bar
|
|
|
|
if(pDialog != None):
|
|
|
|
percentage = int(((float(count) / float(totalCount)) * 100))
|
|
|
|
pDialog.update(percentage, message="Updating Movie: " + str(count))
|
|
|
|
count += 1
|
2015-03-16 03:10:41 +00:00
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
#process Tv shows
|
|
|
|
if processTvShows:
|
2015-03-17 17:51:45 +00:00
|
|
|
tvshowData = ReadEmbyDB().getTVShows(False)
|
2015-03-16 23:04:29 +00:00
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
|
|
|
|
|
|
|
if (tvshowData == None):
|
|
|
|
return False
|
|
|
|
|
|
|
|
for item in tvshowData:
|
2015-03-17 17:25:52 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-17 17:51:45 +00:00
|
|
|
episodeData = ReadEmbyDB().getEpisodes(item["Id"], False)
|
2015-03-16 23:04:29 +00:00
|
|
|
|
|
|
|
if (episodeData != None):
|
2015-03-16 02:32:45 +00:00
|
|
|
if(pDialog != None):
|
2015-03-16 23:04:29 +00:00
|
|
|
pDialog.update(0, "Sync PlayCounts: Processing Episodes")
|
|
|
|
totalCount = len(episodeData) + 1
|
|
|
|
count = 1
|
|
|
|
|
|
|
|
for episode in episodeData:
|
2015-03-17 17:25:52 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:04:29 +00:00
|
|
|
kodiItem = self.getKodiEpisodeByMbItem(episode)
|
|
|
|
userData=API().getUserData(episode)
|
|
|
|
timeInfo = API().getTimeInfo(episode)
|
|
|
|
if kodiItem != None:
|
|
|
|
if kodiItem['playcount'] != int(userData.get("PlayCount")):
|
|
|
|
self.updateProperty(kodiItem,"playcount",int(userData.get("PlayCount")),"episode")
|
|
|
|
kodiresume = int(round(kodiItem['resume'].get("position")))
|
|
|
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
|
|
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
|
|
|
if kodiresume != resume:
|
|
|
|
self.setKodiResumePoint(kodiItem['episodeid'],resume,total,"episode")
|
|
|
|
|
|
|
|
if(self.ShouldStop()):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# update progress bar
|
|
|
|
if(pDialog != None):
|
|
|
|
percentage = int(((float(count) / float(totalCount)) * 100))
|
|
|
|
pDialog.update(percentage, message="Updating Episode: " + str(count))
|
|
|
|
count += 1
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 02:32:45 +00:00
|
|
|
finally:
|
|
|
|
WINDOW.clearProperty("librarysync")
|
|
|
|
if(pDialog != None):
|
|
|
|
pDialog.close()
|
2015-03-14 22:33:16 +00:00
|
|
|
|
|
|
|
return True
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
def updatePlayCountFromKodi(self, id, playcount=0):
|
|
|
|
#when user marks item watched from kodi interface update this to MB3
|
2015-03-14 22:33:16 +00:00
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
print "updateplaycount called!"
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
# TODO --> extend support for episodes
|
2015-03-16 23:04:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": ' + str(id) + ', "properties" : ["playcount", "file"] }, "id": "1"}')
|
2015-03-13 21:24:59 +00:00
|
|
|
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","")
|
|
|
|
|
2015-03-14 22:33:16 +00:00
|
|
|
watchedurl = 'http://' + server + '/mediabrowser/Users/' + userid + '/PlayedItems/' + mb3Id
|
2015-03-16 21:42:53 +00:00
|
|
|
utils.logMsg("MB3 Sync","watchedurl -->" + watchedurl)
|
2015-03-13 21:24:59 +00:00
|
|
|
if playcount != 0:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, postBody="", type="POST")
|
|
|
|
else:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, type="DELETE")
|
|
|
|
|
|
|
|
def updateMovieToKodiLibrary( self, MBitem, KodiItem ):
|
|
|
|
|
2015-03-14 22:33:16 +00:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
2015-03-15 01:18:29 +00:00
|
|
|
userid = downloadUtils.getUserId()
|
2015-03-14 22:33:16 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
2015-03-14 11:26:25 +00:00
|
|
|
genre = API().getGenre(MBitem)
|
2015-03-14 17:23:45 +00:00
|
|
|
studios = API().getStudios(MBitem)
|
2015-03-13 21:24:59 +00:00
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
|
|
|
|
2015-03-14 18:10:27 +00:00
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = False
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
#update artwork
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "poster"),"movie")
|
|
|
|
changes = self.updateArtWork(KodiItem,"clearlogo", API().getArtwork(MBitem, "Logo"),"movie")
|
|
|
|
changes = self.updateArtWork(KodiItem,"clearart", API().getArtwork(MBitem, "Art"),"movie")
|
|
|
|
changes = self.updateArtWork(KodiItem,"banner", API().getArtwork(MBitem, "Banner"),"movie")
|
|
|
|
changes = self.updateArtWork(KodiItem,"landscape", API().getArtwork(MBitem, "Thumb"),"movie")
|
|
|
|
changes = self.updateArtWork(KodiItem,"discart", API().getArtwork(MBitem, "Disc"),"movie")
|
|
|
|
changes = self.updateArtWork(KodiItem,"fanart", API().getArtwork(MBitem, "Backdrop"),"movie")
|
2015-03-14 12:08:05 +00:00
|
|
|
|
|
|
|
#update common properties
|
2015-03-13 21:24:59 +00:00
|
|
|
duration = (int(timeInfo.get('Duration'))*60)
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"runtime",duration,"movie")
|
|
|
|
changes = self.updateProperty(KodiItem,"year",MBitem.get("ProductionYear"),"movie")
|
|
|
|
changes = self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"movie")
|
2015-03-16 23:04:29 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"movie")
|
2015-03-14 17:23:45 +00:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"movie")
|
2015-03-14 17:23:45 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"plotoutline",MBitem.get("ShortOverview"),"movie")
|
|
|
|
changes = self.updateProperty(KodiItem,"set",MBitem.get("TmdbCollectionName"),"movie")
|
|
|
|
changes = self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"movie")
|
2015-03-14 17:23:45 +00:00
|
|
|
|
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"movie")
|
2015-03-14 17:23:45 +00:00
|
|
|
|
|
|
|
# FIXME --> Taglines not returned by MB3 server !?
|
|
|
|
if MBitem.get("TagLines") != None:
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"tagline",MBitem.get("TagLines")[0],"movie")
|
2015-03-14 17:23:45 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"movie")
|
|
|
|
changes = self.updatePropertyArray(KodiItem,"director",people.get("Director"),"movie")
|
|
|
|
changes = self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"movie")
|
|
|
|
changes = self.updatePropertyArray(KodiItem,"studio",studios,"movie")
|
2015-03-14 17:23:45 +00:00
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
|
|
|
self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"movie")
|
|
|
|
|
2015-03-14 11:26:25 +00:00
|
|
|
#trailer link
|
|
|
|
trailerUrl = None
|
|
|
|
if MBitem.get("LocalTrailerCount") != None and MBitem.get("LocalTrailerCount") > 0:
|
|
|
|
itemTrailerUrl = "http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + MBitem.get("Id") + "/LocalTrailers?format=json"
|
2015-03-14 21:25:08 +00:00
|
|
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=True, popup=0 )
|
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = json.loads(jsonData)
|
|
|
|
trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play'
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"trailer",trailerUrl,"movie")
|
2015-03-16 14:29:31 +00:00
|
|
|
|
2015-03-14 17:23:45 +00:00
|
|
|
#add actors
|
|
|
|
self.AddActorsToMedia(KodiItem,MBitem.get("People"),"movie")
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
self.createSTRM(MBitem)
|
|
|
|
self.createNFO(MBitem)
|
2015-03-16 21:31:32 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
|
|
|
|
2015-03-14 22:43:36 +00:00
|
|
|
def updateTVShowToKodiLibrary( self, MBitem, KodiItem ):
|
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
|
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
|
|
|
|
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = False
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
#update artwork
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "Primary"),"tvshow")
|
|
|
|
changes = self.updateArtWork(KodiItem,"clearlogo", API().getArtwork(MBitem, "Logo"),"tvshow")
|
|
|
|
changes = self.updateArtWork(KodiItem,"clearart", API().getArtwork(MBitem, "Art"),"tvshow")
|
|
|
|
changes = self.updateArtWork(KodiItem,"banner", API().getArtwork(MBitem, "Banner"),"tvshow")
|
|
|
|
changes = self.updateArtWork(KodiItem,"landscape", API().getArtwork(MBitem, "Thumb"),"tvshow")
|
|
|
|
changes = self.updateArtWork(KodiItem,"discart", API().getArtwork(MBitem, "Disc"),"tvshow")
|
|
|
|
changes = self.updateArtWork(KodiItem,"fanart", API().getArtwork(MBitem, "Backdrop"),"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
#update common properties
|
2015-03-17 00:12:50 +00:00
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"premiered",premieredate,"tvshow")
|
2015-03-16 23:36:42 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"sorttitle",MBitem.get("SortName"),"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
if MBitem.get("ProviderIds") != None:
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb") != None:
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
2015-03-15 03:28:37 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"tvshow")
|
|
|
|
changes = self.updatePropertyArray(KodiItem,"studio",studios,"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"tvshow")
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
#add actors
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.AddActorsToMedia(KodiItem,MBitem.get("People"),"tvshow")
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
self.createNFO(MBitem)
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem, tvshowId ):
|
2015-03-14 22:43:36 +00:00
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
|
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
genre = API().getGenre(MBitem)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
mediaStreams=API().getMediaStreams(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
|
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = False
|
|
|
|
|
2015-03-16 23:36:42 +00:00
|
|
|
# TODO --> set season poster instead of show poster ?
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateArtWork(KodiItem,"poster", API().getArtwork(MBitem, "tvshow.poster"),"episode")
|
|
|
|
changes = self.updateArtWork(KodiItem,"fanart", API().getArtwork(MBitem, "Backdrop"),"episode")
|
|
|
|
changes = self.updateArtWork(KodiItem,"clearlogo", API().getArtwork(MBitem, "Logo"),"episode")
|
|
|
|
changes = self.updateArtWork(KodiItem,"clearart", API().getArtwork(MBitem, "Art"),"episode")
|
|
|
|
changes = self.updateArtWork(KodiItem,"banner", API().getArtwork(MBitem, "Banner"),"episode")
|
|
|
|
changes = self.updateArtWork(KodiItem,"landscape", API().getArtwork(MBitem, "Thumb"),"episode")
|
|
|
|
changes = self.updateArtWork(KodiItem,"discart", API().getArtwork(MBitem, "Disc"),"episode")
|
2015-03-16 21:36:13 +00:00
|
|
|
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
#update common properties
|
|
|
|
duration = (int(timeInfo.get('Duration'))*60)
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"runtime",duration,"episode")
|
2015-03-17 00:12:50 +00:00
|
|
|
|
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
2015-03-17 09:41:52 +00:00
|
|
|
premieretime = premieredatelist[1].split(".")[0]
|
|
|
|
firstaired = premieredate + " " + premieretime
|
|
|
|
# for Helix we use the whole time string, for kodi 15 we have to change to only the datestring
|
|
|
|
# see: http://forum.kodi.tv/showthread.php?tid=218743
|
|
|
|
if KodiItem["firstaired"] != premieredate:
|
|
|
|
self.updateProperty(KodiItem,"firstaired",firstaired,"episode")
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
if MBitem.get("CriticRating") != None:
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.updateProperty(KodiItem,"rating",int(MBitem.get("CriticRating"))/10,"episode")
|
|
|
|
|
|
|
|
changes = self.updatePropertyArray(KodiItem,"writer",people.get("Writer"),"episode")
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
#add actors
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode")
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
self.createNFO(MBitem, tvshowId)
|
|
|
|
self.createSTRM(MBitem, tvshowId)
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-14 12:08:05 +00:00
|
|
|
# adds or updates artwork to the given Kodi file in database
|
2015-03-15 17:04:01 +00:00
|
|
|
def updateArtWork(self,KodiItem,artWorkName,artworkValue, fileType):
|
2015-03-14 12:08:05 +00:00
|
|
|
if fileType == "tvshow":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['tvshowid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "art": { "%s": "%s" }}, "id": 1 }'
|
2015-03-14 12:08:05 +00:00
|
|
|
elif fileType == "episode":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['episodeid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "art": { "%s": "%s" }}, "id": 1 }'
|
2015-03-14 12:08:05 +00:00
|
|
|
elif fileType == "musicvideo":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['musicvideoid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { musicvideoid": %i, "art": { "%s": "%s" }}, "id": 1 }'
|
|
|
|
elif fileType == "movie":
|
|
|
|
id = KodiItem['movieid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "art": { "%s": "%s" }}, "id": 1 }'
|
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = False
|
2015-03-13 21:24:59 +00:00
|
|
|
if KodiItem['art'].has_key(artWorkName):
|
2015-03-14 00:46:54 +00:00
|
|
|
curValue = urllib.unquote(KodiItem['art'][artWorkName]).decode('utf8')
|
|
|
|
if not artworkValue in curValue:
|
2015-03-16 21:31:32 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 21:42:53 +00:00
|
|
|
utils.logMsg("MB3 Syncer","updating artwork..." + str(artworkValue) + " - " + str(curValue))
|
2015-03-15 03:28:37 +00:00
|
|
|
xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue))
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = True
|
2015-03-14 00:46:54 +00:00
|
|
|
elif artworkValue != None:
|
2015-03-16 21:31:32 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-15 03:28:37 +00:00
|
|
|
xbmc.executeJSONRPC(jsoncommand %(id, artWorkName, artworkValue))
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = True
|
|
|
|
|
|
|
|
return changes
|
2015-03-14 12:08:05 +00:00
|
|
|
|
|
|
|
# adds or updates the given property on the videofile in Kodi database
|
2015-03-15 17:04:01 +00:00
|
|
|
def updateProperty(self,KodiItem,propertyName,propertyValue,fileType):
|
2015-03-14 12:08:05 +00:00
|
|
|
if fileType == "tvshow":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['tvshowid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": "%s"}, "id": 1 }'
|
2015-03-14 12:08:05 +00:00
|
|
|
elif fileType == "episode":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['episodeid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": "%s"}, "id": 1 }'
|
2015-03-14 12:08:05 +00:00
|
|
|
elif fileType == "musicvideo":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['musicvideoid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": "%s"}, "id": 1 }'
|
|
|
|
elif fileType == "movie":
|
|
|
|
id = KodiItem['movieid']
|
|
|
|
jsoncommand_i = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %i}, "id": 1 }'
|
|
|
|
jsoncommand_s = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": "%s"}, "id": 1 }'
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
changes = False
|
2015-03-14 13:32:50 +00:00
|
|
|
if propertyValue != KodiItem[propertyName]:
|
2015-03-14 17:23:45 +00:00
|
|
|
if propertyValue != None:
|
|
|
|
if type(propertyValue) is int:
|
2015-03-16 21:31:32 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:54:30 +00:00
|
|
|
utils.logMsg("MB3 Sync","updating property..." + str(propertyName))
|
2015-03-16 23:36:42 +00:00
|
|
|
utils.logMsg("MB3 Sync","kodi value:" + str(KodiItem[propertyName]) + " MB value: " + str(propertyValue))
|
2015-03-15 03:28:37 +00:00
|
|
|
xbmc.executeJSONRPC(jsoncommand_i %(id, propertyName, propertyValue))
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = True
|
2015-03-14 17:23:45 +00:00
|
|
|
else:
|
2015-03-16 21:31:32 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-16 23:54:30 +00:00
|
|
|
utils.logMsg("MB3 Sync","updating property..." + str(propertyName))
|
2015-03-16 23:36:42 +00:00
|
|
|
utils.logMsg("MB3 Sync","kodi value:" + KodiItem[propertyName] + " MB value: " + propertyValue)
|
2015-03-15 03:28:37 +00:00
|
|
|
xbmc.executeJSONRPC(jsoncommand_s %(id, propertyName, propertyValue.encode('utf-8')))
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = True
|
|
|
|
|
|
|
|
return changes
|
2015-03-14 12:08:05 +00:00
|
|
|
|
2015-03-14 17:23:45 +00:00
|
|
|
# adds or updates the property-array on the videofile in Kodi database
|
2015-03-15 17:04:01 +00:00
|
|
|
def updatePropertyArray(self,KodiItem,propertyName,propertyCollection,fileType):
|
2015-03-14 13:32:50 +00:00
|
|
|
if fileType == "tvshow":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['tvshowid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetTVShowDetails", "params": { "tvshowid": %i, "%s": %s}, "id": 1 }'
|
2015-03-14 13:32:50 +00:00
|
|
|
elif fileType == "episode":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['episodeid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": %i, "%s": %s}, "id": 1 }'
|
2015-03-14 13:32:50 +00:00
|
|
|
elif fileType == "musicvideo":
|
2015-03-15 03:28:37 +00:00
|
|
|
id = KodiItem['musicvideoid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMusicVideoDetails", "params": { "musicvideoid": %i, "%s": %s}, "id": 1 }'
|
|
|
|
elif fileType == "movie":
|
|
|
|
id = KodiItem['movieid']
|
|
|
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }'
|
2015-03-14 13:32:50 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
|
2015-03-14 13:32:50 +00:00
|
|
|
pendingChanges = False
|
2015-03-14 17:23:45 +00:00
|
|
|
if propertyCollection != None:
|
|
|
|
currentvalues = set(KodiItem[propertyName])
|
2015-03-14 13:32:50 +00:00
|
|
|
genrestring = ""
|
2015-03-14 17:23:45 +00:00
|
|
|
for item in propertyCollection:
|
|
|
|
if not item in currentvalues:
|
2015-03-14 13:32:50 +00:00
|
|
|
pendingChanges = True
|
2015-03-14 17:23:45 +00:00
|
|
|
json_array = json.dumps(propertyCollection)
|
2015-03-14 13:32:50 +00:00
|
|
|
|
|
|
|
if pendingChanges:
|
2015-03-16 21:31:32 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-17 02:33:20 +00:00
|
|
|
utils.logMsg("MB3 Sync","updating propertyarray... Name:" + str(propertyName) + " Current:" + str(currentvalues) + " New:" + str(json_array))
|
2015-03-17 09:41:52 +00:00
|
|
|
xbmc.executeJSONRPC(jsoncommand %(id,propertyName,json_array))
|
|
|
|
|
|
|
|
return pendingChanges
|
2015-03-16 09:15:26 +00:00
|
|
|
|
|
|
|
def CleanName(self, name):
|
|
|
|
name = name.replace(":", "-")
|
|
|
|
return name
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
def createSTRM(self,item,parentId=None):
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
item_type=str(item.get("Type")).encode('utf-8')
|
|
|
|
if item_type == "Movie":
|
|
|
|
itemPath = os.path.join(movieLibrary,item["Id"])
|
|
|
|
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
|
|
|
|
|
|
|
if item_type == "MusicVideo":
|
|
|
|
itemPath = os.path.join(musicVideoLibrary,item["Id"])
|
|
|
|
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
|
|
|
|
|
|
|
if item_type == "Episode":
|
|
|
|
itemPath = os.path.join(tvLibrary,parentId)
|
|
|
|
if str(item.get("IndexNumber")) != None:
|
2015-03-16 09:15:26 +00:00
|
|
|
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + ".strm"
|
2015-03-15 17:04:01 +00:00
|
|
|
else:
|
2015-03-16 21:31:32 +00:00
|
|
|
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S0E0 " + item["Name"].decode('utf-8') + ".strm"
|
2015-03-15 17:04:01 +00:00
|
|
|
strmFile = os.path.join(itemPath,filenamestr)
|
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = False
|
2015-03-15 17:04:01 +00:00
|
|
|
if not xbmcvfs.exists(strmFile):
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = True
|
2015-03-13 21:24:59 +00:00
|
|
|
xbmcvfs.mkdir(itemPath)
|
2015-03-15 17:04:01 +00:00
|
|
|
text_file = open(strmFile, "w")
|
|
|
|
|
|
|
|
playUrl = "plugin://plugin.video.mb3sync/?id=" + item["Id"] + '&mode=play'
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
text_file.writelines(playUrl)
|
|
|
|
text_file.close()
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
return changes
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
def createNFO(self,item, parentId=None):
|
2015-03-16 21:31:32 +00:00
|
|
|
downloadUtils = DownloadUtils()
|
2015-03-13 21:24:59 +00:00
|
|
|
timeInfo = API().getTimeInfo(item)
|
|
|
|
userData=API().getUserData(item)
|
|
|
|
people = API().getPeople(item)
|
|
|
|
mediaStreams=API().getMediaStreams(item)
|
2015-03-16 21:31:32 +00:00
|
|
|
studios = API().getStudios(item)
|
|
|
|
userid = downloadUtils.getUserId()
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
item_type=str(item.get("Type"))
|
2015-03-15 01:18:29 +00:00
|
|
|
|
|
|
|
if item_type == "Movie":
|
|
|
|
itemPath = os.path.join(movieLibrary,item["Id"])
|
|
|
|
nfoFile = os.path.join(itemPath,item["Id"] + ".nfo")
|
|
|
|
rootelement = "movie"
|
|
|
|
if item_type == "Series":
|
|
|
|
itemPath = os.path.join(tvLibrary,item["Id"])
|
|
|
|
nfoFile = os.path.join(itemPath,"tvshow.nfo")
|
|
|
|
rootelement = "tvshow"
|
|
|
|
if item_type == "Episode":
|
2015-03-15 17:04:01 +00:00
|
|
|
itemPath = os.path.join(tvLibrary,parentId)
|
|
|
|
if str(item.get("ParentIndexNumber")) != None:
|
2015-03-16 09:15:26 +00:00
|
|
|
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + ".nfo"
|
2015-03-15 17:04:01 +00:00
|
|
|
else:
|
2015-03-16 21:31:32 +00:00
|
|
|
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S0E0 " + item["Name"].decode('utf-8') + ".nfo"
|
2015-03-15 17:04:01 +00:00
|
|
|
nfoFile = os.path.join(itemPath,filenamestr)
|
2015-03-15 01:18:29 +00:00
|
|
|
rootelement = "episodedetails"
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = False
|
2015-03-15 17:04:01 +00:00
|
|
|
if not xbmcvfs.exists(nfoFile):
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = True
|
|
|
|
utils.logMsg("MB3 Syncer","creating NFO file " + nfoFile)
|
2015-03-15 17:04:01 +00:00
|
|
|
xbmcvfs.mkdir(itemPath)
|
|
|
|
root = Element(rootelement)
|
|
|
|
SubElement(root, "id").text = item["Id"]
|
2015-03-16 14:29:31 +00:00
|
|
|
if item.get("Tag") != None:
|
2015-03-16 23:04:29 +00:00
|
|
|
for tag in item.get("Tag"):
|
|
|
|
SubElement(root, "tag").text = tag
|
2015-03-16 21:31:32 +00:00
|
|
|
|
|
|
|
SubElement(root, "thumb").text = API().getArtwork(item, "Primary")
|
2015-03-15 17:04:01 +00:00
|
|
|
SubElement(root, "fanart").text = API().getArtwork(item, "Backdrop")
|
2015-03-16 21:31:32 +00:00
|
|
|
SubElement(root, "title").text = utils.convertEncoding(item["Name"])
|
|
|
|
SubElement(root, "originaltitle").text = utils.convertEncoding(item["Name"])
|
|
|
|
SubElement(root, "sorttitle").text = utils.convertEncoding(item["SortName"])
|
|
|
|
|
|
|
|
if item.has_key("OfficialRating"):
|
|
|
|
SubElement(root, "mpaa").text = item["OfficialRating"]
|
|
|
|
|
|
|
|
if item.get("CriticRating") != None:
|
|
|
|
rating = int(item.get("CriticRating"))/10
|
|
|
|
SubElement(root, "rating").text = str(rating)
|
|
|
|
|
|
|
|
if item.get("DateCreated") != None:
|
|
|
|
SubElement(root, "dateadded").text = item["DateCreated"]
|
|
|
|
|
|
|
|
if userData.get("PlayCount") != None:
|
|
|
|
SubElement(root, "playcount").text = userData.get("PlayCount")
|
|
|
|
if int(userData.get("PlayCount")) > 0:
|
|
|
|
SubElement(root, "watched").text = "true"
|
|
|
|
|
|
|
|
if timeInfo.get("ResumeTime") != None:
|
|
|
|
resume_sec = int(round(float(timeInfo.get("ResumeTime"))))*60
|
|
|
|
total_sec = int(round(float(timeInfo.get("TotalTime"))))*60
|
|
|
|
resume = SubElement(root, "resume")
|
|
|
|
SubElement(resume, "position").text = str(resume_sec)
|
|
|
|
SubElement(resume, "total").text = str(total_sec)
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
if item_type == "Episode":
|
|
|
|
SubElement(root, "season").text = str(item.get("ParentIndexNumber"))
|
|
|
|
SubElement(root, "episode").text = str(item.get("IndexNumber"))
|
|
|
|
SubElement(root, "aired").text = str(item.get("ProductionYear"))
|
|
|
|
|
|
|
|
SubElement(root, "year").text = str(item.get("ProductionYear"))
|
2015-03-17 00:12:50 +00:00
|
|
|
if item.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (item.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
|
|
|
SubElement(root, "firstaired").text = premieredate
|
|
|
|
SubElement(root, "premieredate").text = premieredate
|
2015-03-17 02:33:20 +00:00
|
|
|
|
|
|
|
if(timeInfo.get('Duration') != "0"):
|
|
|
|
SubElement(root, "runtime").text = str(timeInfo.get('Duration'))
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-16 21:31:32 +00:00
|
|
|
SubElement(root, "plot").text = utils.convertEncoding(API().getOverview(item))
|
|
|
|
|
|
|
|
if item.get("ShortOverview") != None:
|
|
|
|
SubElement(root, "plotoutline").text = utils.convertEncoding(item.get("ShortOverview"))
|
|
|
|
|
|
|
|
if item.get("TmdbCollectionName") != None:
|
|
|
|
SubElement(root, "set").text = item.get("TmdbCollectionName")
|
|
|
|
|
|
|
|
if item.get("ProviderIds") != None:
|
|
|
|
if item.get("ProviderIds").get("Imdb") != None:
|
|
|
|
SubElement(root, "imdbnumber").text = item
|
|
|
|
|
|
|
|
if people.get("Writer") != None:
|
|
|
|
for writer in people.get("Writer"):
|
|
|
|
SubElement(root, "writer").text = utils.convertEncoding(writer)
|
|
|
|
|
|
|
|
if people.get("Director") != None:
|
|
|
|
for director in people.get("Director"):
|
|
|
|
SubElement(root, "director").text = utils.convertEncoding(director)
|
|
|
|
|
|
|
|
if item.get("Genres") != None:
|
|
|
|
for genre in item.get("Genres"):
|
|
|
|
SubElement(root, "genre").text = utils.convertEncoding(genre)
|
|
|
|
|
|
|
|
if studios != None:
|
|
|
|
for studio in studios:
|
|
|
|
SubElement(root, "studio").text = utils.convertEncoding(studio)
|
|
|
|
|
|
|
|
if item.get("ProductionLocations") != None:
|
|
|
|
for country in item.get("ProductionLocations"):
|
|
|
|
SubElement(root, "country").text = utils.convertEncoding(country)
|
|
|
|
|
|
|
|
#trailer link
|
|
|
|
trailerUrl = None
|
|
|
|
if item.get("LocalTrailerCount") != None and item.get("LocalTrailerCount") > 0:
|
|
|
|
itemTrailerUrl = "http://" + server + "/mediabrowser/Users/" + userid + "/Items/" + item.get("Id") + "/LocalTrailers?format=json"
|
|
|
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl, suppress=True, popup=0 )
|
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = json.loads(jsonData)
|
|
|
|
trailerUrl = "plugin://plugin.video.mb3sync/?id=" + trailerItem[0].get("Id") + '&mode=play'
|
|
|
|
SubElement(root, "trailer").text = trailerUrl
|
|
|
|
|
|
|
|
#add streamdetails
|
2015-03-15 17:04:01 +00:00
|
|
|
fileinfo = SubElement(root, "fileinfo")
|
|
|
|
streamdetails = SubElement(fileinfo, "streamdetails")
|
|
|
|
video = SubElement(streamdetails, "video")
|
|
|
|
SubElement(video, "duration").text = str(mediaStreams.get('totaltime'))
|
|
|
|
SubElement(video, "aspect").text = mediaStreams.get('aspectratio')
|
|
|
|
SubElement(video, "codec").text = mediaStreams.get('videocodec')
|
|
|
|
SubElement(video, "width").text = str(mediaStreams.get('width'))
|
|
|
|
SubElement(video, "height").text = str(mediaStreams.get('height'))
|
2015-03-16 21:31:32 +00:00
|
|
|
SubElement(video, "duration").text = str(timeInfo.get('Duration'))
|
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
audio = SubElement(streamdetails, "audio")
|
|
|
|
SubElement(audio, "codec").text = mediaStreams.get('audiocodec')
|
|
|
|
SubElement(audio, "channels").text = mediaStreams.get('channels')
|
2015-03-16 21:31:32 +00:00
|
|
|
|
|
|
|
#add people
|
|
|
|
if item.get("People") != None:
|
|
|
|
for actor in item.get("People"):
|
|
|
|
if(actor.get("Type") == "Actor"):
|
|
|
|
actor_elem = SubElement(root, "actor")
|
|
|
|
SubElement(actor_elem, "name").text = utils.convertEncoding(actor.get("Name"))
|
|
|
|
SubElement(actor_elem, "type").text = utils.convertEncoding(actor.get("Role"))
|
|
|
|
SubElement(actor_elem, "thumb").text = downloadUtils.imageUrl(actor.get("Id"), "Primary", 0, 400, 400)
|
2015-03-17 09:41:52 +00:00
|
|
|
|
2015-03-16 21:31:32 +00:00
|
|
|
ET.ElementTree(root).write(nfoFile, xml_declaration=True)
|
2015-03-17 09:41:52 +00:00
|
|
|
return changes
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
def addMovieToKodiLibrary( self, item ):
|
|
|
|
itemPath = os.path.join(movieLibrary,item["Id"])
|
|
|
|
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
changes = False
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
#create path if not exists
|
2015-03-15 01:18:29 +00:00
|
|
|
if not xbmcvfs.exists(itemPath + os.sep):
|
2015-03-13 21:24:59 +00:00
|
|
|
xbmcvfs.mkdir(itemPath)
|
2015-03-17 09:41:52 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
#create nfo file
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.createNFO(item)
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
# create strm file
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.createSTRM(item)
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
def addEpisodeToKodiLibrary(self, item, tvshowId):
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
changes = False
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
#create nfo file
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.createNFO(item, tvshowId)
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
# create strm file
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.createSTRM(item, tvshowId)
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
|
2015-03-15 17:04:01 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def deleteMovieFromKodiLibrary(self, id ):
|
|
|
|
kodiItem = self.getKodiMovie(id)
|
|
|
|
utils.logMsg("deleting movie from Kodi library",id)
|
|
|
|
if kodiItem != None:
|
2015-03-16 23:04:29 +00:00
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"]))
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
path = os.path.join(movieLibrary,id)
|
|
|
|
xbmcvfs.rmdir(path)
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
def addTVShowToKodiLibrary( self, item ):
|
|
|
|
itemPath = os.path.join(tvLibrary,item["Id"])
|
2015-03-17 09:41:52 +00:00
|
|
|
|
|
|
|
changes = False
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
#create path if not exists
|
2015-03-15 01:18:29 +00:00
|
|
|
if not xbmcvfs.exists(itemPath + os.sep):
|
2015-03-14 22:43:36 +00:00
|
|
|
xbmcvfs.mkdir(itemPath)
|
|
|
|
|
|
|
|
#create nfo file
|
2015-03-17 09:41:52 +00:00
|
|
|
changes = self.createNFO(item)
|
|
|
|
|
|
|
|
if changes:
|
|
|
|
utils.logMsg("Added TV Show to Kodi Library ",item["Id"] + " - " + item["Name"])
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
def deleteTVShowFromKodiLibrary(self, id ):
|
|
|
|
kodiItem = self.getKodiTVShow(id)
|
|
|
|
utils.logMsg("deleting tvshow from Kodi library",id)
|
|
|
|
if kodiItem != None:
|
2015-03-16 23:04:29 +00:00
|
|
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"]))
|
2015-03-14 22:43:36 +00:00
|
|
|
path = os.path.join(tvLibrary,id)
|
|
|
|
xbmcvfs.rmdir(path)
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-03-15 17:04:01 +00:00
|
|
|
def setKodiResumePoint(self, id, resume_seconds, total_seconds, fileType):
|
2015-03-14 00:46:54 +00:00
|
|
|
#use sqlite to set the resume point while json api doesn't support this yet
|
|
|
|
#todo --> submit PR to kodi team to get this added to the jsonrpc api
|
2015-03-16 23:54:30 +00:00
|
|
|
|
|
|
|
utils.logMsg("MB3 Sync","setting resume point in kodi db..." + fileType + ": " + str(id))
|
|
|
|
|
2015-03-14 00:46:54 +00:00
|
|
|
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
|
|
|
|
connection = sqlite3.connect(dbPath)
|
|
|
|
cursor = connection.cursor( )
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
if fileType == "episode":
|
|
|
|
cursor.execute("SELECT idFile as fileidid FROM episode WHERE idEpisode = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
fileid = result[0]
|
|
|
|
if fileType == "movie":
|
|
|
|
cursor.execute("SELECT idFile as fileidid FROM movie WHERE idMovie = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
fileid = result[0]
|
|
|
|
|
|
|
|
cursor.execute("delete FROM bookmark WHERE idFile = ?", (fileid,))
|
2015-03-14 00:46:54 +00:00
|
|
|
cursor.execute("select coalesce(max(idBookmark),0) as bookmarkId from bookmark")
|
|
|
|
bookmarkId = cursor.fetchone()[0]
|
|
|
|
bookmarkId = bookmarkId + 1
|
|
|
|
bookmarksql="insert into bookmark(idBookmark, idFile, timeInSeconds, totalTimeInSeconds, thumbNailImage, player, playerState, type) values(?, ?, ?, ?, ?, ?, ?, ?)"
|
2015-03-15 17:04:01 +00:00
|
|
|
cursor.execute(bookmarksql, (bookmarkId,fileid,resume_seconds,total_seconds,None,"DVDPlayer",None,1))
|
2015-03-14 00:46:54 +00:00
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
|
|
|
|
2015-03-14 17:23:45 +00:00
|
|
|
def AddActorsToMedia(self, KodiItem, people, mediatype):
|
|
|
|
#use sqlite to set add the actors while json api doesn't support this yet
|
|
|
|
#todo --> submit PR to kodi team to get this added to the jsonrpc api
|
|
|
|
|
2015-03-14 22:33:16 +00:00
|
|
|
downloadUtils = DownloadUtils()
|
2015-03-15 03:28:37 +00:00
|
|
|
if mediatype == "movie":
|
|
|
|
id = KodiItem["movieid"]
|
|
|
|
if mediatype == "tvshow":
|
|
|
|
id = KodiItem["tvshowid"]
|
|
|
|
if mediatype == "episode":
|
|
|
|
id = KodiItem["episodeid"]
|
|
|
|
|
2015-03-14 22:33:16 +00:00
|
|
|
|
2015-03-14 17:23:45 +00:00
|
|
|
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos90.db")
|
|
|
|
connection = sqlite3.connect(dbPath)
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
|
|
|
currentcast = list()
|
|
|
|
if KodiItem["cast"] != None:
|
|
|
|
for cast in KodiItem["cast"]:
|
|
|
|
currentcast.append(cast["name"])
|
|
|
|
|
|
|
|
if(people != None):
|
|
|
|
for person in people:
|
|
|
|
if(person.get("Type") == "Actor"):
|
|
|
|
if person.get("Name") not in currentcast:
|
|
|
|
Name = person.get("Name")
|
|
|
|
Role = person.get("Role")
|
|
|
|
actorid = None
|
|
|
|
Thumb = downloadUtils.imageUrl(person.get("Id"), "Primary", 0, 400, 400)
|
|
|
|
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ?",(Name,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
actorid = result[0]
|
|
|
|
if actorid == None:
|
|
|
|
cursor.execute("select coalesce(max(idActor),0) as actorid from actors")
|
|
|
|
actorid = cursor.fetchone()[0]
|
|
|
|
actorid = actorid + 1
|
|
|
|
peoplesql="insert into actors(idActor, strActor, strThumb) values(?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid,Name,Thumb))
|
|
|
|
|
|
|
|
if mediatype == "movie":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinkmovie(idActor, idMovie, strRole, iOrder) values(?, ?, ?, ?)"
|
|
|
|
if mediatype == "tvshow":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinktvshow(idActor, idShow, strRole, iOrder) values(?, ?, ?, ?)"
|
|
|
|
if mediatype == "episode":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinkepisode(idActor, idEpisode, strRole, iOrder) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid,id,Role,None))
|
|
|
|
|
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def getKodiMovie(self, id):
|
2015-03-16 23:04:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties" : ["art", "rating", "thumbnail", "resume", "runtime", "year", "genre", "cast", "trailer", "country", "studio", "set", "imdbnumber", "mpaa", "tagline", "plotoutline","plot", "sorttitle", "director", "writer", "playcount", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}')
|
2015-03-13 21:24:59 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
movie = None
|
|
|
|
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('movies')):
|
|
|
|
movies = result['movies']
|
|
|
|
movie = movies[0]
|
|
|
|
|
|
|
|
return movie
|
2015-03-14 22:43:36 +00:00
|
|
|
|
|
|
|
def getKodiTVShow(self, id):
|
2015-03-17 00:00:28 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
2015-03-14 22:43:36 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
tvshow = None
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('tvshows')):
|
|
|
|
tvshows = result['tvshows']
|
|
|
|
tvshow = tvshows[0]
|
|
|
|
return tvshow
|
2015-03-15 17:04:01 +00:00
|
|
|
|
|
|
|
def getKodiEpisodes(self, id):
|
|
|
|
episodes = None
|
2015-03-16 23:36:42 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["sorttitle", "title", "originaltitle", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
2015-03-15 17:04:01 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
tvshow = None
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('tvshows')):
|
|
|
|
tvshows = result['tvshows']
|
|
|
|
tvshow = tvshows[0]
|
|
|
|
|
2015-03-16 23:04:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "plot", "season", "episode", "showtitle", "file", "lastplayed", "rating", "resume", "art", "streamdetails", "firstaired", "runtime", "writer", "cast", "dateadded"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
2015-03-15 17:04:01 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
episodes = None
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('episodes')):
|
|
|
|
episodes = result['episodes']
|
|
|
|
return episodes
|
|
|
|
|
|
|
|
def getKodiEpisodeByMbItem(self, MBitem):
|
2015-03-16 23:04:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "is", "field": "title", "value": "' + MBitem.get("SeriesName").encode('utf-8') + '"} }, "id": "libTvShows"}')
|
2015-03-15 17:04:01 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
episode = None
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('tvshows')):
|
|
|
|
tvshows = result['tvshows']
|
|
|
|
tvshow = tvshows[0]
|
|
|
|
|
|
|
|
# find the episode by combination of season and episode
|
2015-03-16 23:04:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["playcount","season", "resume", "episode"], "sort": {"method": "episode"}}, "id": 1}' %tvshow['tvshowid'])
|
2015-03-15 17:04:01 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
episodes = None
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('episodes')):
|
|
|
|
episodes = result['episodes']
|
|
|
|
|
|
|
|
comparestring1 = str(MBitem.get("ParentIndexNumber")) + "-" + str(MBitem.get("IndexNumber"))
|
|
|
|
for item in episodes:
|
|
|
|
comparestring2 = str(item["season"]) + "-" + str(item["episode"])
|
|
|
|
if comparestring1 == comparestring2:
|
|
|
|
episode = item
|
|
|
|
|
2015-03-15 17:14:23 +00:00
|
|
|
return episode
|
|
|
|
|
2015-03-16 03:10:41 +00:00
|
|
|
def ShouldStop(self):
|
|
|
|
if(xbmc.Player().isPlaying() or xbmc.abortRequested):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2015-03-16 17:51:49 +00:00
|
|
|
|
|
|
|
def executeJSONRPC(self, command):
|
|
|
|
print "ExecuteJSONRPC called!"
|
|
|
|
print inspect.stack()[1][3]
|
|
|
|
return xbmc.executeJSONRPC(command)
|
2015-03-15 17:14:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|