2015-03-17 18:41:26 +00:00
|
|
|
#################################################################################################
|
|
|
|
# ReadKodiDB
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import json
|
2015-03-18 15:47:55 +00:00
|
|
|
import os
|
|
|
|
|
2015-04-01 19:07:29 +00:00
|
|
|
import Utils as utils
|
|
|
|
|
2015-03-17 18:41:26 +00:00
|
|
|
|
2015-03-19 10:13:49 +00:00
|
|
|
#sleepval is used to throttle the calls to the xbmc json API
|
|
|
|
sleepVal = 15
|
|
|
|
|
2015-03-17 18:41:26 +00:00
|
|
|
class ReadKodiDB():
|
2015-03-29 20:13:11 +00:00
|
|
|
|
2015-03-17 18:41:26 +00:00
|
|
|
def getKodiMovie(self, id):
|
2015-03-18 15:47:55 +00:00
|
|
|
#returns a single movie from Kodi db selected on MB item ID
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-29 20:13:11 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties" : ["art", "rating", "thumbnail", "resume", "runtime", "year", "genre", "cast", "trailer", "country", "studio", "set", "imdbnumber", "mpaa", "tagline", "plotoutline","plot", "sorttitle", "director", "lastplayed", "writer", "playcount", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}')
|
2015-03-17 18:41:26 +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]
|
2015-03-29 20:13:11 +00:00
|
|
|
for item in movies:
|
|
|
|
if item["imdbnumber"] == id:
|
|
|
|
movie = item
|
|
|
|
break
|
2015-03-17 18:41:26 +00:00
|
|
|
return movie
|
|
|
|
|
2015-03-28 16:42:38 +00:00
|
|
|
def getEmbyIdByKodiId(self, kodiid, type):
|
|
|
|
#returns the emby id by search on kodi id
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
|
|
|
|
embyId = None
|
2015-04-01 19:07:29 +00:00
|
|
|
json_response = None
|
2015-03-28 16:42:38 +00:00
|
|
|
|
|
|
|
if type == "movie":
|
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": %d, "properties" : ["imdbnumber","file"] }, "id": "libMovies"}' %kodiid)
|
|
|
|
if type == "episode":
|
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": %d, "properties": ["file","uniqueid"]}, "id": 1}' %kodiid)
|
2015-04-01 19:07:29 +00:00
|
|
|
if type == "musicvideo":
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("SELECT c23 as MBid FROM musicvideo WHERE idMVideo = ?",(kodiid,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
cursor.close()
|
|
|
|
if result != None:
|
|
|
|
embyId = result[0]
|
2015-03-28 16:42:38 +00:00
|
|
|
|
|
|
|
if json_response != None:
|
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
resulttype = type + "details"
|
|
|
|
if(result.has_key(resulttype)):
|
|
|
|
item = result[resulttype]
|
|
|
|
if type == "movie":
|
|
|
|
if item.has_key('imdbnumber'):
|
|
|
|
embyId = item['imdbnumber']
|
|
|
|
if type == "episode":
|
|
|
|
if item.has_key('uniqueid'):
|
|
|
|
if item['uniqueid'].has_key('unknown'):
|
|
|
|
embyId = item["uniqueid"]["unknown"]
|
|
|
|
|
2015-04-01 19:07:29 +00:00
|
|
|
return embyId
|
2015-03-28 16:42:38 +00:00
|
|
|
|
2015-03-18 15:47:55 +00:00
|
|
|
def getKodiMovies(self,fullInfo = False):
|
2015-03-28 16:42:38 +00:00
|
|
|
#returns all movies in Kodi db
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-18 15:47:55 +00:00
|
|
|
if fullInfo:
|
2015-03-28 16:42:38 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties" : ["art", "rating", "thumbnail", "resume", "runtime", "year", "genre", "cast", "trailer", "country", "lastplayed", "studio", "set", "imdbnumber", "mpaa", "tagline", "plotoutline","plot", "sorttitle", "director", "writer", "playcount", "tag", "file"] }, "id": "libMovies"}')
|
2015-03-18 15:47:55 +00:00
|
|
|
else:
|
2015-03-28 16:42:38 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties" : ["resume", "playcount", "imdbnumber", "lastplayed", "file"] }, "id": "libMovies"}')
|
2015-03-18 15:47:55 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
movies = None
|
|
|
|
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('movies')):
|
|
|
|
movies = result['movies']
|
|
|
|
|
2015-03-20 03:04:54 +00:00
|
|
|
kodiMovieMap = None
|
|
|
|
if(movies != None and len(movies) > 0):
|
|
|
|
kodiMovieMap = {}
|
|
|
|
for kodimovie in movies:
|
2015-03-28 16:42:38 +00:00
|
|
|
key = kodimovie["imdbnumber"] #extract the id from the imdbnumber
|
2015-03-20 03:04:54 +00:00
|
|
|
kodiMovieMap[key] = kodimovie
|
|
|
|
|
|
|
|
return kodiMovieMap
|
2015-03-18 15:47:55 +00:00
|
|
|
|
|
|
|
def getKodiMoviesIds(self,returnMB3Ids = False):
|
|
|
|
# returns a list of movieIds or MB3 Id's from all movies currently in the Kodi library
|
|
|
|
allKodiMovies = self.getKodiMovies(False)
|
|
|
|
|
2015-03-20 03:04:54 +00:00
|
|
|
if(allKodiMovies == None):
|
|
|
|
return list()
|
|
|
|
|
|
|
|
if(returnMB3Ids):
|
|
|
|
allKodiMovieIds = list(allKodiMovies.keys())
|
|
|
|
return allKodiMovieIds
|
|
|
|
else:
|
|
|
|
allKodiMovieIds = list()
|
|
|
|
for kodimovie in allKodiMovies.values():
|
|
|
|
id = str(kodimovie["movieid"])
|
2015-03-18 15:47:55 +00:00
|
|
|
allKodiMovieIds.append(id)
|
|
|
|
|
2015-03-20 03:04:54 +00:00
|
|
|
return allKodiMovieIds
|
2015-03-18 15:47:55 +00:00
|
|
|
|
2015-03-18 17:00:38 +00:00
|
|
|
def getKodiTvShowsIds(self,returnMB3Ids = False):
|
|
|
|
# returns a list of tvshowIds or MB3 Id's from all tvshows currently in the Kodi library
|
|
|
|
allKodiTvShows = self.getKodiTvShows(False)
|
|
|
|
|
2015-03-20 12:27:02 +00:00
|
|
|
if allKodiTvShows == None:
|
|
|
|
return list()
|
|
|
|
|
|
|
|
if(returnMB3Ids):
|
|
|
|
allKodiTvShowsIds = list(allKodiTvShows.keys())
|
|
|
|
return allKodiTvShowsIds
|
|
|
|
else:
|
|
|
|
allKodiTvShowsIds = list()
|
|
|
|
for kodishow in allKodiTvShows.values():
|
|
|
|
id = str(kodishow["tvshowid"])
|
2015-03-18 17:00:38 +00:00
|
|
|
allKodiTvShowsIds.append(id)
|
|
|
|
|
2015-03-20 12:27:02 +00:00
|
|
|
return allKodiTvShowsIds
|
2015-03-20 10:08:22 +00:00
|
|
|
|
2015-03-18 17:00:38 +00:00
|
|
|
def getKodiTvShows(self,fullInfo = False):
|
|
|
|
#returns all tvshows in Kodi db inserted by MB
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-18 17:00:38 +00:00
|
|
|
if fullInfo:
|
2015-04-04 21:48:02 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "lastplayed", "file", "fanart", "tag"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
2015-03-18 17:00:38 +00:00
|
|
|
else:
|
2015-03-29 17:13:21 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["sorttitle", "title", "playcount", "lastplayed", "imdbnumber", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
2015-03-18 17:00:38 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
tvshows = None
|
2015-03-18 17:43:57 +00:00
|
|
|
|
2015-03-18 17:00:38 +00:00
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('tvshows')):
|
2015-03-18 17:43:57 +00:00
|
|
|
tvshows = result['tvshows']
|
2015-03-18 17:00:38 +00:00
|
|
|
|
2015-03-20 12:27:02 +00:00
|
|
|
kodiShowMap = None
|
|
|
|
if(tvshows != None and len(tvshows) > 0):
|
|
|
|
kodiShowMap = {}
|
|
|
|
for kodishow in tvshows:
|
2015-03-29 16:20:02 +00:00
|
|
|
key = kodishow["imdbnumber"] #extract the id from the imdb number
|
2015-03-20 12:27:02 +00:00
|
|
|
kodiShowMap[key] = kodishow
|
|
|
|
|
|
|
|
return kodiShowMap
|
2015-03-18 17:00:38 +00:00
|
|
|
|
2015-03-17 18:41:26 +00:00
|
|
|
def getKodiTVShow(self, id):
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-04 21:48:02 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "lastplayed", "premiered", "rating", "thumbnail", "playcount", "file", "fanart", "tag"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
2015-03-17 18:41:26 +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']
|
2015-03-29 20:13:11 +00:00
|
|
|
for show in tvshows:
|
|
|
|
if show["imdbnumber"] == id:
|
|
|
|
tvshow = show
|
|
|
|
break
|
2015-03-17 18:41:26 +00:00
|
|
|
return tvshow
|
|
|
|
|
2015-03-29 17:13:21 +00:00
|
|
|
def getKodiEpisodes(self, KodiTvShowId, fullInfo = True, returnmap = True):
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-17 18:41:26 +00:00
|
|
|
episodes = None
|
2015-03-29 17:13:21 +00:00
|
|
|
if fullInfo:
|
|
|
|
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","uniqueid"], "sort": {"method": "episode"}}, "id": 1}' %KodiTvShowId)
|
|
|
|
else:
|
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": %d, "properties": ["title", "playcount", "season", "episode", "lastplayed", "resume","file","uniqueid"], "sort": {"method": "episode"}}, "id": 1}' %KodiTvShowId)
|
2015-03-17 18:41:26 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
2015-03-29 17:13:21 +00:00
|
|
|
episodes = None
|
2015-03-17 18:41:26 +00:00
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
2015-03-29 17:13:21 +00:00
|
|
|
if(result.has_key('episodes')):
|
|
|
|
episodes = result['episodes']
|
2015-03-20 19:26:37 +00:00
|
|
|
if returnmap:
|
|
|
|
episodeMap = None
|
|
|
|
if(episodes != None):
|
|
|
|
episodeMap = {}
|
|
|
|
for KodiItem in episodes:
|
|
|
|
key = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
|
|
|
episodeMap[key] = KodiItem
|
|
|
|
return episodeMap
|
|
|
|
else:
|
|
|
|
return episodes
|
2015-03-17 18:41:26 +00:00
|
|
|
|
2015-03-21 11:33:59 +00:00
|
|
|
def getKodiEpisodeByMbItem(self, episodeid, tvshowid):
|
2015-03-19 10:13:49 +00:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-03-17 18:41:26 +00:00
|
|
|
episode = None
|
2015-03-21 11:33:59 +00:00
|
|
|
tvshow = self.getKodiTVShow(tvshowid)
|
|
|
|
|
|
|
|
if tvshow != None:
|
2015-03-24 20:03:07 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": ' + str(tvshow['tvshowid']) + ', "properties": ["playcount","season", "resume", "episode", "lastplayed", "uniqueid", "file"], "sort": {"method": "episode"}}, "id": 1}')
|
2015-03-21 11:33:59 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('episodes')):
|
|
|
|
episodes = result['episodes']
|
|
|
|
for ep in episodes:
|
|
|
|
if ep["uniqueid"]["unknown"] == episodeid:
|
|
|
|
episode = ep
|
|
|
|
break
|
2015-03-17 18:41:26 +00:00
|
|
|
|
|
|
|
return episode
|
2015-03-21 13:31:30 +00:00
|
|
|
|
|
|
|
def getKodiMusicVideo(self, id):
|
|
|
|
#returns a single musicvideo from Kodi db selected on MB item ID
|
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-01 19:07:29 +00:00
|
|
|
#get the mediabrowser ID from DB
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("SELECT idMVideo as musicvideoid FROM musicvideo WHERE c23 = ?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
musicvideoid = None
|
|
|
|
if result != None:
|
|
|
|
musicvideoid = result[0]
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
if musicvideoid != None:
|
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideosDetails", "params": { "musicvideoid": ' + musicvideoid + ', "properties" : ["art", "thumbnail", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track","plot", "director", "playcount", "lastplayed", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMusicVideos"}')
|
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
musicvideo = None
|
|
|
|
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('musicvideodetails')):
|
|
|
|
musicvideo = result['musicvideodetails']
|
2015-03-21 13:31:30 +00:00
|
|
|
|
|
|
|
return musicvideo
|
|
|
|
|
|
|
|
def getKodiMusicVideos(self,fullInfo = False):
|
|
|
|
#returns all musicvideos in Kodi db inserted by MB
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
if fullInfo:
|
2015-04-01 19:07:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties" : ["art", "thumbnail", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track", "lastplayed", "plot", "director", "playcount", "tag", "file"] }, "id": "libMusicVideos"}')
|
2015-03-21 13:31:30 +00:00
|
|
|
else:
|
2015-04-01 19:07:29 +00:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties" : ["resume", "playcount", "lastplayed", "file", "track"] }, "id": "libMusicVideos"}')
|
2015-03-21 13:31:30 +00:00
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
musicvideos = None
|
|
|
|
if(jsonobject.has_key('result')):
|
|
|
|
result = jsonobject['result']
|
|
|
|
if(result.has_key('musicvideos')):
|
|
|
|
musicvideos = result['musicvideos']
|
|
|
|
|
|
|
|
kodiMusicVideoMap = None
|
|
|
|
if(musicvideos != None and len(musicvideos) > 0):
|
|
|
|
kodiMusicVideoMap = {}
|
2015-04-01 19:07:29 +00:00
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
2015-03-21 13:31:30 +00:00
|
|
|
for kodivideo in musicvideos:
|
2015-04-01 19:07:29 +00:00
|
|
|
cursor.execute("SELECT c23 as MBid FROM musicvideo WHERE idMVideo = ?",(kodivideo["musicvideoid"],))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
key = result[0]
|
|
|
|
kodiMusicVideoMap[key] = kodivideo
|
|
|
|
|
|
|
|
cursor.close()
|
2015-03-21 13:31:30 +00:00
|
|
|
return kodiMusicVideoMap
|
|
|
|
|
|
|
|
def getKodiMusicVideoIds(self,returnMB3Ids = False):
|
|
|
|
# returns a list of movieIds or MB3 Id's from all movies currently in the Kodi library
|
|
|
|
allKodiMusicVideos = self.getKodiMusicVideos(False)
|
|
|
|
|
|
|
|
if(allKodiMusicVideos == None):
|
|
|
|
return list()
|
|
|
|
|
|
|
|
if(returnMB3Ids):
|
|
|
|
allKodiMusicVideoIds = list(allKodiMusicVideos.keys())
|
|
|
|
return allKodiMusicVideoIds
|
|
|
|
else:
|
|
|
|
allKodiMusicVideoIds = list()
|
|
|
|
for kodivideo in allKodiMusicVideos.values():
|
|
|
|
id = str(kodivideo["musicvideoid"])
|
|
|
|
allKodiMusicVideoIds.append(id)
|
|
|
|
|
|
|
|
return allKodiMusicVideoIds
|
|
|
|
|