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
|
|
|
class ReadKodiDB():
|
|
|
|
|
2015-05-02 10:26:06 +10: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-02 10:26:06 +10:00
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='movie'")
|
2015-05-01 21:30:21 +10:00
|
|
|
allmovies = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allmovies
|
2015-05-03 06:02:06 +10:00
|
|
|
|
|
|
|
def getKodiMusicVideos(self, connection, cursor):
|
|
|
|
#returns all musicvideos in Kodi db
|
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='musicvideo'")
|
|
|
|
allvideos = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allvideos
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def getKodiTvShows(self, connection, cursor):
|
2015-05-02 10:26:06 +10:00
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='tvshow'")
|
2015-05-01 21:30:21 +10:00
|
|
|
allshows = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allshows
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
def getKodiEpisodes(self, connection, cursor, showid=None):
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
if showid == None:
|
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=?",("episode",))
|
2015-03-22 00:31:30 +11:00
|
|
|
else:
|
2015-05-02 10:26:06 +10:00
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type=? AND parent_id=?",("episode", showid))
|
2015-05-02 22:57:43 +10:00
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
allepisodes = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allepisodes
|
2015-03-22 00:31:30 +11:00
|
|
|
|
2015-05-03 00:49:47 +10:00
|
|
|
def getEmbyIdByKodiId(self, id, type, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
2015-05-07 00:17:33 +10:00
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
2015-05-03 00:49:47 +10:00
|
|
|
cursor.execute("SELECT emby_id FROM emby WHERE media_type=? AND kodi_id=?",(type,id))
|
|
|
|
result = cursor.fetchone()
|
2015-05-07 00:17:33 +10:00
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
2015-05-03 00:49:47 +10:00
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
2015-05-17 01:58:48 +10:00
|
|
|
|
|
|
|
def getShowIdByEmbyId(self, id, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
|
|
|
cursor.execute("SELECT parent_id FROM emby WHERE emby_id=?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getTypeByEmbyId(self, id, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
|
|
|
cursor.execute("SELECT media_type FROM emby WHERE emby_id=?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getShowTotalCount(self, id, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
|
|
|
command = "SELECT totalCount FROM tvshowcounts WHERE idShow=%s" % str(id)
|
|
|
|
cursor.execute(command)
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2015-05-08 08:04:40 +10:00
|
|
|
def getKodiMusicArtists(self, connection, cursor):
|
|
|
|
#returns all artists in Kodi db
|
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='artist'")
|
|
|
|
allartists = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allartists
|
|
|
|
|
|
|
|
def getKodiMusicAlbums(self, connection, cursor):
|
|
|
|
#returns all artists in Kodi db
|
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='album'")
|
|
|
|
allalbums = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
|
|
|
return allalbums
|
|
|
|
|
|
|
|
def getKodiMusicSongs(self, connection, cursor):
|
|
|
|
#returns all songs in Kodi db
|
|
|
|
cursor.execute("SELECT kodi_id, emby_id, checksum FROM emby WHERE media_type='song'")
|
|
|
|
allsongs = cursor.fetchall()
|
|
|
|
#this will return a list with tuples of all items returned from the database
|
2015-09-16 03:03:52 +10:00
|
|
|
return allsongs
|
|
|
|
|
|
|
|
def getCriticRatingByEmbyId(self, id, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
|
|
|
cursor.execute("SELECT rotten_tomatoes FROM emby WHERE emby_id=?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getCriticRatingSummaryByEmbyId(self, id, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
|
|
|
cursor.execute("SELECT rotten_tomatoes_summary FROM emby WHERE emby_id=?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def getMetaScoreRatingByEmbyId(self, id, connection=None, cursor=None):
|
|
|
|
if not connection:
|
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
closeCon = True
|
|
|
|
else:
|
|
|
|
closeCon = False
|
|
|
|
cursor.execute("SELECT metascore FROM emby WHERE emby_id=?",(id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if closeCon:
|
|
|
|
connection.close()
|
|
|
|
if result:
|
|
|
|
return result[0]
|
|
|
|
else:
|
|
|
|
return None
|