2015-03-18 06:02:42 +11:00
|
|
|
#################################################################################################
|
2015-05-07 19:45:24 +10:00
|
|
|
# WriteKodiVideoDB
|
2015-03-18 06:02:42 +11:00
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
import json
|
|
|
|
import urllib
|
|
|
|
import sqlite3
|
|
|
|
import os
|
2015-04-08 10:58:28 +10:00
|
|
|
from decimal import Decimal
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-06-06 08:11:24 +10:00
|
|
|
|
2015-03-18 06:02:42 +11:00
|
|
|
from DownloadUtils import DownloadUtils
|
2015-03-29 03:42:38 +11:00
|
|
|
from PlayUtils import PlayUtils
|
2015-03-18 07:18:27 +11:00
|
|
|
from ReadKodiDB import ReadKodiDB
|
2015-03-21 02:58:46 +11:00
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
2015-06-06 08:11:24 +10:00
|
|
|
from TextureCache import TextureCache
|
2015-03-18 06:02:42 +11:00
|
|
|
from API import API
|
|
|
|
import Utils as utils
|
|
|
|
|
2015-05-04 04:30:24 +10: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
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-05-07 19:45:24 +10:00
|
|
|
class WriteKodiVideoDB():
|
2015-06-06 08:11:24 +10:00
|
|
|
|
|
|
|
textureCache = TextureCache()
|
2015-03-18 13:45:15 +11:00
|
|
|
|
|
|
|
def updatePlayCountFromKodi(self, id, type, playcount=0):
|
2015-05-03 00:49:47 +10:00
|
|
|
#when user marks item watched from kodi interface update this in Emby
|
2015-05-02 11:47:05 +10:00
|
|
|
|
2015-04-03 05:34:47 +11:00
|
|
|
utils.logMsg("Emby", "updatePlayCountFromKodi Called")
|
2015-05-02 11:47:05 +10:00
|
|
|
connection = utils.KodiSQL()
|
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("SELECT emby_id FROM emby WHERE media_type=? AND kodi_id=?",(type,id))
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-05-02 11:47:05 +10:00
|
|
|
emby_id = cursor.fetchone()[0]
|
|
|
|
cursor.close
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-05-02 11:47:05 +10:00
|
|
|
if(emby_id != None):
|
2015-05-18 13:04:24 +10:00
|
|
|
# Erase resume point when user marks watched/unwatched to follow Emby behavior
|
|
|
|
# Also force sets the playcount to instantly reflect the appropriate playstate.
|
2015-05-17 17:50:33 +10:00
|
|
|
if type == "episode":
|
2015-05-18 13:04:24 +10:00
|
|
|
resume = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": {"episodeid": %d, "playcount": %d, "resume": {"position": 0}}, "id": "setResumePoint"}' % (id, playcount)
|
2015-05-17 17:50:33 +10:00
|
|
|
elif type == "movie":
|
2015-05-18 13:04:24 +10:00
|
|
|
resume = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": %d, "playcount": %d, "resume": {"position": 0}}, "id": "setResumePoint"}' % (id, playcount)
|
2015-05-17 17:50:33 +10:00
|
|
|
xbmc.executeJSONRPC(resume)
|
2015-05-24 15:56:31 +10:00
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % emby_id
|
|
|
|
if playcount != 0:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, type="POST")
|
|
|
|
else:
|
|
|
|
downloadUtils.downloadUrl(watchedurl, type="DELETE")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def addOrUpdateMovieToKodiLibrary( self, embyId ,connection, cursor, viewTag):
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-04-14 04:56:36 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
2015-04-02 06:07:29 +11:00
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
MBitem = ReadEmbyDB().getFullItem(embyId)
|
|
|
|
|
2015-05-13 02:16:30 +10:00
|
|
|
if not MBitem:
|
|
|
|
utils.logMsg("ADD movie to Kodi library FAILED", "Item %s not found on server!" %embyId)
|
|
|
|
return
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
# If the item already exist in the local Kodi DB we'll perform a full item update
|
|
|
|
# If the item doesn't exist, we'll add it to the database
|
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(MBitem["Id"],))
|
2015-05-01 21:30:21 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
movieid = result[0]
|
|
|
|
else:
|
|
|
|
movieid = None
|
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
2015-05-02 00:58:20 +10:00
|
|
|
people = API().getPeople(MBitem)
|
2015-04-08 19:21:11 +10:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
#### The movie details #########
|
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
sorttitle = utils.convertEncoding(MBitem["SortName"])
|
|
|
|
year = MBitem.get("ProductionYear")
|
|
|
|
rating = MBitem.get("CommunityRating")
|
2015-05-02 00:58:20 +10:00
|
|
|
mpaa = MBitem.get("OfficialRating")
|
|
|
|
genres = MBitem.get("Genres")
|
|
|
|
genre = " / ".join(genres)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
studio = " / ".join(studios)
|
|
|
|
writer = " / ".join(people.get("Writer"))
|
|
|
|
director = " / ".join(people.get("Director"))
|
2015-05-06 00:16:34 +10:00
|
|
|
country = None
|
|
|
|
if MBitem.get("ProductionLocations") !=None and MBitem.get("ProductionLocations") != []:
|
|
|
|
country = MBitem.get("ProductionLocations")[0]
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
imdb = None
|
|
|
|
if MBitem.get("ProviderIds"):
|
|
|
|
if MBitem.get("ProviderIds").get("Imdb"):
|
|
|
|
imdb = MBitem.get("ProviderIds").get("Imdb")
|
2015-05-01 21:30:21 +10:00
|
|
|
|
|
|
|
if MBitem.get("ShortOverview") != None:
|
|
|
|
shortplot = utils.convertEncoding(MBitem.get("ShortOverview"))
|
|
|
|
else:
|
|
|
|
shortplot = None
|
|
|
|
|
|
|
|
trailerUrl = None
|
|
|
|
if MBitem.get("LocalTrailerCount") != None and MBitem.get("LocalTrailerCount") > 0:
|
|
|
|
itemTrailerUrl = "%s/mediabrowser/Users/%s/Items/%s/LocalTrailers?format=json" % (server, userid, MBitem.get("Id"))
|
|
|
|
jsonData = downloadUtils.downloadUrl(itemTrailerUrl)
|
|
|
|
if(jsonData != ""):
|
|
|
|
trailerItem = jsonData
|
2015-05-09 03:05:10 +10:00
|
|
|
trailerUrl = "plugin://plugin.video.emby/trailer/?id=%s&mode=play" % trailerItem[0][u'Id']
|
2015-06-17 18:19:08 +10:00
|
|
|
elif MBitem.get("RemoteTrailers"):
|
2015-06-17 15:35:07 +10:00
|
|
|
try:
|
|
|
|
trailerUrl = MBitem.get("RemoteTrailers")[0].get("Url")
|
|
|
|
trailerId = trailerUrl.split('=')[1]
|
|
|
|
trailerUrl = "plugin://plugin.video.youtube/play/?video_id=%s" % trailerId
|
|
|
|
except:
|
|
|
|
trailerUrl = MBitem.get("RemoteTrailers")[0].get("Url")
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
if MBitem.get("DateCreated") != None:
|
2015-05-04 09:09:16 +10:00
|
|
|
dateadded = MBitem["DateCreated"].split('.')[0].replace('T', " ")
|
2015-04-02 06:07:29 +11:00
|
|
|
else:
|
|
|
|
dateadded = None
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-05-17 15:37:53 +10:00
|
|
|
if userData.get("PlayCount") != "0":
|
|
|
|
playcount = int(userData.get('PlayCount'))
|
2015-05-06 02:40:53 +10:00
|
|
|
else:
|
|
|
|
playcount = None #playcount must be set to NULL in the db
|
2015-05-23 10:23:36 +10:00
|
|
|
|
|
|
|
votecount = MBitem.get("VoteCount")
|
|
|
|
|
|
|
|
tagline = None
|
|
|
|
if MBitem.get("Taglines") != None and MBitem.get("Taglines") != []:
|
|
|
|
tagline = MBitem.get("Taglines")[0]
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
#### ADD OR UPDATE THE FILE AND PATH ###########
|
|
|
|
#### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY
|
2015-05-26 00:23:46 +10:00
|
|
|
if addon.getSetting('useDirectPaths')=='true':
|
|
|
|
if PlayUtils().isDirectPlay(MBitem):
|
|
|
|
playurl = PlayUtils().directPlay(MBitem)
|
|
|
|
#use the direct file path
|
|
|
|
if "\\" in playurl:
|
|
|
|
filename = playurl.rsplit("\\",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
elif "/" in playurl:
|
|
|
|
filename = playurl.rsplit("/",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
else:
|
|
|
|
#for transcoding we just use the server's streaming path because I couldn't figure out how to set the plugin path in the music DB
|
2015-05-26 02:53:53 +10:00
|
|
|
path = server + "/Video/%s/" %MBitem["Id"]
|
|
|
|
filename = "stream.mp4"
|
2015-05-26 00:23:46 +10:00
|
|
|
else:
|
|
|
|
path = "plugin://plugin.video.emby/movies/%s/" % MBitem["Id"]
|
|
|
|
filename = "plugin://plugin.video.emby/movies/%s/?id=%s&mode=play" % (MBitem["Id"],MBitem["Id"])
|
2015-05-07 07:41:44 +10:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#create the path
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
else:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#create the file if not exists
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,))
|
2015-04-02 06:07:29 +11:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
fileid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
|
|
fileid = cursor.fetchone()[0]
|
|
|
|
fileid = fileid + 1
|
|
|
|
pathsql="insert into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (fileid,pathid,filename,playcount,userData.get("LastPlayedDate"),dateadded))
|
2015-05-02 22:02:31 +10:00
|
|
|
else:
|
|
|
|
pathsql="update files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
|
|
|
|
cursor.execute(pathsql, (playcount,userData.get("LastPlayedDate"), fileid))
|
2015-04-02 06:07:29 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
##### ADD THE MOVIE ############
|
2015-05-02 20:51:46 +10:00
|
|
|
if movieid == None:
|
|
|
|
|
|
|
|
utils.logMsg("ADD movie to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
#create the movie
|
|
|
|
cursor.execute("select coalesce(max(idMovie),0) as movieid from movie")
|
|
|
|
movieid = cursor.fetchone()[0]
|
|
|
|
movieid = movieid + 1
|
2015-05-23 10:23:36 +10:00
|
|
|
pathsql="insert into movie(idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07, c09, c10, c11, c12, c14, c15, c16, c18, c19, c21) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (movieid, fileid, title, plot, shortplot, tagline, votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailerUrl, country))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#add the viewtag
|
|
|
|
self.AddTagToMedia(movieid, viewTag, "movie", cursor)
|
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
#create the reference in emby table
|
|
|
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (MBitem["Id"], movieid, "movie", API().getChecksum(MBitem)))
|
2015-05-03 08:44:35 +10:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
#### UPDATE THE MOVIE #####
|
|
|
|
else:
|
2015-05-02 20:51:46 +10:00
|
|
|
utils.logMsg("UPDATE movie to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
2015-05-23 10:23:36 +10:00
|
|
|
pathsql="update movie SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?WHERE idMovie = ?"
|
|
|
|
cursor.execute(pathsql, (title, plot, shortplot, tagline, votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailerUrl, country, movieid))
|
2015-05-02 10:26:06 +10:00
|
|
|
|
|
|
|
#update the checksum in emby table
|
|
|
|
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
2015-04-02 21:47:29 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
#update or insert actors
|
2015-05-02 00:58:20 +10:00
|
|
|
self.AddPeopleToMedia(movieid,MBitem.get("People"),"movie", connection, cursor)
|
2015-04-02 06:07:29 +11:00
|
|
|
|
2015-05-01 21:57:24 +10:00
|
|
|
#update artwork
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), movieid, "movie", "thumb", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), movieid, "movie", "poster", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner"), movieid, "movie", "banner", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo"), movieid, "movie", "clearlogo", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Art"), movieid, "movie", "clearart", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb"), movieid, "movie", "landscape", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), movieid, "movie", "discart", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), movieid, "movie", "fanart", cursor)
|
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
#update genres
|
|
|
|
self.AddGenresToMedia(movieid, genres, "movie", cursor)
|
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
#update countries
|
2015-05-06 00:21:30 +10:00
|
|
|
self.AddCountriesToMedia(movieid, MBitem.get("ProductionLocations"), "movie", cursor)
|
2015-05-06 00:20:09 +10:00
|
|
|
|
|
|
|
#update studios
|
|
|
|
self.AddStudiosToMedia(movieid, studios, "movie", cursor)
|
2015-05-06 00:16:34 +10:00
|
|
|
|
2015-05-03 08:44:35 +10:00
|
|
|
#add streamdetails
|
|
|
|
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor)
|
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
#add to or remove from favorites tag
|
2015-05-03 09:46:11 +10:00
|
|
|
if userData.get("Favorite"):
|
|
|
|
self.AddTagToMedia(movieid, "Favorite movies", "movie", cursor)
|
|
|
|
else:
|
|
|
|
self.AddTagToMedia(movieid, "Favorite movies", "movie", cursor, True)
|
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
#set resume point
|
|
|
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
|
|
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
|
|
|
self.setKodiResumePoint(fileid, resume, total, cursor)
|
|
|
|
|
2015-05-03 06:02:06 +10:00
|
|
|
def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor):
|
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
username = WINDOW.getProperty('currUser')
|
|
|
|
userid = WINDOW.getProperty('userId%s' % username)
|
|
|
|
server = WINDOW.getProperty('server%s' % username)
|
|
|
|
downloadUtils = DownloadUtils()
|
|
|
|
|
|
|
|
MBitem = ReadEmbyDB().getFullItem(embyId)
|
2015-05-13 02:16:30 +10:00
|
|
|
|
|
|
|
if not MBitem:
|
|
|
|
utils.logMsg("ADD musicvideo to Kodi library FAILED", "Item %s not found on server!" %embyId)
|
|
|
|
return
|
2015-05-03 06:25:08 +10:00
|
|
|
|
2015-05-03 06:02:06 +10:00
|
|
|
# If the item already exist in the local Kodi DB we'll perform a full item update
|
|
|
|
# If the item doesn't exist, we'll add it to the database
|
|
|
|
|
|
|
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(MBitem["Id"],))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
idMVideo = result[0]
|
|
|
|
else:
|
|
|
|
idMVideo = None
|
|
|
|
|
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
people = API().getPeople(MBitem)
|
|
|
|
|
|
|
|
#### The video details #########
|
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
year = MBitem.get("ProductionYear")
|
|
|
|
genres = MBitem.get("Genres")
|
|
|
|
genre = " / ".join(genres)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
studio = " / ".join(studios)
|
|
|
|
director = " / ".join(people.get("Director"))
|
2015-05-03 06:25:08 +10:00
|
|
|
artist = " / ".join(MBitem.get("Artists"))
|
2015-05-03 06:02:06 +10:00
|
|
|
album = MBitem.get("Album")
|
|
|
|
track = MBitem.get("Track")
|
|
|
|
|
|
|
|
if MBitem.get("DateCreated") != None:
|
2015-05-04 09:09:16 +10:00
|
|
|
dateadded = MBitem["DateCreated"].split('.')[0].replace('T', " ")
|
2015-05-03 06:02:06 +10:00
|
|
|
else:
|
|
|
|
dateadded = None
|
|
|
|
|
2015-05-17 15:37:53 +10:00
|
|
|
if userData.get("PlayCount") != "0":
|
|
|
|
playcount = int(userData.get('PlayCount'))
|
2015-05-06 02:40:53 +10:00
|
|
|
else:
|
|
|
|
playcount = None #playcount must be set to NULL in the db
|
2015-05-03 06:02:06 +10:00
|
|
|
|
|
|
|
#### ADD OR UPDATE THE FILE AND PATH ###########
|
|
|
|
#### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY
|
2015-05-26 00:23:46 +10:00
|
|
|
if addon.getSetting('useDirectPaths')=='true':
|
|
|
|
if PlayUtils().isDirectPlay(MBitem):
|
|
|
|
playurl = PlayUtils().directPlay(MBitem)
|
|
|
|
#use the direct file path
|
|
|
|
if "\\" in playurl:
|
|
|
|
filename = playurl.rsplit("\\",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
elif "/" in playurl:
|
|
|
|
filename = playurl.rsplit("/",1)[-1]
|
|
|
|
path = playurl.replace(filename,"")
|
|
|
|
else:
|
|
|
|
#for transcoding we just use the server's streaming path because I couldn't figure out how to set the plugin path in the music DB
|
2015-05-26 02:53:53 +10:00
|
|
|
path = server + "/Video/%s/" %MBitem["Id"]
|
|
|
|
filename = "stream.mp4"
|
2015-05-26 00:23:46 +10:00
|
|
|
else:
|
2015-05-28 21:53:07 +10:00
|
|
|
path = "plugin://plugin.video.emby/musicvideos/%s/" % MBitem["Id"]
|
|
|
|
filename = "plugin://plugin.video.emby/musicvideos/%s/?id=%s&mode=play" % (MBitem["Id"], MBitem["Id"])
|
2015-05-03 06:02:06 +10:00
|
|
|
|
|
|
|
#create the path
|
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
else:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,"musicvideos","metadata.local",1))
|
|
|
|
|
|
|
|
#create the file if not exists
|
|
|
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
fileid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
|
|
fileid = cursor.fetchone()[0]
|
|
|
|
fileid = fileid + 1
|
|
|
|
pathsql="insert into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (fileid,pathid,filename,playcount,userData.get("LastPlayedDate"),dateadded))
|
|
|
|
else:
|
|
|
|
pathsql="update files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
|
|
|
|
cursor.execute(pathsql, (playcount,userData.get("LastPlayedDate"), fileid))
|
|
|
|
|
|
|
|
##### ADD THE VIDEO ############
|
|
|
|
if idMVideo == None:
|
|
|
|
|
|
|
|
utils.logMsg("ADD musicvideo to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
|
|
|
|
|
|
|
#create the video
|
|
|
|
cursor.execute("select coalesce(max(idMVideo),0) as idMVideo from musicvideo")
|
|
|
|
idMVideo = cursor.fetchone()[0]
|
|
|
|
idMVideo = idMVideo + 1
|
|
|
|
pathsql="insert into musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10, c11, c12) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (idMVideo, fileid, title, runtime, director, studio, year, plot, album, artist, genre, track))
|
|
|
|
|
|
|
|
#create the reference in emby table
|
|
|
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (MBitem["Id"], idMVideo, "musicvideo", API().getChecksum(MBitem)))
|
|
|
|
|
|
|
|
#### UPDATE THE VIDEO #####
|
|
|
|
else:
|
|
|
|
utils.logMsg("UPDATE musicvideo to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
|
|
|
pathsql="update musicvideo SET c00 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c08 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ? WHERE idMVideo = ?"
|
|
|
|
cursor.execute(pathsql, (title, runtime, director, studio, year, plot, album, artist, genre, track, idMVideo))
|
|
|
|
|
|
|
|
#update the checksum in emby table
|
|
|
|
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
|
|
|
|
|
|
|
|
#update or insert actors
|
|
|
|
self.AddPeopleToMedia(idMVideo,MBitem.get("People"),"musicvideo", connection, cursor)
|
|
|
|
|
|
|
|
#update artwork
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), idMVideo, "musicvideo", "thumb", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), idMVideo, "musicvideo", "poster", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner"), idMVideo, "musicvideo", "banner", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo"), idMVideo, "musicvideo", "clearlogo", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Art"), idMVideo, "musicvideo", "clearart", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb"), idMVideo, "musicvideo", "landscape", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), idMVideo, "musicvideo", "discart", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), idMVideo, "musicvideo", "fanart", cursor)
|
|
|
|
|
|
|
|
#update genres
|
|
|
|
self.AddGenresToMedia(idMVideo, genres, "musicvideo", cursor)
|
|
|
|
|
|
|
|
#update studios
|
|
|
|
self.AddStudiosToMedia(idMVideo, studios, "musicvideo", cursor)
|
|
|
|
|
2015-05-03 08:44:35 +10:00
|
|
|
#add streamdetails
|
|
|
|
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor)
|
|
|
|
|
2015-05-03 06:02:06 +10:00
|
|
|
#set resume point
|
|
|
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
|
|
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
|
|
|
self.setKodiResumePoint(fileid, resume, total, cursor)
|
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
def addOrUpdateTvShowToKodiLibrary( self, embyId, connection, cursor, viewTag ):
|
|
|
|
|
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
|
|
|
|
|
|
|
MBitem = ReadEmbyDB().getFullItem(embyId)
|
|
|
|
|
2015-05-13 02:16:30 +10:00
|
|
|
if not MBitem:
|
|
|
|
utils.logMsg("ADD tvshow to Kodi library FAILED", "Item %s not found on server!" %embyId)
|
|
|
|
return
|
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
|
|
|
|
|
|
|
thumbPath = API().getArtwork(MBitem, "Primary")
|
|
|
|
|
|
|
|
# If the item already exist in the local Kodi DB we'll perform a full item update
|
|
|
|
# If the item doesn't exist, we'll add it to the database
|
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(MBitem["Id"],))
|
2015-05-02 00:58:20 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
showid = result[0]
|
|
|
|
else:
|
|
|
|
showid = None
|
|
|
|
|
|
|
|
#### TV SHOW DETAILS #########
|
|
|
|
|
|
|
|
genres = MBitem.get("Genres")
|
|
|
|
genre = " / ".join(genres)
|
|
|
|
studios = API().getStudios(MBitem)
|
|
|
|
studio = " / ".join(studios)
|
|
|
|
mpaa = MBitem.get("OfficialRating")
|
2015-05-02 20:10:57 +10:00
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
sorttitle = utils.convertEncoding(MBitem["SortName"])
|
|
|
|
rating = MBitem.get("CommunityRating")
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
tvdb = None
|
|
|
|
if MBitem.get("ProviderIds"):
|
|
|
|
if MBitem.get("ProviderIds").get("Tvdb"):
|
|
|
|
tvdb = MBitem.get("ProviderIds").get("Tvdb")
|
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
if MBitem.get("DateCreated") != None:
|
2015-05-04 09:09:16 +10:00
|
|
|
dateadded = MBitem["DateCreated"].split('.')[0].replace('T', " ")
|
2015-05-02 00:58:20 +10:00
|
|
|
else:
|
|
|
|
dateadded = None
|
|
|
|
|
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
|
|
|
else:
|
|
|
|
premieredate = None
|
2015-05-27 09:12:13 +10:00
|
|
|
|
|
|
|
#create toplevel path as monitored source - needed for things like actors and stuff to work (no clue why)
|
|
|
|
if addon.getSetting('useDirectPaths')=='true':
|
2015-05-29 00:57:15 +10:00
|
|
|
smbuser = addon.getSetting('smbusername')
|
|
|
|
smbpass = addon.getSetting('smbpassword')
|
|
|
|
# Network share
|
|
|
|
if smbuser:
|
|
|
|
playurl = MBitem["Path"].replace("\\\\", "smb://%s:%s@" % (smbuser, smbpass)).replace("\\", "/")
|
|
|
|
else:
|
|
|
|
playurl = MBitem["Path"].replace("\\\\", "smb://").replace("\\", "/")
|
2015-05-27 09:12:13 +10:00
|
|
|
#make sure that the path always ends with a slash
|
|
|
|
path = utils.convertEncoding(playurl + "/")
|
|
|
|
toplevelpathstr = path.rsplit("/",2)[1]
|
|
|
|
toplevelpath = path.replace(toplevelpathstr + "/","")
|
|
|
|
else:
|
|
|
|
path = "plugin://plugin.video.emby/tvshows/" + MBitem["Id"] + "/"
|
|
|
|
toplevelpath = "plugin://plugin.video.emby/"
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#### ADD THE TV SHOW TO KODI ##############
|
|
|
|
if showid == None:
|
2015-05-02 06:14:00 +10:00
|
|
|
|
2015-05-02 20:51:46 +10:00
|
|
|
utils.logMsg("ADD tvshow to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
|
|
|
|
2015-05-02 06:14:00 +10:00
|
|
|
#create the tv show path
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,None,None,1))
|
2015-05-02 00:58:20 +10:00
|
|
|
cursor.execute("SELECT idPath as tlpathid FROM path WHERE strPath = ?",(toplevelpath,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as tlpathid from path")
|
|
|
|
tlpathid = cursor.fetchone()[0]
|
|
|
|
tlpathid = tlpathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (tlpathid,toplevelpath,"tvshows","metadata.local",1))
|
|
|
|
|
|
|
|
#create the tvshow
|
|
|
|
cursor.execute("select coalesce(max(idShow),0) as showid from tvshow")
|
|
|
|
showid = cursor.fetchone()[0]
|
2015-05-02 06:14:00 +10:00
|
|
|
showid = showid + 1
|
2015-05-06 00:16:34 +10:00
|
|
|
pathsql="insert into tvshow(idShow, c00, c01, c04, c05, c08, c09, c12, c13, c14, c15) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (showid, title, plot, rating, premieredate, genre, title, tvdb, mpaa, studio, sorttitle))
|
2015-05-02 10:26:06 +10:00
|
|
|
|
|
|
|
#create the reference in emby table
|
|
|
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (MBitem["Id"], showid, "tvshow", API().getChecksum(MBitem)))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#link the path
|
|
|
|
pathsql="insert into tvshowlinkpath(idShow,idPath) values(?, ?)"
|
|
|
|
cursor.execute(pathsql, (showid,pathid))
|
2015-05-03 09:46:11 +10:00
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
#add the viewtag
|
|
|
|
self.AddTagToMedia(showid, viewTag, "tvshow", cursor)
|
|
|
|
|
|
|
|
#### UPDATE THE TV SHOW #############
|
|
|
|
else:
|
2015-05-02 20:51:46 +10:00
|
|
|
utils.logMsg("UPDATE tvshow to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
pathsql="UPDATE tvshow SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ? WHERE idShow = ?"
|
|
|
|
cursor.execute(pathsql, (title, plot, rating, premieredate, title, genre, tvdb, mpaa, studio, sorttitle, showid))
|
2015-05-02 10:26:06 +10:00
|
|
|
|
|
|
|
#update the checksum in emby table
|
|
|
|
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem), MBitem["Id"]))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#update or insert people
|
|
|
|
self.AddPeopleToMedia(showid,MBitem.get("People"),"tvshow", connection, cursor)
|
|
|
|
|
|
|
|
#update genres
|
2015-05-02 01:13:22 +10:00
|
|
|
self.AddGenresToMedia(showid, genres, "tvshow", cursor)
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#update studios
|
2015-05-02 01:13:22 +10:00
|
|
|
self.AddStudiosToMedia(showid, studios, "tvshow", cursor)
|
2015-05-03 09:46:11 +10:00
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
#add to or remove from favorites tag
|
2015-05-03 09:46:11 +10:00
|
|
|
if userData.get("Favorite"):
|
|
|
|
self.AddTagToMedia(showid, "Favorite tvshows", "tvshow", cursor)
|
|
|
|
else:
|
|
|
|
self.AddTagToMedia(showid, "Favorite tvshows", "tvshow", cursor, True)
|
2015-05-02 10:26:06 +10:00
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
#update artwork
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), showid, "tvshow", "thumb", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), showid, "tvshow", "poster", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner"), showid, "tvshow", "banner", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo"), showid, "tvshow", "clearlogo", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Art"), showid, "tvshow", "clearart", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb"), showid, "tvshow", "landscape", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), showid, "tvshow", "discart", cursor)
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), showid, "tvshow", "fanart", cursor)
|
|
|
|
|
|
|
|
#update season details
|
|
|
|
self.updateSeasons(MBitem["Id"], showid, connection, cursor)
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor):
|
|
|
|
|
|
|
|
# If the episode already exist in the local Kodi DB we'll perform a full item update
|
|
|
|
# If the item doesn't exist, we'll add it to the database
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
MBitem = ReadEmbyDB().getFullItem(embyId)
|
2015-05-13 02:16:30 +10:00
|
|
|
if not MBitem:
|
|
|
|
utils.logMsg("ADD episode to Kodi library FAILED", "Item %s not found on server!" %embyId)
|
|
|
|
return
|
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(MBitem["Id"],))
|
2015-04-05 09:32:42 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
2015-05-01 21:30:21 +10:00
|
|
|
episodeid = result[0]
|
|
|
|
else:
|
|
|
|
episodeid = None
|
2015-04-05 09:32:42 +10:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
|
|
|
port = addon.getSetting('port')
|
|
|
|
host = addon.getSetting('ipaddress')
|
|
|
|
server = host + ":" + port
|
2015-03-18 06:02:42 +11:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
timeInfo = API().getTimeInfo(MBitem)
|
|
|
|
userData=API().getUserData(MBitem)
|
2015-05-02 00:58:20 +10:00
|
|
|
people = API().getPeople(MBitem)
|
2015-04-08 19:21:11 +10:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
###### episode properties ################
|
|
|
|
episode = 0
|
|
|
|
if MBitem.get("IndexNumber") != None:
|
|
|
|
episode = int(MBitem.get("IndexNumber"))
|
|
|
|
|
|
|
|
runtime = int(timeInfo.get('Duration'))*60
|
|
|
|
plot = utils.convertEncoding(API().getOverview(MBitem))
|
|
|
|
title = utils.convertEncoding(MBitem["Name"])
|
|
|
|
rating = MBitem.get("CommunityRating")
|
2015-05-02 00:58:20 +10:00
|
|
|
writer = " / ".join(people.get("Writer"))
|
|
|
|
director = " / ".join(people.get("Director"))
|
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
if MBitem.get("PremiereDate") != None:
|
|
|
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
|
|
|
premieredate = premieredatelist[0]
|
|
|
|
else:
|
|
|
|
premieredate = None
|
2015-04-02 06:07:29 +11:00
|
|
|
|
|
|
|
if MBitem.get("DateCreated") != None:
|
|
|
|
dateadded = MBitem["DateCreated"].replace("T"," ")
|
|
|
|
dateadded = dateadded.split(".")[0]
|
|
|
|
else:
|
|
|
|
dateadded = None
|
|
|
|
|
|
|
|
if userData.get("LastPlayedDate") != None:
|
|
|
|
lastplayed = userData.get("LastPlayedDate")
|
|
|
|
else:
|
|
|
|
lastplayed = None
|
2015-05-01 21:30:21 +10:00
|
|
|
|
2015-05-17 15:37:53 +10:00
|
|
|
if userData.get("PlayCount") != "0":
|
|
|
|
playcount = int(userData.get('PlayCount'))
|
2015-05-06 02:40:53 +10:00
|
|
|
else:
|
|
|
|
playcount = None #playcount must be set to NULL in the db
|
2015-05-01 21:30:21 +10:00
|
|
|
|
|
|
|
#### ADD OR UPDATE THE FILE AND PATH ###########
|
|
|
|
#### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY
|
2015-06-13 11:20:40 +10:00
|
|
|
if addon.getSetting('useDirectPaths') == 'true':
|
|
|
|
playurl = PlayUtils().directPlay(MBitem)
|
|
|
|
if playurl == False:
|
|
|
|
return
|
|
|
|
elif "\\" in playurl:
|
|
|
|
filename = playurl.rsplit("\\",1)[-1]
|
|
|
|
path = playurl.replace(filename, "")
|
|
|
|
elif "/" in playurl:
|
|
|
|
filename = playurl.rsplit("/",1)[-1]
|
|
|
|
path = playurl.replace(filename, "")
|
2015-05-26 00:23:46 +10:00
|
|
|
else:
|
2015-05-28 21:53:07 +10:00
|
|
|
path = "plugin://plugin.video.emby/tvshows/" + MBitem["SeriesId"] + "/"
|
|
|
|
filename = "plugin://plugin.video.emby/tvshows/" + MBitem["SeriesId"] + "/?id=" + MBitem["Id"] + "&mode=play"
|
2015-05-07 07:41:44 +10:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#create the new path - return id if already exists
|
|
|
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
pathid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
|
|
|
|
pathid = cursor.fetchone()[0]
|
|
|
|
pathid = pathid + 1
|
|
|
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (pathid,path,None,None,1))
|
2015-05-01 21:30:21 +10:00
|
|
|
|
2015-04-02 06:07:29 +11:00
|
|
|
#create the file if not exists
|
2015-04-02 10:48:04 +11:00
|
|
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,))
|
2015-04-02 06:07:29 +11:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
fileid = result[0]
|
|
|
|
if result == None:
|
|
|
|
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
|
|
|
|
fileid = cursor.fetchone()[0]
|
|
|
|
fileid = fileid + 1
|
|
|
|
sql="INSERT OR REPLACE into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(sql, (fileid,pathid,filename,playcount,lastplayed,dateadded))
|
2015-05-02 22:02:31 +10:00
|
|
|
else:
|
|
|
|
pathsql="update files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
|
|
|
|
cursor.execute(pathsql, (playcount,userData.get("LastPlayedDate"), fileid))
|
2015-04-22 12:31:16 +10:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
# safety check: check season first
|
2015-04-22 12:31:16 +10:00
|
|
|
season = 0
|
|
|
|
if MBitem.get("ParentIndexNumber") != None:
|
|
|
|
season = int(MBitem.get("ParentIndexNumber"))
|
|
|
|
else:
|
2015-05-01 21:30:21 +10:00
|
|
|
utils.logMsg("Emby","SKIP adding episode to Kodi Library, no ParentIndexNumber - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
2015-04-22 12:31:16 +10:00
|
|
|
return False
|
|
|
|
|
|
|
|
cursor.execute("SELECT idSeason FROM seasons WHERE idShow = ? and season = ?",(showid, season))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if(result == None):
|
2015-05-01 21:30:21 +10:00
|
|
|
#update seasons first
|
|
|
|
self.updateSeasons(MBitem["SeriesId"], showid, connection, cursor)
|
|
|
|
|
|
|
|
# ADD EPISODE TO KODI
|
|
|
|
if episodeid == None:
|
2015-05-02 20:51:46 +10:00
|
|
|
utils.logMsg("ADD episode to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
2015-05-01 21:30:21 +10:00
|
|
|
#create the episode
|
|
|
|
cursor.execute("select coalesce(max(idEpisode),0) as episodeid from episode")
|
|
|
|
episodeid = cursor.fetchone()[0]
|
|
|
|
episodeid = episodeid + 1
|
2015-05-02 10:26:06 +10:00
|
|
|
pathsql = "INSERT into episode(idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14, idShow, c15, c16) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (episodeid, fileid, title, plot, rating, writer, premieredate, runtime, director, season, episode, title, showid, "-1", "-1"))
|
|
|
|
|
|
|
|
#create the reference in emby table
|
|
|
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum, parent_id) values(?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(pathsql, (MBitem["Id"], episodeid, "episode", API().getChecksum(MBitem), showid))
|
2015-05-01 21:30:21 +10:00
|
|
|
|
|
|
|
# UPDATE THE EPISODE IN KODI (for now, we just send in all data)
|
2015-04-08 19:21:11 +10:00
|
|
|
else:
|
2015-05-02 20:51:46 +10:00
|
|
|
utils.logMsg("UPDATE episode to Kodi library","Id: %s - Title: %s" % (embyId, title))
|
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
pathsql = "UPDATE episode SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?, c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ? WHERE idEpisode = ?"
|
|
|
|
cursor.execute(pathsql, (title, plot, rating, writer, premieredate, runtime, director, season, episode, title, "-1", "-1", episodeid))
|
|
|
|
|
|
|
|
#update the checksum in emby table
|
|
|
|
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem), MBitem["Id"]))
|
2015-04-02 06:07:29 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
#update or insert actors
|
2015-05-02 00:58:20 +10:00
|
|
|
self.AddPeopleToMedia(episodeid,MBitem.get("People"),"episode", connection, cursor)
|
2015-04-02 06:07:29 +11:00
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
#set resume point
|
|
|
|
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
|
|
|
|
total = int(round(float(timeInfo.get("TotalTime"))))*60
|
|
|
|
self.setKodiResumePoint(fileid, resume, total, cursor)
|
|
|
|
|
2015-05-03 08:44:35 +10:00
|
|
|
#add streamdetails
|
|
|
|
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor)
|
|
|
|
|
2015-05-01 21:57:24 +10:00
|
|
|
#update artwork
|
|
|
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), episodeid, "episode", "thumb", cursor)
|
2015-05-02 10:26:06 +10:00
|
|
|
|
2015-05-02 19:56:31 +10:00
|
|
|
def deleteItemFromKodiLibrary(self, id, connection, cursor ):
|
|
|
|
|
|
|
|
cursor.execute("SELECT kodi_id, media_type FROM emby WHERE emby_id=?", (id,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result:
|
|
|
|
kodi_id = result[0]
|
|
|
|
media_type = result[1]
|
|
|
|
if media_type == "movie":
|
|
|
|
utils.logMsg("deleting movie from Kodi library --> ",id)
|
|
|
|
cursor.execute("DELETE FROM movie WHERE idMovie = ?", (kodi_id,))
|
|
|
|
if media_type == "episode":
|
|
|
|
utils.logMsg("deleting episode from Kodi library --> ",id)
|
|
|
|
cursor.execute("DELETE FROM episode WHERE idEpisode = ?", (kodi_id,))
|
|
|
|
if media_type == "tvshow":
|
|
|
|
utils.logMsg("deleting tvshow from Kodi library --> ",id)
|
|
|
|
cursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodi_id,))
|
|
|
|
if media_type == "musicvideo":
|
|
|
|
utils.logMsg("deleting musicvideo from Kodi library --> ",id)
|
|
|
|
cursor.execute("DELETE FROM musicvideo WHERE idMVideo = ?", (kodi_id,))
|
2015-05-02 22:57:43 +10:00
|
|
|
|
|
|
|
#delete the record in emby table
|
|
|
|
cursor.execute("DELETE FROM emby WHERE emby_id = ?", (id,))
|
2015-05-02 19:56:31 +10:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
def updateSeasons(self,embyTvShowId, kodiTvShowId, connection, cursor):
|
2015-03-21 02:16:39 +11:00
|
|
|
|
2015-05-01 21:30:21 +10:00
|
|
|
seasonData = ReadEmbyDB().getTVShowSeasons(embyTvShowId)
|
2015-03-21 02:58:46 +11:00
|
|
|
if seasonData != None:
|
|
|
|
for season in seasonData:
|
2015-04-16 18:38:16 +10:00
|
|
|
seasonNum = season.get("IndexNumber")
|
2015-05-08 09:38:38 +10:00
|
|
|
if seasonNum != None and seasonNum >= 0:
|
2015-05-01 21:30:21 +10:00
|
|
|
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?",(kodiTvShowId, seasonNum))
|
2015-04-02 06:07:29 +11:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result == None:
|
|
|
|
#create the season
|
|
|
|
cursor.execute("select coalesce(max(idSeason),0) as seasonid from seasons")
|
|
|
|
seasonid = cursor.fetchone()[0]
|
|
|
|
seasonid = seasonid + 1
|
2015-05-01 21:30:21 +10:00
|
|
|
cursor.execute("INSERT into seasons(idSeason, idShow, season) values(?, ?, ?)", (seasonid, kodiTvShowId, seasonNum))
|
2015-04-15 12:20:08 +10:00
|
|
|
else:
|
|
|
|
seasonid = result[0]
|
2015-04-02 06:07:29 +11:00
|
|
|
|
2015-04-15 12:20:08 +10:00
|
|
|
#update artwork
|
|
|
|
imageUrl = API().getArtwork(season, "Thumb")
|
2015-05-01 21:57:24 +10:00
|
|
|
self.addOrUpdateArt(imageUrl, seasonid, "season", "landscape", cursor)
|
2015-04-15 12:20:08 +10:00
|
|
|
|
|
|
|
imageUrl = API().getArtwork(season, "Primary")
|
2015-05-01 21:57:24 +10:00
|
|
|
self.addOrUpdateArt(imageUrl, seasonid, "season", "poster", cursor)
|
2015-04-15 12:20:08 +10:00
|
|
|
|
|
|
|
imageUrl = API().getArtwork(season, "Banner")
|
2015-06-18 20:10:49 +10:00
|
|
|
self.addOrUpdateArt(imageUrl, seasonid, "season", "banner", cursor)
|
|
|
|
# Set All season poster
|
|
|
|
MBitem = ReadEmbyDB().getFullItem(embyTvShowId)
|
|
|
|
seasonNum = -1
|
|
|
|
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?", (kodiTvShowId, seasonNum))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result == None:
|
|
|
|
# Create the all-season
|
|
|
|
cursor.execute("select coalesce(max(idSeason),0) as seasonid from seasons")
|
|
|
|
seasonid = cursor.fetchone()[0]
|
|
|
|
seasonid = seasonid + 1
|
|
|
|
cursor.execute("INSERT into seasons(idSeason, idShow, season) values(?, ?, ?)", (seasonid, kodiTvShowId, seasonNum))
|
|
|
|
else:
|
|
|
|
seasonid = result[0]
|
|
|
|
imageUrl = API().getArtwork(MBitem, "Primary")
|
|
|
|
self.addOrUpdateArt(imageUrl, seasonid, "season", "poster", cursor)
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-01 21:57:24 +10:00
|
|
|
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType, cursor):
|
2015-04-15 12:20:08 +10:00
|
|
|
updateDone = False
|
2015-05-01 21:57:24 +10:00
|
|
|
if imageUrl:
|
|
|
|
cursor.execute("SELECT url FROM art WHERE media_id = ? AND media_type = ? AND type = ?", (kodiId, mediaType, imageType))
|
2015-04-15 12:20:08 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if(result == None):
|
2015-05-01 22:06:31 +10:00
|
|
|
utils.logMsg("ArtworkSync", "Adding Art Link for kodiId: " + str(kodiId) + " (" + imageUrl + ")")
|
2015-05-01 21:57:24 +10:00
|
|
|
cursor.execute("INSERT INTO art(media_id, media_type, type, url) values(?, ?, ?, ?)", (kodiId, mediaType, imageType, imageUrl))
|
2015-04-15 12:20:08 +10:00
|
|
|
else:
|
|
|
|
url = result[0];
|
|
|
|
if(url != imageUrl):
|
2015-05-01 22:06:31 +10:00
|
|
|
utils.logMsg("ArtworkSync", "Updating Art Link for kodiId: " + str(kodiId) + " (" + url + ") -> (" + imageUrl + ")")
|
2015-05-01 21:57:24 +10:00
|
|
|
cursor.execute("UPDATE art set url = ? WHERE media_id = ? AND media_type = ? AND type = ?", (imageUrl, kodiId, mediaType, imageType))
|
2015-06-06 08:11:24 +10:00
|
|
|
|
|
|
|
#cache fanart and poster in Kodi texture cache
|
|
|
|
if imageType == "fanart" or imageType == "poster":
|
|
|
|
self.textureCache.CacheTexture(imageUrl)
|
2015-04-15 12:20:08 +10:00
|
|
|
|
2015-05-02 10:26:06 +10:00
|
|
|
def setKodiResumePoint(self, fileid, resume_seconds, total_seconds, cursor):
|
2015-03-18 06:02:42 +11:00
|
|
|
|
|
|
|
cursor.execute("delete FROM bookmark WHERE idFile = ?", (fileid,))
|
2015-05-02 10:26:06 +10:00
|
|
|
if resume_seconds != 0:
|
|
|
|
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(?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(bookmarksql, (bookmarkId,fileid,resume_seconds,total_seconds,None,"DVDPlayer",None,1))
|
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
def AddPeopleToMedia(self, id, people, mediatype, connection, cursor):
|
2015-03-18 06:02:42 +11:00
|
|
|
downloadUtils = DownloadUtils()
|
2015-03-20 11:21:43 +11:00
|
|
|
|
2015-04-08 18:01:04 +10:00
|
|
|
kodiVersion = 14
|
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("15"):
|
|
|
|
kodiVersion = 15
|
2015-03-20 11:21:43 +11:00
|
|
|
|
|
|
|
if(people != None):
|
|
|
|
for person in people:
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
Name = person.get("Name")
|
|
|
|
actorid = None
|
2015-05-07 01:43:40 +10:00
|
|
|
|
|
|
|
# Get existing actor
|
2015-05-02 00:58:20 +10:00
|
|
|
if kodiVersion == 15:
|
|
|
|
# Kodi Isengard database #
|
|
|
|
cursor.execute("SELECT actor_id as actorid FROM actor WHERE name = ?",(Name,))
|
|
|
|
else:
|
|
|
|
# Kodi Gotham or Helix database #
|
|
|
|
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ?",(Name,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
actorid = result[0]
|
|
|
|
if actorid == None:
|
2015-05-01 21:30:21 +10:00
|
|
|
if kodiVersion == 15:
|
|
|
|
# Kodi Isengard database #
|
2015-05-02 00:58:20 +10:00
|
|
|
cursor.execute("select coalesce(max(actor_id),0) as actorid from actor")
|
|
|
|
actorid = cursor.fetchone()[0]
|
|
|
|
actorid = actorid + 1
|
2015-05-07 01:43:40 +10:00
|
|
|
peoplesql="insert into actor(actor_id, name) values(?, ?)"
|
2015-05-01 21:30:21 +10:00
|
|
|
else:
|
|
|
|
# Kodi Gotham or Helix database #
|
2015-05-02 00:58:20 +10:00
|
|
|
cursor.execute("select coalesce(max(idActor),0) as actorid from actors")
|
|
|
|
actorid = cursor.fetchone()[0]
|
|
|
|
actorid = actorid + 1
|
2015-05-07 01:43:40 +10:00
|
|
|
peoplesql="insert into actors(idActor, strActor) values(?, ?)"
|
2015-05-02 00:58:20 +10:00
|
|
|
utils.logMsg("AddPeopleToMedia", "Processing : " + person.get("Name"))
|
2015-05-07 01:43:40 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,Name))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-07 01:43:40 +10:00
|
|
|
### add people image to art table
|
|
|
|
Thumb = downloadUtils.imageUrl(person.get("Id"), "Primary", 0, 400, 400)
|
|
|
|
if Thumb:
|
|
|
|
if(person.get("Type") == "Director"):
|
|
|
|
arttype = "director"
|
|
|
|
elif(person.get("Type") == "Writer" or person.get("Type") == "Writing"):
|
|
|
|
arttype = "writer"
|
|
|
|
else:
|
|
|
|
arttype = "actor"
|
|
|
|
self.addOrUpdateArt(Thumb, actorid, arttype, "thumb", cursor)
|
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
#### ACTORS ######
|
|
|
|
if(person.get("Type") == "Actor"):
|
2015-05-01 21:30:21 +10:00
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
Role = person.get("Role")
|
2015-05-01 21:30:21 +10:00
|
|
|
if kodiVersion == 15:
|
|
|
|
# Kodi Isengard database #
|
2015-05-10 22:28:42 +10:00
|
|
|
peoplesql="INSERT OR REPLACE into actor_link(actor_id, media_id, media_type,role) values(?, ?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid, id, mediatype, Role))
|
2015-05-01 21:30:21 +10:00
|
|
|
else:
|
|
|
|
# Kodi Gotham or Helix database #
|
|
|
|
if mediatype == "movie":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinkmovie(idActor, idMovie, strRole, iOrder) values(?, ?, ?, ?)"
|
2015-05-02 02:32:13 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,id,Role,None))
|
2015-05-01 21:30:21 +10:00
|
|
|
if mediatype == "tvshow":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinktvshow(idActor, idShow, strRole, iOrder) values(?, ?, ?, ?)"
|
2015-05-02 02:32:13 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,id,Role,None))
|
2015-05-01 21:30:21 +10:00
|
|
|
if mediatype == "episode":
|
|
|
|
peoplesql="INSERT OR REPLACE into actorlinkepisode(idActor, idEpisode, strRole, iOrder) values(?, ?, ?, ?)"
|
2015-05-02 02:32:13 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,id,Role,None))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#### DIRECTORS ######
|
|
|
|
if(person.get("Type") == "Director"):
|
|
|
|
|
|
|
|
if kodiVersion == 15:
|
|
|
|
# Kodi Isengard database #
|
|
|
|
peoplesql="INSERT OR REPLACE into director_link(actor_id, media_id, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid, id, mediatype))
|
|
|
|
else:
|
|
|
|
# Kodi Gotham or Helix database #
|
|
|
|
if mediatype == "movie":
|
|
|
|
peoplesql="INSERT OR REPLACE into directorlinkmovie(idDirector, idMovie) values(?, ?)"
|
|
|
|
if mediatype == "tvshow":
|
|
|
|
peoplesql="INSERT OR REPLACE into directorlinktvshow(idDirector, idShow) values(?, ?)"
|
|
|
|
if mediatype == "musicvideo":
|
|
|
|
peoplesql="INSERT OR REPLACE into directorlinkmusicvideo(idDirector, idMVideo) values(?, ?)"
|
2015-05-02 02:32:13 +10:00
|
|
|
if mediatype == "episode":
|
|
|
|
peoplesql="INSERT OR REPLACE into directorlinkepisode(idDirector, idEpisode) values(?, ?)"
|
2015-05-02 00:58:20 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,id))
|
|
|
|
|
|
|
|
#### WRITERS ######
|
|
|
|
if(person.get("Type") == "Writing" or person.get("Type") == "Writer"):
|
|
|
|
|
|
|
|
if kodiVersion == 15:
|
|
|
|
# Kodi Isengard database #
|
|
|
|
peoplesql="INSERT OR REPLACE into writer_link(actor_id, media_id, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(peoplesql, (actorid, id, mediatype))
|
|
|
|
else:
|
|
|
|
# Kodi Gotham or Helix database #
|
|
|
|
if mediatype == "movie":
|
|
|
|
peoplesql="INSERT OR REPLACE into writerlinkmovie(idWriter, idMovie) values(?, ?)"
|
2015-05-02 02:32:13 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,id))
|
2015-05-02 00:58:20 +10:00
|
|
|
if mediatype == "episode":
|
|
|
|
peoplesql="INSERT OR REPLACE into writerlinkepisode(idWriter, idEpisode) values(?, ?)"
|
2015-05-02 02:32:13 +10:00
|
|
|
cursor.execute(peoplesql, (actorid,id))
|
|
|
|
|
2015-05-06 00:20:09 +10:00
|
|
|
def AddGenresToMedia(self, id, genres, mediatype, cursor):
|
|
|
|
|
|
|
|
if genres:
|
|
|
|
|
|
|
|
kodiVersion = 14
|
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("15"):
|
|
|
|
kodiVersion = 15
|
|
|
|
|
|
|
|
for genre in genres:
|
|
|
|
|
|
|
|
if kodiVersion == 15:
|
|
|
|
genre_id = None
|
|
|
|
cursor.execute("SELECT genre_id as genre_id FROM genre WHERE name = ?",(genre,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
genre_id = result[0]
|
|
|
|
#create genre
|
|
|
|
if genre_id == None:
|
|
|
|
cursor.execute("select coalesce(max(genre_id),0) as genre_id from genre")
|
|
|
|
genre_id = cursor.fetchone()[0]
|
|
|
|
genre_id = genre_id + 1
|
|
|
|
sql="insert into genre(genre_id, name) values(?, ?)"
|
|
|
|
cursor.execute(sql, (genre_id,genre))
|
|
|
|
utils.logMsg("AddGenresToMedia", "Processing : " + genre)
|
|
|
|
|
|
|
|
#assign genre to item
|
|
|
|
sql="INSERT OR REPLACE into genre_link(genre_id, media_id, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(sql, (genre_id, id, mediatype))
|
|
|
|
|
|
|
|
else:
|
|
|
|
idGenre = None
|
|
|
|
cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ?",(genre,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
idGenre = result[0]
|
|
|
|
#create genre
|
|
|
|
if idGenre == None:
|
|
|
|
cursor.execute("select coalesce(max(idGenre),0) as idGenre from genre")
|
|
|
|
idGenre = cursor.fetchone()[0]
|
|
|
|
idGenre = idGenre + 1
|
|
|
|
sql="insert into genre(idGenre, strGenre) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idGenre,genre))
|
|
|
|
|
|
|
|
#assign genre to item
|
|
|
|
if mediatype == "movie":
|
|
|
|
sql="INSERT OR REPLACE into genrelinkmovie(idGenre, idMovie) values(?, ?)"
|
|
|
|
if mediatype == "tvshow":
|
|
|
|
sql="INSERT OR REPLACE into genrelinktvshow(idGenre, idShow) values(?, ?)"
|
|
|
|
if mediatype == "episode":
|
|
|
|
return
|
|
|
|
if mediatype == "musicvideo":
|
|
|
|
sql="INSERT OR REPLACE into genrelinkmusicvideo(idGenre, idMVideo) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idGenre,id))
|
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
def AddCountriesToMedia(self, id, countries, mediatype, cursor):
|
|
|
|
if countries:
|
2015-05-02 00:58:20 +10:00
|
|
|
kodiVersion = 14
|
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("15"):
|
|
|
|
kodiVersion = 15
|
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
for country in countries:
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
if kodiVersion == 15:
|
2015-05-06 00:16:34 +10:00
|
|
|
country_id = None
|
|
|
|
cursor.execute("SELECT country_id as country_id FROM country WHERE name = ?",(country,))
|
2015-05-02 00:58:20 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
2015-05-06 00:16:34 +10:00
|
|
|
country_id = result[0]
|
|
|
|
#create country
|
|
|
|
if country_id == None:
|
|
|
|
cursor.execute("select coalesce(max(country_id),0) as country_id from country")
|
|
|
|
country_id = cursor.fetchone()[0]
|
|
|
|
country_id = country_id + 1
|
|
|
|
sql="insert into country(country_id, name) values(?, ?)"
|
|
|
|
cursor.execute(sql, (country_id,country))
|
|
|
|
utils.logMsg("AddCountriesToMedia", "Processing : " + country)
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
#assign country to item
|
|
|
|
sql="INSERT OR REPLACE into country_link(country_id, media_id, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(sql, (country_id, id, mediatype))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
else:
|
2015-05-06 00:16:34 +10:00
|
|
|
idCountry = None
|
|
|
|
cursor.execute("SELECT idCountry as idCountry FROM country WHERE strCountry = ?",(country,))
|
2015-05-02 00:58:20 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
2015-05-06 00:16:34 +10:00
|
|
|
idCountry = result[0]
|
|
|
|
#create country
|
|
|
|
if idCountry == None:
|
|
|
|
cursor.execute("select coalesce(max(idCountry),0) as idCountry from country")
|
|
|
|
idCountry = cursor.fetchone()[0]
|
|
|
|
idCountry = idCountry + 1
|
|
|
|
sql="insert into country(idCountry, strCountry) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idCountry,country))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-06 00:16:34 +10:00
|
|
|
#assign country to item
|
2015-05-02 00:58:20 +10:00
|
|
|
if mediatype == "movie":
|
2015-05-06 00:16:34 +10:00
|
|
|
sql="INSERT OR REPLACE into countrylinkmovie(idCountry, idMovie) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idCountry,id))
|
|
|
|
else:
|
|
|
|
#only movies have a country field
|
2015-05-03 06:25:08 +10:00
|
|
|
return
|
2015-06-06 08:11:24 +10:00
|
|
|
|
2015-05-02 00:58:20 +10:00
|
|
|
def AddStudiosToMedia(self, id, studios, mediatype, cursor):
|
|
|
|
|
|
|
|
if studios:
|
|
|
|
|
|
|
|
kodiVersion = 14
|
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("15"):
|
|
|
|
kodiVersion = 15
|
|
|
|
|
|
|
|
for studio in studios:
|
|
|
|
|
|
|
|
if kodiVersion == 15:
|
|
|
|
studio_id = None
|
|
|
|
cursor.execute("SELECT studio_id as studio_id FROM studio WHERE name = ?",(studio,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
studio_id = result[0]
|
|
|
|
#create studio
|
|
|
|
if studio_id == None:
|
|
|
|
cursor.execute("select coalesce(max(studio_id),0) as studio_id from studio")
|
|
|
|
studio_id = cursor.fetchone()[0]
|
|
|
|
studio_id = studio_id + 1
|
|
|
|
sql="insert into studio(studio_id, name) values(?, ?)"
|
|
|
|
cursor.execute(sql, (studio_id,studio))
|
2015-05-03 06:02:06 +10:00
|
|
|
utils.logMsg("AddstudiosToMedia", "Processing : " + studio)
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
#assign studio to item
|
|
|
|
sql="INSERT OR REPLACE into studio_link(studio_id, media_id, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(sql, (studio_id, id, mediatype))
|
|
|
|
|
|
|
|
else:
|
|
|
|
idstudio = None
|
|
|
|
cursor.execute("SELECT idstudio as idstudio FROM studio WHERE strstudio = ?",(studio,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
idstudio = result[0]
|
|
|
|
#create studio
|
|
|
|
if idstudio == None:
|
|
|
|
cursor.execute("select coalesce(max(idstudio),0) as idstudio from studio")
|
|
|
|
idstudio = cursor.fetchone()[0]
|
|
|
|
idstudio = idstudio + 1
|
|
|
|
sql="insert into studio(idstudio, strstudio) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idstudio,studio))
|
|
|
|
|
|
|
|
#assign studio to item
|
|
|
|
if mediatype == "movie":
|
|
|
|
sql="INSERT OR REPLACE into studiolinkmovie(idstudio, idMovie) values(?, ?)"
|
2015-05-03 09:59:08 +10:00
|
|
|
if mediatype == "musicvideo":
|
2015-05-03 10:01:15 +10:00
|
|
|
sql="INSERT OR REPLACE into studiolinkmusicvideo(idstudio, idMVideo) values(?, ?)"
|
2015-05-02 00:58:20 +10:00
|
|
|
if mediatype == "tvshow":
|
|
|
|
sql="INSERT OR REPLACE into studiolinktvshow(idstudio, idShow) values(?, ?)"
|
|
|
|
if mediatype == "episode":
|
|
|
|
sql="INSERT OR REPLACE into studiolinkepisode(idstudio, idEpisode) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idstudio,id))
|
|
|
|
|
2015-05-03 09:46:11 +10:00
|
|
|
def AddTagToMedia(self, id, tag, mediatype, cursor, doRemove=False):
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
if tag:
|
|
|
|
|
|
|
|
kodiVersion = 14
|
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("15"):
|
|
|
|
kodiVersion = 15
|
|
|
|
|
|
|
|
if kodiVersion == 15:
|
|
|
|
tag_id = None
|
|
|
|
cursor.execute("SELECT tag_id as tag_id FROM tag WHERE name = ?",(tag,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
tag_id = result[0]
|
|
|
|
#create tag
|
|
|
|
if tag_id == None:
|
|
|
|
cursor.execute("select coalesce(max(tag_id),0) as tag_id from tag")
|
|
|
|
tag_id = cursor.fetchone()[0]
|
|
|
|
tag_id = tag_id + 1
|
|
|
|
sql="insert into tag(tag_id, name) values(?, ?)"
|
|
|
|
cursor.execute(sql, (tag_id,tag))
|
2015-05-03 06:02:06 +10:00
|
|
|
utils.logMsg("AddTagToMedia", "Adding tag: " + tag)
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-03 09:46:11 +10:00
|
|
|
#assign tag to item
|
|
|
|
if doRemove:
|
|
|
|
sql="DELETE FROM tag_link WHERE media_id = ? AND media_type = ? AND tag_id = ?"
|
|
|
|
cursor.execute(sql, (id, mediatype, tag_id))
|
|
|
|
else:
|
|
|
|
sql="INSERT OR REPLACE into tag_link(tag_id, media_id, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(sql, (tag_id, id, mediatype))
|
2015-05-02 00:58:20 +10:00
|
|
|
|
|
|
|
else:
|
|
|
|
idTag = None
|
2015-05-02 01:13:22 +10:00
|
|
|
cursor.execute("SELECT idTag as idTag FROM tag WHERE strTag = ?",(tag,))
|
2015-05-02 00:58:20 +10:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
idTag = result[0]
|
|
|
|
#create idTag
|
|
|
|
if idTag == None:
|
|
|
|
cursor.execute("select coalesce(max(idTag),0) as idTag from tag")
|
|
|
|
idTag = cursor.fetchone()[0]
|
|
|
|
idTag = idTag + 1
|
|
|
|
sql="insert into tag(idTag, strTag) values(?, ?)"
|
|
|
|
cursor.execute(sql, (idTag,tag))
|
2015-05-04 04:30:24 +10:00
|
|
|
utils.logMsg("AddTagToMedia", "Adding tag: " + tag)
|
2015-05-02 00:58:20 +10:00
|
|
|
|
2015-05-03 09:46:11 +10:00
|
|
|
#assign tag to item
|
|
|
|
if doRemove:
|
|
|
|
sql="DELETE FROM taglinks WHERE idMedia = ? AND media_type = ? AND idTag = ?"
|
|
|
|
cursor.execute(sql, (id, mediatype, idTag))
|
|
|
|
else:
|
|
|
|
sql="INSERT OR REPLACE into taglinks(idTag, idMedia, media_type) values(?, ?, ?)"
|
|
|
|
cursor.execute(sql, (idTag, id, mediatype))
|
2015-05-02 10:57:58 +10:00
|
|
|
|
|
|
|
def AddStreamDetailsToMedia(self, streamdetails, fileid, cursor):
|
|
|
|
|
|
|
|
#first remove any existing entries
|
|
|
|
cursor.execute("delete FROM streamdetails WHERE idFile = ?", (fileid,))
|
|
|
|
if streamdetails:
|
|
|
|
#video details
|
2015-05-03 08:44:35 +10:00
|
|
|
sql="insert into streamdetails(idFile, iStreamType, strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight, strStereoMode) values(?, ?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(sql, (fileid,0,streamdetails.get("videocodec"),streamdetails.get("aspectratio"),streamdetails.get("width"),streamdetails.get("height"),streamdetails.get("3dformat")))
|
2015-05-02 10:57:58 +10:00
|
|
|
#audio details
|
2015-06-13 05:49:07 +10:00
|
|
|
sql="insert into streamdetails(idFile, iStreamType, strAudioCodec, iAudioChannels, strAudioLanguage, strSubtitleLanguage) values(?, ?, ?, ?, ?, ?)"
|
|
|
|
cursor.execute(sql, (fileid,1,streamdetails.get("audiocodec"),streamdetails.get("channels"),streamdetails.get("audiolanguage"),streamdetails.get("subtitlelanguage")))
|
2015-05-03 00:49:47 +10:00
|
|
|
|
2015-04-05 03:20:48 +10:00
|
|
|
def addBoxsetToKodiLibrary(self, boxset, connection, cursor):
|
2015-03-25 03:47:26 +11:00
|
|
|
|
|
|
|
strSet = boxset["Name"]
|
|
|
|
# check if exists
|
|
|
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
setid = None
|
|
|
|
if result != None:
|
|
|
|
setid = result[0]
|
|
|
|
currentsetartsql = "SELECT type, url FROM art where media_type = ? and media_id = ? and url != ''"
|
|
|
|
cursor.execute(currentsetartsql, ("set", setid))
|
|
|
|
existing_type_map = {}
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
for row in rows:
|
|
|
|
existing_type_map[row[0] ] = row[1]
|
|
|
|
|
|
|
|
artwork = {}
|
|
|
|
artwork["poster"] = API().getArtwork(boxset, "Primary")
|
|
|
|
artwork["banner"] = API().getArtwork(boxset, "Banner")
|
|
|
|
artwork["clearlogo"] = API().getArtwork(boxset, "Logo")
|
|
|
|
artwork["clearart"] = API().getArtwork(boxset, "Art")
|
|
|
|
artwork["landscape"] = API().getArtwork(boxset, "Thumb")
|
|
|
|
artwork["discart"] = API().getArtwork(boxset, "Disc")
|
|
|
|
artwork["fanart"] = API().getArtwork(boxset, "Backdrop")
|
|
|
|
|
2015-03-25 05:58:13 +11:00
|
|
|
art_types = ['poster','fanart','landscape','clearlogo','clearart','banner','discart']
|
2015-03-25 03:47:26 +11:00
|
|
|
for update_type in art_types:
|
|
|
|
if ( update_type in existing_type_map ):
|
|
|
|
if ( existing_type_map[update_type] != artwork[update_type] ) and artwork[update_type] != '':
|
|
|
|
setupdateartsql = "UPDATE art SET url = ? where media_type = ? and media_id = ? and type = ?"
|
|
|
|
cursor.execute(setupdateartsql,(artwork[update_type],"set",setid,update_type))
|
|
|
|
elif artwork[update_type] != '':
|
|
|
|
setartsql = "INSERT INTO art(media_id, media_type, type, url) VALUES(?,?,?,?)"
|
|
|
|
cursor.execute(setartsql,(setid,"set",update_type,artwork[update_type]))
|
|
|
|
|
|
|
|
if setid == None:
|
|
|
|
# insert not exists
|
|
|
|
setssql="INSERT INTO sets (idSet, strSet) values(?, ?)"
|
|
|
|
cursor.execute(setssql, (None,strSet))
|
|
|
|
#if OK:
|
2015-05-03 22:44:23 +10:00
|
|
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
|
|
|
|
2015-03-25 03:47:26 +11:00
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
setid = result[0]
|
2015-05-03 22:44:23 +10:00
|
|
|
|
|
|
|
currentsetartsql = "SELECT type, url FROM art where media_type = ? and media_id = ? and url != ''"
|
|
|
|
cursor.execute(currentsetartsql, ("set", setid))
|
|
|
|
existing_type_map = {}
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
for row in rows:
|
|
|
|
existing_type_map[row[0] ] = row[1]
|
|
|
|
|
|
|
|
artwork = {}
|
|
|
|
artwork["poster"] = API().getArtwork(boxset, "Primary")
|
|
|
|
artwork["banner"] = API().getArtwork(boxset, "Banner")
|
|
|
|
artwork["clearlogo"] = API().getArtwork(boxset, "Logo")
|
|
|
|
artwork["clearart"] = API().getArtwork(boxset, "Art")
|
|
|
|
artwork["landscape"] = API().getArtwork(boxset, "Thumb")
|
|
|
|
artwork["discart"] = API().getArtwork(boxset, "Disc")
|
|
|
|
artwork["fanart"] = API().getArtwork(boxset, "Backdrop")
|
|
|
|
|
|
|
|
art_types = ['poster','fanart','landscape','clearlogo','clearart','banner','discart']
|
|
|
|
for update_type in art_types:
|
|
|
|
if ( update_type in existing_type_map ):
|
|
|
|
if ( existing_type_map[update_type] != artwork[update_type] ) and artwork[update_type] != '':
|
|
|
|
setupdateartsql = "UPDATE art SET url = ? where media_type = ? and media_id = ? and type = ?"
|
|
|
|
cursor.execute(setupdateartsql,(artwork[update_type],"set",setid,update_type))
|
|
|
|
elif artwork[update_type] != '':
|
|
|
|
setartsql = "INSERT INTO art(media_id, media_type, type, url) VALUES(?,?,?,?)"
|
|
|
|
cursor.execute(setartsql,(setid,"set",update_type,artwork[update_type]))
|
2015-03-25 03:47:26 +11:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2015-05-03 22:44:23 +10:00
|
|
|
def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset, connection, cursor):
|
2015-03-25 03:47:26 +11:00
|
|
|
strSet = boxset["Name"]
|
2015-05-03 22:44:23 +10:00
|
|
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(boxsetmovie["Id"],))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
if result != None:
|
|
|
|
movieid = result[0]
|
|
|
|
else:
|
|
|
|
movieid = None
|
|
|
|
if movieid != None:
|
|
|
|
# check if exists
|
|
|
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
setid = None
|
|
|
|
if result != None:
|
|
|
|
setid = result[0]
|
|
|
|
|
|
|
|
pathsql="update movie SET idSet = ? WHERE idMovie = ?"
|
|
|
|
cursor.execute(pathsql, (setid, movieid))
|
|
|
|
|
|
|
|
#update the checksum in emby table
|
|
|
|
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(boxsetmovie),boxsetmovie["Id"]))
|
|
|
|
|
2015-06-06 08:11:24 +10:00
|
|
|
|