work in progress - move home videos to plugin listing

This commit is contained in:
marcelveldt 2016-01-11 22:20:34 +01:00
parent b7f0f869eb
commit ee9f08080e
9 changed files with 172 additions and 398 deletions

View file

@ -61,15 +61,13 @@ class Items(object):
'Movie': Movies,
'BoxSet': Movies,
'MusicVideo': MusicVideos,
'Series': TVShows,
'Season': TVShows,
'Episode': TVShows,
'MusicAlbum': Music,
'MusicArtist': Music,
'AlbumArtist': Music,
'Audio': Music,
'Video': HomeVideos
'Audio': Music
}
total = 0
@ -169,13 +167,6 @@ class Items(object):
'userdata': items_process.updateUserdata,
'remove': items_process.remove
}
elif itemtype == "Video":
actions = {
'added': items_process.added,
'update': items_process.add_update,
'userdata': items_process.updateUserdata,
'remove': items_process.remove
}
else:
self.logMsg("Unsupported itemtype: %s." % itemtype, 1)
actions = {}
@ -624,257 +615,6 @@ class Movies(Items):
self.logMsg("Deleted %s %s from kodi database" % (mediatype, itemid), 1)
class HomeVideos(Items):
def __init__(self, embycursor, kodicursor):
Items.__init__(self, embycursor, kodicursor)
def added(self, items, pdialog):
total = len(items)
count = 0
for hvideo in items:
title = hvideo['Name']
if pdialog:
percentage = int((float(count) / float(total))*100)
pdialog.update(percentage, message=title)
count += 1
self.add_update(hvideo)
if not pdialog and self.contentmsg:
self.contentPop(title)
def add_update(self, item, viewtag=None, viewid=None):
# Process single movie
kodicursor = self.kodicursor
emby_db = self.emby_db
kodi_db = self.kodi_db
artwork = self.artwork
API = api.API(item)
# 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
update_item = True
itemid = item['Id']
emby_dbitem = emby_db.getItem_byId(itemid)
try:
hmovieid = emby_dbitem[0]
fileid = emby_dbitem[1]
pathid = emby_dbitem[2]
self.logMsg("hmovieid: %s fileid: %s pathid: %s" % (hmovieid, fileid, pathid), 1)
except TypeError:
update_item = False
self.logMsg("hmovieid: %s not found." % itemid, 2)
# movieid
kodicursor.execute("select coalesce(max(idMovie),0) from movie")
hmovieid = kodicursor.fetchone()[0] + 1
if not viewtag or not viewid:
# Get view tag from emby
viewtag, viewid, mediatype = self.emby.getView_embyId(itemid)
self.logMsg("View tag found: %s" % viewtag, 2)
# fileId information
checksum = API.getChecksum()
dateadded = API.getDateCreated()
userdata = API.getUserData()
playcount = userdata['PlayCount']
dateplayed = userdata['LastPlayedDate']
# item details
people = API.getPeople()
title = item['Name']
year = item.get('ProductionYear')
sorttitle = item['SortName']
runtime = API.getRuntime()
genre = "HomeVideos"
##### GET THE FILE AND PATH #####
playurl = API.getFilePath()
if "\\" in playurl:
# Local path
filename = playurl.rsplit("\\", 1)[1]
else: # Network share
filename = playurl.rsplit("/", 1)[1]
if self.directpath:
# Direct paths is set the Kodi way
if utils.window('emby_pathverified') != "true" and not xbmcvfs.exists(playurl):
# Validate the path is correct with user intervention
utils.window('emby_directPath', clear=True)
resp = xbmcgui.Dialog().yesno(
heading="Can't validate path",
line1=(
"Kodi can't locate file: %s. Verify the path. "
"You may to verify your network credentials in the "
"add-on settings or use the emby path substitution "
"to format your path correctly. Stop syncing?"
% playurl))
if resp:
utils.window('emby_shouldStop', value="true")
return False
path = playurl.replace(filename, "")
utils.window('emby_pathverified', value="true")
else:
# Set plugin path and media flags using real filename
path = "plugin://plugin.video.emby.movies/"
params = {
'filename': filename.encode('utf-8'),
'id': itemid,
'dbid': hmovieid,
'mode': "play"
}
filename = "%s?%s" % (path, urllib.urlencode(params))
##### UPDATE THE MOVIE #####
if update_item:
self.logMsg("UPDATE homemovie itemid: %s - Title: %s" % (itemid, title), 1)
# Update the movie entry
query = ' '.join((
"UPDATE movie",
"SET c00 = ?, c07 = ?, c10 = ?, c11 = ?, c14 = ?, c16 = ?",
"WHERE idMovie = ?"
))
kodicursor.execute(query, (title, year, sorttitle, runtime, genre, title, hmovieid))
# Update the checksum in emby table
emby_db.updateReference(itemid, checksum)
##### OR ADD THE MOVIE #####
else:
self.logMsg("ADD homemovie itemid: %s - Title: %s" % (itemid, title), 1)
# Add path
pathid = kodi_db.addPath(path)
# Add the file
fileid = kodi_db.addFile(filename, pathid)
# Create the movie entry
query = (
'''
INSERT INTO movie(
idMovie, idFile, c00, c07, c10, c11, c14, c16)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
'''
)
kodicursor.execute(query, (hmovieid, fileid, title, year, sorttitle, runtime,
genre, title))
# Create the reference in emby table
emby_db.addReference(itemid, hmovieid, "Video", "movie", fileid, pathid,
None, checksum, viewid)
# Update the path
query = ' '.join((
"UPDATE path",
"SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?",
"WHERE idPath = ?"
))
kodicursor.execute(query, (path, "movies", "metadata.local", 1, pathid))
# Update the file
query = ' '.join((
"UPDATE files",
"SET idPath = ?, strFilename = ?, dateAdded = ?",
"WHERE idFile = ?"
))
kodicursor.execute(query, (pathid, filename, dateadded, fileid))
# Process artwork
artwork.addArtwork(artwork.getAllArtwork(item), hmovieid, "movie", kodicursor)
# Process stream details
streams = API.getMediaStreams()
kodi_db.addStreams(fileid, streams, runtime)
# Process tags: view, emby tags
tags = [viewtag]
tags.extend(item['Tags'])
if userdata['Favorite']:
tags.append("Favorite homemovies")
kodi_db.addTags(hmovieid, tags, "movie")
# Process playstates
resume = API.adjustResume(userdata['Resume'])
total = round(float(runtime), 6)
kodi_db.addPlaystate(fileid, resume, total, playcount, dateplayed)
def updateUserdata(self, item):
# This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
# Poster with progress bar
emby_db = self.emby_db
kodi_db = self.kodi_db
API = api.API(item)
# Get emby information
itemid = item['Id']
checksum = API.getChecksum()
userdata = API.getUserData()
runtime = API.getRuntime()
# Get Kodi information
emby_dbitem = emby_db.getItem_byId(itemid)
try:
movieid = emby_dbitem[0]
fileid = emby_dbitem[1]
self.logMsg(
"Update playstate for homemovie: %s fileid: %s"
% (item['Name'], fileid), 1)
except TypeError:
return
# Process favorite tags
if userdata['Favorite']:
kodi_db.addTag(movieid, "Favorite homemovies", "movie")
else:
kodi_db.removeTag(movieid, "Favorite homemovies", "movie")
# Process playstates
playcount = userdata['PlayCount']
dateplayed = userdata['LastPlayedDate']
resume = API.adjustResume(userdata['Resume'])
total = round(float(runtime), 6)
kodi_db.addPlaystate(fileid, resume, total, playcount, dateplayed)
emby_db.updateReference(itemid, checksum)
def remove(self, itemid):
# Remove movieid, fileid, emby reference
emby_db = self.emby_db
kodicursor = self.kodicursor
artwork = self.artwork
emby_dbitem = emby_db.getItem_byId(itemid)
try:
hmovieid = emby_dbitem[0]
fileid = emby_dbitem[1]
self.logMsg("Removing hmovieid: %s fileid: %s" % (hmovieid, fileid), 1)
except TypeError:
return
# Remove artwork
artwork.deleteArtwork(hmovieid, "movie", kodicursor)
# Delete kodi movie and file
kodicursor.execute("DELETE FROM movie WHERE idMovie = ?", (hmovieid,))
kodicursor.execute("DELETE FROM files WHERE idFile = ?", (fileid,))
# Remove the emby reference
emby_db.removeItem(itemid)
self.logMsg("Deleted homemovie %s from kodi database" % itemid, 1)
class MusicVideos(Items):