2015-03-18 05:41:26 +11:00
|
|
|
#################################################################################################
|
|
|
|
# ReadKodiDB
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import json
|
2015-03-19 02:47:55 +11:00
|
|
|
import os
|
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
import Utils as utils
|
|
|
|
|
2015-03-18 05:41:26 +11:00
|
|
|
|
2015-03-19 21:13:49 +11:00
|
|
|
#sleepval is used to throttle the calls to the xbmc json API
|
|
|
|
sleepVal = 15
|
|
|
|
|
2015-03-18 05:41:26 +11:00
|
|
|
class ReadKodiDB():
|
2015-03-30 07:13:11 +11:00
|
|
|
|
2015-03-18 05:41:26 +11:00
|
|
|
def getKodiMovie(self, id):
|
2015-03-19 02:47:55 +11:00
|
|
|
#returns a single movie from Kodi db selected on MB item ID
|
2015-03-19 21:13:49 +11:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-08 19:21:11 +10:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties" : ["art", "rating", "thumbnail", "fanart", "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-18 05:41:26 +11: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-30 07:13:11 +11:00
|
|
|
for item in movies:
|
2015-05-01 21:30:21 +10:00
|
|
|
if id in item["file"]:
|
2015-03-30 07:13:11 +11:00
|
|
|
movie = item
|
|
|
|
break
|
2015-03-18 05:41:26 +11:00
|
|
|
return movie
|
|
|
|
|
2015-03-29 03:42:38 +11:00
|
|
|
def getEmbyIdByKodiId(self, kodiid, type):
|
|
|
|
embyId = None
|
2015-05-01 21:30:21 +10:00
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
2015-03-29 03:42:38 +11:00
|
|
|
|
|
|
|
if type == "movie":
|
2015-05-01 21:30:21 +10:00
|
|
|
cursor.execute("SELECT embyId as embyId FROM movie WHERE idMovie = ?",(kodiid,))
|
2015-03-29 03:42:38 +11:00
|
|
|
if type == "episode":
|
2015-05-01 21:30:21 +10:00
|
|
|
cursor.execute("SELECT embyId as embyId FROM episode WHERE idEpisode = ?",(kodiid,))
|
2015-04-02 06:07:29 +11:00
|
|
|
if type == "musicvideo":
|
2015-05-01 21:30:21 +10:00
|
|
|
cursor.execute("SELECT embyId as embyId FROM musicvideo WHERE idMVideo = ?",(kodiid,))
|
|
|
|
if type == "tvshow":
|
|
|
|
cursor.execute("SELECT embyId as embyId FROM tvshow WHERE idShow = ?",(kodiid,))
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
cursor.close()
|
|
|
|
if result != None:
|
|
|
|
embyId = result[0]
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
return embyId
|
2015-03-29 03:42:38 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def getKodiMovies(self, connection, cursor):
|
2015-03-29 03:42:38 +11:00
|
|
|
#returns all movies in Kodi db
|
2015-05-01 21:30:21 +10:00
|
|
|
cursor.execute("SELECT idMovie, embyId, c00 FROM movie")
|
|
|
|
allmovies = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allmovies
|
2015-03-19 02:47:55 +11: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 14:04:54 +11: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-19 02:47:55 +11:00
|
|
|
allKodiMovieIds.append(id)
|
|
|
|
|
2015-03-20 14:04:54 +11:00
|
|
|
return allKodiMovieIds
|
2015-03-19 02:47:55 +11:00
|
|
|
|
2015-03-19 04:00:38 +11: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 23:27:02 +11: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-19 04:00:38 +11:00
|
|
|
allKodiTvShowsIds.append(id)
|
|
|
|
|
2015-03-20 23:27:02 +11:00
|
|
|
return allKodiTvShowsIds
|
2015-03-20 21:08:22 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def getKodiTvShows(self, connection, cursor):
|
|
|
|
cursor.execute("SELECT idShow, embyId, c00 FROM tvshow")
|
|
|
|
allshows = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allshows
|
2015-03-19 04:00:38 +11:00
|
|
|
|
2015-03-18 05:41:26 +11:00
|
|
|
def getKodiTVShow(self, id):
|
2015-03-19 21:13:49 +11:00
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-05 07:48:02 +10: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-18 05:41:26 +11: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-30 07:13:11 +11:00
|
|
|
for show in tvshows:
|
|
|
|
if show["imdbnumber"] == id:
|
|
|
|
tvshow = show
|
|
|
|
break
|
2015-03-18 05:41:26 +11:00
|
|
|
return tvshow
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def getKodiEpisodes(self, connection, cursor, showid):
|
|
|
|
cursor.execute("SELECT idEpisode, embyId, c00 FROM episode WHERE idShow = ?", (showid,))
|
|
|
|
allepisodes = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allepisodes
|
2015-03-18 05:41:26 +11:00
|
|
|
|
2015-03-21 22:33:59 +11:00
|
|
|
def getKodiEpisodeByMbItem(self, episodeid, tvshowid):
|
2015-03-18 05:41:26 +11:00
|
|
|
episode = None
|
2015-03-21 22:33:59 +11:00
|
|
|
tvshow = self.getKodiTVShow(tvshowid)
|
|
|
|
|
|
|
|
if tvshow != None:
|
2015-03-25 07:03:07 +11: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 22:33:59 +11: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-18 05:41:26 +11:00
|
|
|
|
|
|
|
return episode
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-04-18 18:02:47 +10:00
|
|
|
def getKodiEpisodeByMbItemEx(self, id):
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("SELECT idEpisode FROM episode WHERE c20 = ?", (id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
kodiId = None
|
|
|
|
if result != None:
|
|
|
|
kodiId = result[0]
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
episode = None
|
|
|
|
if(kodiId != None):
|
|
|
|
print "Kodi Episode ID : " + str(kodiId)
|
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": %d, "properties": ["playcount", "season", "resume", "episode", "lastplayed", "uniqueid", "file"]}, "id": 1}' %kodiId)
|
|
|
|
#json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": ' + str(kodiId) + ', "properties": ["playcount", "season", "resume", "episode", "lastplayed", "uniqueid", "file"], "sort": {"method": "episode"}}, "id": 1}')
|
|
|
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
|
|
|
print "Kodi_Item: " + str(jsonobject)
|
|
|
|
if(jsonobject.has_key("result")):
|
|
|
|
result = jsonobject["result"]
|
|
|
|
if(result.has_key("episodedetails")):
|
|
|
|
episode = result["episodedetails"]
|
|
|
|
|
|
|
|
return episode
|
|
|
|
|
2015-03-22 00:31:30 +11:00
|
|
|
def getKodiMusicVideo(self, id):
|
|
|
|
#returns a single musicvideo from Kodi db selected on MB item ID
|
|
|
|
xbmc.sleep(sleepVal)
|
2015-04-02 06:07:29 +11: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()
|
|
|
|
|
2015-04-18 18:02:47 +10:00
|
|
|
musicvideo = None
|
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
if musicvideoid != None:
|
2015-04-08 19:21:11 +10:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideosDetails", "params": { "musicvideoid": ' + musicvideoid + ', "properties" : ["art", "thumbnail", "fanart", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track","plot", "director", "playcount", "lastplayed", "tag", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMusicVideos"}')
|
2015-04-02 06:07:29 +11:00
|
|
|
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-22 00:31:30 +11:00
|
|
|
|
|
|
|
return musicvideo
|
|
|
|
|
|
|
|
def getKodiMusicVideos(self,fullInfo = False):
|
|
|
|
#returns all musicvideos in Kodi db inserted by MB
|
|
|
|
xbmc.sleep(sleepVal)
|
|
|
|
if fullInfo:
|
2015-04-08 19:21:11 +10:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties" : ["art", "thumbnail", "fanart", "resume", "runtime", "year", "genre", "studio", "artist", "album", "track", "lastplayed", "plot", "director", "playcount", "tag", "file"] }, "id": "libMusicVideos"}')
|
2015-03-22 00:31:30 +11:00
|
|
|
else:
|
2015-04-02 06:07:29 +11:00
|
|
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties" : ["resume", "playcount", "lastplayed", "file", "track"] }, "id": "libMusicVideos"}')
|
2015-03-22 00:31:30 +11: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-02 06:07:29 +11:00
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
2015-03-22 00:31:30 +11:00
|
|
|
for kodivideo in musicvideos:
|
2015-04-02 06:07:29 +11: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-22 00:31:30 +11: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
|
|
|
|
|