mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-24 09:46:11 +00:00
Pylint (#67)
This commit is contained in:
parent
6eb8cdfa30
commit
2b0c9d1bbc
11 changed files with 268 additions and 327 deletions
|
@ -157,7 +157,7 @@ class Main(object):
|
|||
if __name__ == "__main__":
|
||||
|
||||
log.info("plugin.video.emby started")
|
||||
|
||||
|
||||
try:
|
||||
Main()
|
||||
except Exception as error:
|
||||
|
@ -165,5 +165,5 @@ if __name__ == "__main__":
|
|||
errStrings = ga.formatException()
|
||||
ga.sendEventData("Exception", errStrings[0], errStrings[1])
|
||||
log.exception(error)
|
||||
|
||||
|
||||
log.info("plugin.video.emby stopped")
|
||||
|
|
|
@ -110,7 +110,7 @@ class DownloadUtils(object):
|
|||
}
|
||||
|
||||
self.downloadUrl(url, postBody=data, action_type="POST")
|
||||
log.debug("Posted capabilities to %s" % self.session['Server'])
|
||||
log.debug("Posted capabilities to %s", self.session['Server'])
|
||||
|
||||
# Attempt at getting sessionId
|
||||
url = "{server}/emby/Sessions?DeviceId=%s&format=json" % device_id
|
||||
|
@ -301,7 +301,7 @@ class DownloadUtils(object):
|
|||
raise Warning('restricted')
|
||||
|
||||
elif (response.headers['X-Application-Error-Code'] ==
|
||||
"UnauthorizedAccessException"):
|
||||
"UnauthorizedAccessException"):
|
||||
# User tried to do something his emby account doesn't allow
|
||||
pass
|
||||
|
||||
|
|
|
@ -3,23 +3,10 @@
|
|||
##################################################################################################
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
from ntpath import dirname
|
||||
from datetime import datetime
|
||||
|
||||
import xbmc
|
||||
import xbmcgui
|
||||
import xbmcvfs
|
||||
|
||||
import api
|
||||
import artwork
|
||||
import downloadutils
|
||||
import embydb_functions as embydb
|
||||
import kodidb_functions as kodidb
|
||||
import read_embyserver as embyserver
|
||||
import musicutils
|
||||
from objects import Movies, MusicVideos, TVShows, Music
|
||||
from utils import window, settings, language as lang, kodiSQL
|
||||
from utils import settings, kodiSQL
|
||||
|
||||
#################################################################################################
|
||||
|
||||
|
@ -36,28 +23,15 @@ class Items(object):
|
|||
self.embycursor = embycursor
|
||||
self.kodicursor = kodicursor
|
||||
|
||||
self.doUtils = downloadutils.DownloadUtils()
|
||||
|
||||
self.kodiversion = int(xbmc.getInfoLabel('System.BuildVersion')[:2])
|
||||
self.directpath = settings('useDirectPaths') == "1"
|
||||
self.music_enabled = settings('enableMusic') == "true"
|
||||
self.contentmsg = settings('newContent') == "true"
|
||||
self.newvideo_time = int(settings('newvideotime'))*1000
|
||||
self.newmusic_time = int(settings('newmusictime'))*1000
|
||||
|
||||
self.artwork = artwork.Artwork()
|
||||
self.emby = embyserver.Read_EmbyServer()
|
||||
self.emby_db = embydb.Embydb_Functions(embycursor)
|
||||
self.kodi_db = kodidb.Kodidb_Functions(kodicursor)
|
||||
self.music_enabled = settings('enableMusic') == "true"
|
||||
|
||||
|
||||
def itemsbyId(self, items, process, pdialog=None):
|
||||
# Process items by itemid. Process can be added, update, userdata, remove
|
||||
emby = self.emby
|
||||
embycursor = self.embycursor
|
||||
kodicursor = self.kodicursor
|
||||
music_enabled = self.music_enabled
|
||||
|
||||
|
||||
itemtypes = {
|
||||
|
||||
'Movie': Movies,
|
||||
|
@ -80,11 +54,10 @@ class Items(object):
|
|||
if total == 0:
|
||||
return False
|
||||
|
||||
log.info("Processing %s: %s" % (process, items))
|
||||
log.info("Processing %s: %s", process, items)
|
||||
if pdialog:
|
||||
pdialog.update(heading="Processing %s: %s items" % (process, total))
|
||||
|
||||
count = 0
|
||||
for itemtype in items:
|
||||
|
||||
# Safety check
|
||||
|
@ -100,7 +73,7 @@ class Items(object):
|
|||
musicconn = None
|
||||
|
||||
if itemtype in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'):
|
||||
if music_enabled:
|
||||
if self.music_enabled:
|
||||
musicconn = kodiSQL('music')
|
||||
musiccursor = musicconn.cursor()
|
||||
items_process = itemtypes[itemtype](embycursor, musiccursor, pdialog)
|
||||
|
@ -113,19 +86,18 @@ class Items(object):
|
|||
|
||||
|
||||
if process == "added":
|
||||
processItems = itemlist
|
||||
items_process.add_all(itemtype, itemlist)
|
||||
elif process == "remove":
|
||||
items_process.remove_all(itemtype, itemlist)
|
||||
else:
|
||||
processItems = emby.getFullItems(itemlist)
|
||||
items_process.process_all(itemtype, process, processItems, total)
|
||||
process_items = self.emby.getFullItems(itemlist)
|
||||
items_process.process_all(itemtype, process, process_items, total)
|
||||
|
||||
|
||||
if musicconn is not None:
|
||||
# close connection for special types
|
||||
log.info("Updating music database.")
|
||||
log.info("updating music database")
|
||||
musicconn.commit()
|
||||
musiccursor.close()
|
||||
|
||||
return (True, update_videolibrary)
|
||||
return (True, update_videolibrary)
|
||||
|
|
|
@ -999,14 +999,11 @@ class ManualSync(LibrarySync):
|
|||
|
||||
|
||||
def __init__(self):
|
||||
|
||||
LibrarySync.__init__(self)
|
||||
|
||||
def sync(self):
|
||||
|
||||
return self.fullSync(manualrun=True)
|
||||
|
||||
|
||||
def movies(self, embycursor, kodicursor, pdialog):
|
||||
return Movies(embycursor, kodicursor, pdialog).compare_all()
|
||||
|
||||
|
|
|
@ -78,11 +78,11 @@ class Items(object):
|
|||
if self.pdialog and view:
|
||||
self.pdialog.update(heading="Processing %s / %s items" % (view['name'], total))
|
||||
|
||||
action = self._get_func(item_type, "added")
|
||||
process = self._get_func(item_type, "added")
|
||||
if view:
|
||||
action(items, total, view)
|
||||
process(items, total, view)
|
||||
else:
|
||||
action(items, total)
|
||||
process(items, total)
|
||||
|
||||
def process_all(self, item_type, action, items, total=None, view=None):
|
||||
|
||||
|
|
|
@ -4,12 +4,9 @@
|
|||
|
||||
import logging
|
||||
import urllib
|
||||
from ntpath import dirname
|
||||
from datetime import datetime
|
||||
|
||||
import api
|
||||
import common
|
||||
import downloadutils
|
||||
import embydb_functions as embydb
|
||||
import kodidb_functions as kodidb
|
||||
from utils import window, settings, language as lang, catch_except
|
||||
|
@ -20,12 +17,12 @@ log = logging.getLogger("EMBY."+__name__)
|
|||
|
||||
##################################################################################################
|
||||
|
||||
|
||||
|
||||
class Movies(common.Items):
|
||||
|
||||
|
||||
|
||||
def __init__(self, embycursor, kodicursor, pdialog=None):
|
||||
|
||||
|
||||
self.embycursor = embycursor
|
||||
self.emby_db = embydb.Embydb_Functions(self.embycursor)
|
||||
self.kodicursor = kodicursor
|
||||
|
@ -33,7 +30,7 @@ class Movies(common.Items):
|
|||
self.pdialog = pdialog
|
||||
|
||||
self.new_time = int(settings('newvideotime'))*1000
|
||||
|
||||
|
||||
common.Items.__init__(self)
|
||||
|
||||
def _get_func(self, item_type, action):
|
||||
|
@ -62,7 +59,7 @@ class Movies(common.Items):
|
|||
pdialog = self.pdialog
|
||||
views = self.emby_db.getView_byType('movies')
|
||||
views += self.emby_db.getView_byType('mixed')
|
||||
log.info("Media folders: %s" % views)
|
||||
log.info("Media folders: %s", views)
|
||||
|
||||
try:
|
||||
all_kodisets = dict(self.emby_db.get_checksum('BoxSet'))
|
||||
|
@ -107,7 +104,7 @@ class Movies(common.Items):
|
|||
# Only update if movie is not in Kodi or checksum is different
|
||||
updatelist.append(itemid)
|
||||
|
||||
log.info("Movies to update for %s: %s" % (viewName, updatelist))
|
||||
log.info("Movies to update for %s: %s", viewName, updatelist)
|
||||
embymovies = self.emby.getFullItems(updatelist)
|
||||
total = len(updatelist)
|
||||
del updatelist[:]
|
||||
|
@ -137,7 +134,7 @@ class Movies(common.Items):
|
|||
updatelist.append(itemid)
|
||||
embyboxsets.append(boxset)
|
||||
|
||||
log.info("Boxsets to update: %s" % updatelist)
|
||||
log.info("Boxsets to update: %s", updatelist)
|
||||
self.total = len(updatelist)
|
||||
|
||||
if pdialog:
|
||||
|
@ -158,14 +155,14 @@ class Movies(common.Items):
|
|||
for kodimovie in all_kodimovies:
|
||||
if kodimovie not in all_embymoviesIds:
|
||||
self.remove(kodimovie)
|
||||
else:
|
||||
log.info("Movies compare finished.")
|
||||
|
||||
log.info("Movies compare finished.")
|
||||
|
||||
for boxset in all_kodisets:
|
||||
if boxset not in all_embyboxsetsIds:
|
||||
self.remove(boxset)
|
||||
else:
|
||||
log.info("Boxsets compare finished.")
|
||||
|
||||
log.info("Boxsets compare finished.")
|
||||
|
||||
return True
|
||||
|
||||
|
@ -193,11 +190,11 @@ class Movies(common.Items):
|
|||
movieid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
pathid = emby_dbitem[2]
|
||||
log.info("movieid: %s fileid: %s pathid: %s" % (movieid, fileid, pathid))
|
||||
|
||||
log.info("movieid: %s fileid: %s pathid: %s", movieid, fileid, pathid)
|
||||
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("movieid: %s not found." % itemid)
|
||||
log.debug("movieid: %s not found", itemid)
|
||||
# movieid
|
||||
kodicursor.execute("select coalesce(max(idMovie),0) from movie")
|
||||
movieid = kodicursor.fetchone()[0] + 1
|
||||
|
@ -211,12 +208,12 @@ class Movies(common.Items):
|
|||
except TypeError:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("movieid: %s missing from Kodi, repairing the entry." % movieid)
|
||||
log.info("movieid: %s missing from Kodi, repairing the entry", movieid)
|
||||
|
||||
if not view:
|
||||
# Get view tag from emby
|
||||
viewtag, viewid, mediatype = self.emby.getView_embyId(itemid)
|
||||
log.debug("View tag found: %s" % viewtag)
|
||||
log.debug("View tag found: %s", viewtag)
|
||||
else:
|
||||
viewtag = view['name']
|
||||
viewid = view['id']
|
||||
|
@ -270,16 +267,16 @@ class Movies(common.Items):
|
|||
trailer = item['RemoteTrailers'][0]['Url']
|
||||
except (KeyError, IndexError):
|
||||
trailer = None
|
||||
else:
|
||||
else:
|
||||
try:
|
||||
trailerId = trailer.rsplit('=', 1)[1]
|
||||
trailer_id = trailer.rsplit('=', 1)[1]
|
||||
except IndexError:
|
||||
log.info("Failed to process trailer: %s" % trailer)
|
||||
log.info("Failed to process trailer: %s", trailer)
|
||||
trailer = None
|
||||
else:
|
||||
trailer = "plugin://plugin.video.youtube/play/?video_id=%s" % trailerId
|
||||
trailer = "plugin://plugin.video.youtube/play/?video_id=%s" % trailer_id
|
||||
|
||||
|
||||
|
||||
##### GET THE FILE AND PATH #####
|
||||
playurl = API.get_file_path()
|
||||
|
||||
|
@ -293,7 +290,7 @@ class Movies(common.Items):
|
|||
# Direct paths is set the Kodi way
|
||||
if not self.path_validation(playurl):
|
||||
return False
|
||||
|
||||
|
||||
path = playurl.replace(filename, "")
|
||||
window('emby_pathverified', value="true")
|
||||
else:
|
||||
|
@ -311,12 +308,12 @@ class Movies(common.Items):
|
|||
|
||||
##### UPDATE THE MOVIE #####
|
||||
if update_item:
|
||||
log.info("UPDATE movie itemid: %s - Title: %s" % (itemid, title))
|
||||
log.info("UPDATE movie itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Update the movie entry
|
||||
if self.kodi_version > 16:
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE movie",
|
||||
"SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?,",
|
||||
"c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?,",
|
||||
|
@ -324,11 +321,12 @@ class Movies(common.Items):
|
|||
"WHERE idMovie = ?"
|
||||
))
|
||||
kodicursor.execute(query, (title, plot, shortplot, tagline, votecount, rating,
|
||||
writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio,
|
||||
trailer, country, year, movieid))
|
||||
writer, year, imdb, sorttitle, runtime, mpaa, genre,
|
||||
director, title, studio, trailer, country, year,
|
||||
movieid))
|
||||
else:
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE movie",
|
||||
"SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?,",
|
||||
"c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?, c14 = ?, c15 = ?,",
|
||||
|
@ -336,51 +334,52 @@ class Movies(common.Items):
|
|||
"WHERE idMovie = ?"
|
||||
))
|
||||
kodicursor.execute(query, (title, plot, shortplot, tagline, votecount, rating,
|
||||
writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio,
|
||||
trailer, country, movieid))
|
||||
|
||||
writer, year, imdb, sorttitle, runtime, mpaa, genre,
|
||||
director, title, studio, trailer, country, movieid))
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
|
||||
##### OR ADD THE MOVIE #####
|
||||
else:
|
||||
log.info("ADD movie itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("ADD movie itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Add path
|
||||
pathid = self.kodi_db.addPath(path)
|
||||
# Add the file
|
||||
fileid = self.kodi_db.addFile(filename, pathid)
|
||||
|
||||
|
||||
# Create the movie entry
|
||||
if self.kodi_version > 16:
|
||||
query = (
|
||||
'''
|
||||
INSERT INTO movie(
|
||||
idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
|
||||
idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
|
||||
c09, c10, c11, c12, c14, c15, c16, c18, c19, c21, premiered)
|
||||
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (movieid, fileid, title, plot, shortplot, tagline,
|
||||
votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre,
|
||||
director, title, studio, trailer, country, year))
|
||||
votecount, rating, writer, year, imdb, sorttitle,
|
||||
runtime, mpaa, genre, director, title, studio, trailer,
|
||||
country, year))
|
||||
else:
|
||||
query = (
|
||||
'''
|
||||
INSERT INTO movie(
|
||||
idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
|
||||
idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
|
||||
c09, c10, c11, c12, c14, c15, c16, c18, c19, c21)
|
||||
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (movieid, fileid, title, plot, shortplot, tagline,
|
||||
votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre,
|
||||
director, title, studio, trailer, country))
|
||||
|
||||
votecount, rating, writer, year, imdb, sorttitle,
|
||||
runtime, mpaa, genre, director, title, studio, trailer,
|
||||
country))
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, movieid, "Movie", "movie", fileid, pathid, None, checksum, viewid)
|
||||
emby_db.addReference(itemid, movieid, "Movie", "movie", fileid, pathid, None,
|
||||
checksum, viewid)
|
||||
|
||||
# Update the path
|
||||
query = ' '.join((
|
||||
|
@ -399,7 +398,7 @@ class Movies(common.Items):
|
|||
"WHERE idFile = ?"
|
||||
))
|
||||
kodicursor.execute(query, (pathid, filename, dateadded, fileid))
|
||||
|
||||
|
||||
# Process countries
|
||||
if 'ProductionLocations' in item:
|
||||
self.kodi_db.addCountries(movieid, item['ProductionLocations'], "movie")
|
||||
|
@ -447,7 +446,7 @@ class Movies(common.Items):
|
|||
|
||||
# Process artwork
|
||||
artwork.add_artwork(artwork.get_all_artwork(boxset), setid, "set", self.kodicursor)
|
||||
|
||||
|
||||
# Process movies inside boxset
|
||||
current_movies = emby_db.getItemId_byParentId(setid, "movie")
|
||||
process = []
|
||||
|
@ -472,10 +471,10 @@ class Movies(common.Items):
|
|||
try:
|
||||
movieid = emby_dbitem[0]
|
||||
except TypeError:
|
||||
log.info("Failed to add: %s to boxset." % movie['Name'])
|
||||
log.info("Failed to add: %s to boxset", movie['Name'])
|
||||
continue
|
||||
|
||||
log.info("New addition to boxset %s: %s" % (title, movie['Name']))
|
||||
log.info("New addition to boxset %s: %s", title, movie['Name'])
|
||||
self.kodi_db.assignBoxset(setid, movieid)
|
||||
# Update emby reference
|
||||
emby_db.updateParentId(itemid, setid)
|
||||
|
@ -486,7 +485,7 @@ class Movies(common.Items):
|
|||
# Process removals from boxset
|
||||
for movie in process:
|
||||
movieid = current[movie]
|
||||
log.info("Remove from boxset %s: %s" % (title, movieid))
|
||||
log.info("Remove from boxset %s: %s", title, movieid)
|
||||
self.kodi_db.removefromBoxset(movieid)
|
||||
# Update emby reference
|
||||
emby_db.updateParentId(movie, None)
|
||||
|
@ -499,7 +498,7 @@ class Movies(common.Items):
|
|||
# Poster with progress bar
|
||||
emby_db = self.emby_db
|
||||
API = api.API(item)
|
||||
|
||||
|
||||
# Get emby information
|
||||
itemid = item['Id']
|
||||
checksum = API.get_checksum()
|
||||
|
@ -511,7 +510,7 @@ class Movies(common.Items):
|
|||
try:
|
||||
movieid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
log.info("Update playstate for movie: %s fileid: %s" % (item['Name'], fileid))
|
||||
log.info("Update playstate for movie: %s fileid: %s", item['Name'], fileid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -527,7 +526,7 @@ class Movies(common.Items):
|
|||
resume = API.adjust_resume(userdata['Resume'])
|
||||
total = round(float(runtime), 6)
|
||||
|
||||
log.debug("%s New resume point: %s" % (itemid, resume))
|
||||
log.debug("%s New resume point: %s", itemid, resume)
|
||||
|
||||
self.kodi_db.addPlaystate(fileid, resume, total, playcount, dateplayed)
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
@ -543,7 +542,7 @@ class Movies(common.Items):
|
|||
kodiid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
mediatype = emby_dbitem[4]
|
||||
log.info("Removing %sid: %s fileid: %s" % (mediatype, kodiid, fileid))
|
||||
log.info("Removing %sid: %s fileid: %s", mediatype, kodiid, fileid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -569,4 +568,4 @@ class Movies(common.Items):
|
|||
|
||||
kodicursor.execute("DELETE FROM sets WHERE idSet = ?", (kodiid,))
|
||||
|
||||
log.info("Deleted %s %s from kodi database" % (mediatype, itemid))
|
||||
log.info("Deleted %s %s from kodi database", mediatype, itemid)
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
##################################################################################################
|
||||
|
||||
import logging
|
||||
import urllib
|
||||
from ntpath import dirname
|
||||
from datetime import datetime
|
||||
|
||||
import api
|
||||
import common
|
||||
import downloadutils
|
||||
import embydb_functions as embydb
|
||||
import kodidb_functions as kodidb
|
||||
import musicutils
|
||||
|
@ -21,12 +18,12 @@ log = logging.getLogger("EMBY."+__name__)
|
|||
|
||||
##################################################################################################
|
||||
|
||||
|
||||
|
||||
class Music(common.Items):
|
||||
|
||||
|
||||
|
||||
def __init__(self, embycursor, kodicursor, pdialog=None):
|
||||
|
||||
|
||||
self.embycursor = embycursor
|
||||
self.emby_db = embydb.Embydb_Functions(self.embycursor)
|
||||
self.kodicursor = kodicursor
|
||||
|
@ -40,7 +37,7 @@ class Music(common.Items):
|
|||
self.enableupdatesongrating = settings('enableUpdateSongRating') == "true"
|
||||
self.userid = window('emby_currUser')
|
||||
self.server = window('emby_server%s' % self.userid)
|
||||
|
||||
|
||||
common.Items.__init__(self)
|
||||
|
||||
def _get_func(self, item_type, action):
|
||||
|
@ -133,7 +130,7 @@ class Music(common.Items):
|
|||
if all_kodisongs.get(itemid) != API.get_checksum():
|
||||
# Only update if songs is not in Kodi or checksum is different
|
||||
updatelist.append(itemid)
|
||||
log.info("%s to update: %s" % (data_type, updatelist))
|
||||
log.info("%s to update: %s", data_type, updatelist)
|
||||
embyitems = self.emby.getFullItems(updatelist)
|
||||
self.total = len(updatelist)
|
||||
del updatelist[:]
|
||||
|
@ -152,18 +149,20 @@ class Music(common.Items):
|
|||
for kodiartist in all_kodiartists:
|
||||
if kodiartist not in all_embyartistsIds and all_kodiartists[kodiartist] is not None:
|
||||
self.remove(kodiartist)
|
||||
else:
|
||||
log.info("Artist compare finished.")
|
||||
|
||||
log.info("Artist compare finished.")
|
||||
|
||||
for kodialbum in all_kodialbums:
|
||||
if kodialbum not in all_embyalbumsIds:
|
||||
self.remove(kodialbum)
|
||||
else:
|
||||
log.info("Albums compare finished.")
|
||||
|
||||
log.info("Albums compare finished.")
|
||||
|
||||
for kodisong in all_kodisongs:
|
||||
if kodisong not in all_embysongsIds:
|
||||
self.remove(kodisong)
|
||||
else:
|
||||
log.info("Songs compare finished.")
|
||||
|
||||
log.info("Songs compare finished.")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -176,7 +175,7 @@ class Music(common.Items):
|
|||
self.added_album(all_albums['Items'])
|
||||
|
||||
def added_album(self, items, total=None):
|
||||
|
||||
|
||||
update = True if not self.total else False
|
||||
|
||||
for item in super(Music, self).added(items, total, update):
|
||||
|
@ -188,7 +187,7 @@ class Music(common.Items):
|
|||
self.added_song(all_songs['Items'])
|
||||
|
||||
def added_song(self, items, total=None):
|
||||
|
||||
|
||||
update = True if not self.total else False
|
||||
|
||||
for item in super(Music, self).added(items, total, update):
|
||||
|
@ -212,7 +211,7 @@ class Music(common.Items):
|
|||
artistid = emby_dbitem[0]
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("artistid: %s not found." % itemid)
|
||||
log.debug("artistid: %s not found", itemid)
|
||||
|
||||
##### The artist details #####
|
||||
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
@ -239,19 +238,18 @@ class Music(common.Items):
|
|||
|
||||
##### UPDATE THE ARTIST #####
|
||||
if update_item:
|
||||
log.info("UPDATE artist itemid: %s - Name: %s" % (itemid, name))
|
||||
log.info("UPDATE artist itemid: %s - Name: %s", itemid, name)
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
##### OR ADD THE ARTIST #####
|
||||
else:
|
||||
log.info("ADD artist itemid: %s - Name: %s" % (itemid, name))
|
||||
log.info("ADD artist itemid: %s - Name: %s", itemid, name)
|
||||
# safety checks: It looks like Emby supports the same artist multiple times.
|
||||
# Kodi doesn't allow that. In case that happens we just merge the artist entries.
|
||||
artistid = self.kodi_db.addArtist(name, musicBrainzId)
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, artistid, artisttype, "artist", checksum=checksum)
|
||||
|
||||
|
||||
# Process the artist
|
||||
if self.kodi_version in (16, 17):
|
||||
|
@ -272,8 +270,7 @@ class Music(common.Items):
|
|||
"WHERE idArtist = ?"
|
||||
))
|
||||
kodicursor.execute(query, (genres, bio, thumb, fanart, lastScraped,
|
||||
dateadded, artistid))
|
||||
|
||||
dateadded, artistid))
|
||||
|
||||
# Update artwork
|
||||
artwork.add_artwork(artworks, artistid, "artist", kodicursor)
|
||||
|
@ -296,7 +293,7 @@ class Music(common.Items):
|
|||
albumid = emby_dbitem[0]
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("albumid: %s not found." % itemid)
|
||||
log.debug("albumid: %s not found", itemid)
|
||||
|
||||
##### The album details #####
|
||||
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
@ -325,13 +322,13 @@ class Music(common.Items):
|
|||
|
||||
##### UPDATE THE ALBUM #####
|
||||
if update_item:
|
||||
log.info("UPDATE album itemid: %s - Name: %s" % (itemid, name))
|
||||
log.info("UPDATE album itemid: %s - Name: %s", itemid, name)
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
##### OR ADD THE ALBUM #####
|
||||
else:
|
||||
log.info("ADD album itemid: %s - Name: %s" % (itemid, name))
|
||||
log.info("ADD album itemid: %s - Name: %s", itemid, name)
|
||||
# safety checks: It looks like Emby supports the same artist multiple times.
|
||||
# Kodi doesn't allow that. In case that happens we just merge the artist entries.
|
||||
albumid = self.kodi_db.addAlbum(name, musicBrainzId)
|
||||
|
@ -350,7 +347,7 @@ class Music(common.Items):
|
|||
"WHERE idAlbum = ?"
|
||||
))
|
||||
kodicursor.execute(query, (artistname, year, genre, bio, thumb, rating, lastScraped,
|
||||
"album", albumid))
|
||||
"album", albumid))
|
||||
elif self.kodi_version == 16:
|
||||
# Kodi Jarvis
|
||||
query = ' '.join((
|
||||
|
@ -361,7 +358,7 @@ class Music(common.Items):
|
|||
"WHERE idAlbum = ?"
|
||||
))
|
||||
kodicursor.execute(query, (artistname, year, genre, bio, thumb, rating, lastScraped,
|
||||
"album", albumid))
|
||||
"album", albumid))
|
||||
elif self.kodi_version == 15:
|
||||
# Kodi Isengard
|
||||
query = ' '.join((
|
||||
|
@ -372,7 +369,7 @@ class Music(common.Items):
|
|||
"WHERE idAlbum = ?"
|
||||
))
|
||||
kodicursor.execute(query, (artistname, year, genre, bio, thumb, rating, lastScraped,
|
||||
dateadded, "album", albumid))
|
||||
dateadded, "album", albumid))
|
||||
else:
|
||||
# Kodi Helix
|
||||
query = ' '.join((
|
||||
|
@ -383,7 +380,7 @@ class Music(common.Items):
|
|||
"WHERE idAlbum = ?"
|
||||
))
|
||||
kodicursor.execute(query, (artistname, year, genre, bio, thumb, rating, lastScraped,
|
||||
dateadded, albumid))
|
||||
dateadded, albumid))
|
||||
|
||||
# Assign main artists to album
|
||||
for artist in item['AlbumArtists']:
|
||||
|
@ -458,8 +455,8 @@ class Music(common.Items):
|
|||
albumid = emby_dbitem[3]
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("songid: %s not found." % itemid)
|
||||
|
||||
log.debug("songid: %s not found", itemid)
|
||||
|
||||
##### The song details #####
|
||||
checksum = API.get_checksum()
|
||||
dateadded = API.get_date_created()
|
||||
|
@ -489,8 +486,8 @@ class Music(common.Items):
|
|||
else:
|
||||
hasEmbeddedCover = False
|
||||
comment = API.get_overview()
|
||||
|
||||
|
||||
|
||||
|
||||
##### GET THE FILE AND PATH #####
|
||||
if self.directstream:
|
||||
path = "%s/emby/Audio/%s/" % (self.server, itemid)
|
||||
|
@ -512,21 +509,21 @@ class Music(common.Items):
|
|||
# Direct paths is set the Kodi way
|
||||
if not self.path_validation(playurl):
|
||||
return False
|
||||
|
||||
|
||||
path = playurl.replace(filename, "")
|
||||
window('emby_pathverified', value="true")
|
||||
|
||||
##### UPDATE THE SONG #####
|
||||
if update_item:
|
||||
log.info("UPDATE song itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("UPDATE song itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Update path
|
||||
query = "UPDATE path SET strPath = ? WHERE idPath = ?"
|
||||
kodicursor.execute(query, (path, pathid))
|
||||
|
||||
# Update the song entry
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE song",
|
||||
"SET idAlbum = ?, strArtists = ?, strGenres = ?, strTitle = ?, iTrack = ?,",
|
||||
"iDuration = ?, iYear = ?, strFilename = ?, iTimesPlayed = ?, lastplayed = ?,",
|
||||
|
@ -534,15 +531,15 @@ class Music(common.Items):
|
|||
"WHERE idSong = ?"
|
||||
))
|
||||
kodicursor.execute(query, (albumid, artists, genre, title, track, duration, year,
|
||||
filename, playcount, dateplayed, rating, comment, songid))
|
||||
filename, playcount, dateplayed, rating, comment, songid))
|
||||
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
|
||||
##### OR ADD THE SONG #####
|
||||
else:
|
||||
log.info("ADD song itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("ADD song itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Add path
|
||||
pathid = self.kodi_db.addPath(path)
|
||||
|
||||
|
@ -554,12 +551,12 @@ class Music(common.Items):
|
|||
# Verify if there's an album associated.
|
||||
album_name = item.get('Album')
|
||||
if album_name:
|
||||
log.info("Creating virtual music album for song: %s." % itemid)
|
||||
log.info("Creating virtual music album for song: %s", itemid)
|
||||
albumid = self.kodi_db.addAlbum(album_name, API.get_provider('MusicBrainzAlbum'))
|
||||
emby_db.addReference("%salbum%s" % (itemid, albumid), albumid, "MusicAlbum_", "album")
|
||||
else:
|
||||
# No album Id associated to the song.
|
||||
log.error("Song itemid: %s has no albumId associated." % itemid)
|
||||
log.error("Song itemid: %s has no albumId associated", itemid)
|
||||
return False
|
||||
|
||||
except TypeError:
|
||||
|
@ -571,7 +568,7 @@ class Music(common.Items):
|
|||
emby_dbalbum = emby_db.getItem_byId(emby_albumId)
|
||||
try:
|
||||
albumid = emby_dbalbum[0]
|
||||
log.info("Found albumid: %s" % albumid)
|
||||
log.info("Found albumid: %s", albumid)
|
||||
except TypeError:
|
||||
# No album found, create a single's album
|
||||
log.info("Failed to add album. Creating singles.")
|
||||
|
@ -607,7 +604,7 @@ class Music(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (albumid, genre, year, dateadded))
|
||||
|
||||
|
||||
# Create the song entry
|
||||
kodicursor.execute("select coalesce(max(idSong),0) from song")
|
||||
songid = kodicursor.fetchone()[0] + 1
|
||||
|
@ -622,24 +619,24 @@ class Music(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (songid, albumid, pathid, artists, genre, title, track,
|
||||
duration, year, filename, musicBrainzId, playcount, dateplayed, rating))
|
||||
duration, year, filename, musicBrainzId, playcount,
|
||||
dateplayed, rating))
|
||||
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, songid, "Audio", "song", pathid=pathid, parentid=albumid,
|
||||
checksum=checksum)
|
||||
checksum=checksum)
|
||||
|
||||
|
||||
# Link song to album
|
||||
query = (
|
||||
'''
|
||||
INSERT OR REPLACE INTO albuminfosong(
|
||||
idAlbumInfoSong, idAlbumInfo, iTrack, strTitle, iDuration)
|
||||
|
||||
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (songid, albumid, track, title, duration))
|
||||
|
||||
|
||||
# Link song to artists
|
||||
for index, artist in enumerate(item['ArtistItems']):
|
||||
|
||||
|
@ -660,31 +657,31 @@ class Music(common.Items):
|
|||
query = (
|
||||
'''
|
||||
INSERT OR REPLACE INTO song_artist(idArtist, idSong, idRole, iOrder, strArtist)
|
||||
|
||||
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (artistid, songid, 1, index, artist_name))
|
||||
|
||||
|
||||
# May want to look into only doing this once?
|
||||
query = (
|
||||
query = (
|
||||
'''
|
||||
INSERT OR REPLACE INTO role(idRole, strRole)
|
||||
|
||||
|
||||
VALUES (?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (1, 'Composer'))
|
||||
kodicursor.execute(query, (1, 'Composer'))
|
||||
else:
|
||||
query = (
|
||||
'''
|
||||
INSERT OR REPLACE INTO song_artist(idArtist, idSong, iOrder, strArtist)
|
||||
|
||||
|
||||
VALUES (?, ?, ?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (artistid, songid, index, artist_name))
|
||||
|
||||
|
||||
# Verify if album artist exists
|
||||
album_artists = []
|
||||
for artist in item['AlbumArtists']:
|
||||
|
@ -720,38 +717,38 @@ class Music(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (artistid, item['Album'], 0))
|
||||
else:
|
||||
album_artists = " / ".join(album_artists)
|
||||
query = ' '.join((
|
||||
|
||||
"SELECT strArtists",
|
||||
"FROM album",
|
||||
"WHERE idAlbum = ?"
|
||||
))
|
||||
kodicursor.execute(query, (albumid,))
|
||||
result = kodicursor.fetchone()
|
||||
if result and result[0] != album_artists:
|
||||
# Field is empty
|
||||
if self.kodi_version in (16, 17):
|
||||
# Kodi Jarvis, Krypton
|
||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (album_artists, albumid))
|
||||
elif self.kodi_version == 15:
|
||||
# Kodi Isengard
|
||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (album_artists, albumid))
|
||||
else:
|
||||
# Kodi Helix
|
||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (album_artists, albumid))
|
||||
album_artists = " / ".join(album_artists)
|
||||
query = ' '.join((
|
||||
|
||||
"SELECT strArtists",
|
||||
"FROM album",
|
||||
"WHERE idAlbum = ?"
|
||||
))
|
||||
kodicursor.execute(query, (albumid,))
|
||||
result = kodicursor.fetchone()
|
||||
if result and result[0] != album_artists:
|
||||
# Field is empty
|
||||
if self.kodi_version in (16, 17):
|
||||
# Kodi Jarvis, Krypton
|
||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (album_artists, albumid))
|
||||
elif self.kodi_version == 15:
|
||||
# Kodi Isengard
|
||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (album_artists, albumid))
|
||||
else:
|
||||
# Kodi Helix
|
||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (album_artists, albumid))
|
||||
|
||||
# Add genres
|
||||
self.kodi_db.addMusicGenres(songid, genres, "song")
|
||||
|
||||
|
||||
# Update artwork
|
||||
allart = artwork.get_all_artwork(item, parent_info=True)
|
||||
if hasEmbeddedCover:
|
||||
allart["Primary"] = "image://music@" + artwork.single_urlencode( playurl )
|
||||
allart["Primary"] = "image://music@" + artwork.single_urlencode(playurl)
|
||||
artwork.add_artwork(allart, songid, "song", kodicursor)
|
||||
|
||||
if item.get('AlbumId') is None:
|
||||
|
@ -771,7 +768,6 @@ class Music(common.Items):
|
|||
itemid = item['Id']
|
||||
checksum = API.get_checksum()
|
||||
userdata = API.get_userdata()
|
||||
runtime = API.get_runtime()
|
||||
rating = userdata['UserRating']
|
||||
|
||||
# Get Kodi information
|
||||
|
@ -779,25 +775,25 @@ class Music(common.Items):
|
|||
try:
|
||||
kodiid = emby_dbitem[0]
|
||||
mediatype = emby_dbitem[4]
|
||||
log.info("Update playstate for %s: %s" % (mediatype, item['Name']))
|
||||
log.info("Update playstate for %s: %s", mediatype, item['Name'])
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
if mediatype == "song":
|
||||
|
||||
|
||||
#should we ignore this item ?
|
||||
#happens when userdata updated by ratings method
|
||||
if window("ignore-update-%s" %itemid):
|
||||
window("ignore-update-%s" %itemid,clear=True)
|
||||
return
|
||||
|
||||
|
||||
# Process playstates
|
||||
playcount = userdata['PlayCount']
|
||||
dateplayed = userdata['LastPlayedDate']
|
||||
|
||||
|
||||
#process item ratings
|
||||
rating, comment, hasEmbeddedCover = musicutils.getAdditionalSongTags(itemid, rating, API, kodicursor, emby_db, self.enableimportsongrating, self.enableexportsongrating, self.enableupdatesongrating)
|
||||
|
||||
|
||||
query = "UPDATE song SET iTimesPlayed = ?, lastplayed = ?, rating = ? WHERE idSong = ?"
|
||||
kodicursor.execute(query, (playcount, dateplayed, rating, kodiid))
|
||||
|
||||
|
@ -806,7 +802,7 @@ class Music(common.Items):
|
|||
if self.kodi_version >= 17:
|
||||
query = "UPDATE album SET fRating = ? WHERE idAlbum = ?"
|
||||
else:
|
||||
query = "UPDATE album SET iRating = ? WHERE idAlbum = ?"
|
||||
query = "UPDATE album SET iRating = ? WHERE idAlbum = ?"
|
||||
kodicursor.execute(query, (rating, kodiid))
|
||||
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
@ -814,14 +810,12 @@ class Music(common.Items):
|
|||
def remove(self, itemid):
|
||||
# Remove kodiid, fileid, pathid, emby reference
|
||||
emby_db = self.emby_db
|
||||
kodicursor = self.kodicursor
|
||||
artwork = self.artwork
|
||||
|
||||
emby_dbitem = emby_db.getItem_byId(itemid)
|
||||
try:
|
||||
kodiid = emby_dbitem[0]
|
||||
mediatype = emby_dbitem[4]
|
||||
log.info("Removing %s kodiid: %s" % (mediatype, kodiid))
|
||||
log.info("Removing %s kodiid: %s", mediatype, kodiid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -837,7 +831,7 @@ class Music(common.Items):
|
|||
# Delete song
|
||||
self.removeSong(kodiid)
|
||||
# This should only address single song scenario, where server doesn't actually
|
||||
# create an album for the song.
|
||||
# create an album for the song.
|
||||
emby_db.removeWildItem(itemid)
|
||||
|
||||
for item in emby_db.getItem_byWildId(itemid):
|
||||
|
|
|
@ -4,15 +4,12 @@
|
|||
|
||||
import logging
|
||||
import urllib
|
||||
from ntpath import dirname
|
||||
from datetime import datetime
|
||||
|
||||
import api
|
||||
import common
|
||||
import downloadutils
|
||||
import embydb_functions as embydb
|
||||
import kodidb_functions as kodidb
|
||||
from utils import window, settings, language as lang, catch_except
|
||||
from utils import window, language as lang, catch_except
|
||||
|
||||
##################################################################################################
|
||||
|
||||
|
@ -23,15 +20,15 @@ log = logging.getLogger("EMBY."+__name__)
|
|||
|
||||
class MusicVideos(common.Items):
|
||||
|
||||
|
||||
|
||||
def __init__(self, embycursor, kodicursor, pdialog=None):
|
||||
|
||||
|
||||
self.embycursor = embycursor
|
||||
self.emby_db = embydb.Embydb_Functions(self.embycursor)
|
||||
self.kodicursor = kodicursor
|
||||
self.kodi_db = kodidb.Kodidb_Functions(self.kodicursor)
|
||||
self.pdialog = pdialog
|
||||
|
||||
|
||||
common.Items.__init__(self)
|
||||
|
||||
def _get_func(self, item_type, action):
|
||||
|
@ -53,7 +50,7 @@ class MusicVideos(common.Items):
|
|||
pdialog = self.pdialog
|
||||
# Pull the list of musicvideos in Kodi
|
||||
views = self.emby_db.getView_byType('musicvideos')
|
||||
log.info("Media folders: %s" % views)
|
||||
log.info("Media folders: %s", views)
|
||||
|
||||
try:
|
||||
all_kodimvideos = dict(self.emby_db.get_checksum('MusicVideo'))
|
||||
|
@ -92,7 +89,7 @@ class MusicVideos(common.Items):
|
|||
# Only update if musicvideo is not in Kodi or checksum is different
|
||||
updatelist.append(itemid)
|
||||
|
||||
log.info("MusicVideos to update for %s: %s" % (viewName, updatelist))
|
||||
log.info("MusicVideos to update for %s: %s", viewName, updatelist)
|
||||
embymvideos = self.emby.getFullItems(updatelist)
|
||||
self.total = len(updatelist)
|
||||
del updatelist[:]
|
||||
|
@ -116,9 +113,8 @@ class MusicVideos(common.Items):
|
|||
for kodimvideo in all_kodimvideos:
|
||||
if kodimvideo not in all_embymvideosIds:
|
||||
self.remove(kodimvideo)
|
||||
else:
|
||||
log.info("MusicVideos compare finished.")
|
||||
|
||||
log.info("MusicVideos compare finished.")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -144,11 +140,11 @@ class MusicVideos(common.Items):
|
|||
mvideoid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
pathid = emby_dbitem[2]
|
||||
log.info("mvideoid: %s fileid: %s pathid: %s" % (mvideoid, fileid, pathid))
|
||||
|
||||
log.info("mvideoid: %s fileid: %s pathid: %s", mvideoid, fileid, pathid)
|
||||
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("mvideoid: %s not found." % itemid)
|
||||
log.debug("mvideoid: %s not found", itemid)
|
||||
# mvideoid
|
||||
kodicursor.execute("select coalesce(max(idMVideo),0) from musicvideo")
|
||||
mvideoid = kodicursor.fetchone()[0] + 1
|
||||
|
@ -162,12 +158,12 @@ class MusicVideos(common.Items):
|
|||
except TypeError:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("mvideoid: %s missing from Kodi, repairing the entry." % mvideoid)
|
||||
log.info("mvideoid: %s missing from Kodi, repairing the entry.", mvideoid)
|
||||
|
||||
if not view:
|
||||
# Get view tag from emby
|
||||
viewtag, viewid, mediatype = self.emby.getView_embyId(itemid)
|
||||
log.debug("View tag found: %s" % viewtag)
|
||||
log.debug("View tag found: %s", viewtag)
|
||||
else:
|
||||
viewtag = view['name']
|
||||
viewid = view['id']
|
||||
|
@ -194,7 +190,7 @@ class MusicVideos(common.Items):
|
|||
people = API.get_people()
|
||||
director = " / ".join(people['Director'])
|
||||
|
||||
|
||||
|
||||
##### GET THE FILE AND PATH #####
|
||||
playurl = API.get_file_path()
|
||||
|
||||
|
@ -208,7 +204,7 @@ class MusicVideos(common.Items):
|
|||
# Direct paths is set the Kodi way
|
||||
if not self.path_validation(playurl):
|
||||
return False
|
||||
|
||||
|
||||
path = playurl.replace(filename, "")
|
||||
window('emby_pathverified', value="true")
|
||||
else:
|
||||
|
@ -226,8 +222,8 @@ class MusicVideos(common.Items):
|
|||
|
||||
##### UPDATE THE MUSIC VIDEO #####
|
||||
if update_item:
|
||||
log.info("UPDATE mvideo itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("UPDATE mvideo itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Update path
|
||||
query = "UPDATE path SET strPath = ? WHERE idPath = ?"
|
||||
kodicursor.execute(query, (path, pathid))
|
||||
|
@ -238,22 +234,21 @@ class MusicVideos(common.Items):
|
|||
|
||||
# Update the music video entry
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE musicvideo",
|
||||
"SET c00 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c08 = ?, c09 = ?, c10 = ?,",
|
||||
"c11 = ?, c12 = ?"
|
||||
"WHERE idMVideo = ?"
|
||||
))
|
||||
kodicursor.execute(query, (title, runtime, director, studio, year, plot, album,
|
||||
artist, genre, track, mvideoid))
|
||||
|
||||
artist, genre, track, mvideoid))
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
|
||||
##### OR ADD THE MUSIC VIDEO #####
|
||||
else:
|
||||
log.info("ADD mvideo itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("ADD mvideo itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Add path
|
||||
query = ' '.join((
|
||||
|
||||
|
@ -289,7 +284,7 @@ class MusicVideos(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (fileid, pathid, filename, dateadded))
|
||||
|
||||
|
||||
# Create the musicvideo entry
|
||||
query = (
|
||||
'''
|
||||
|
@ -300,13 +295,12 @@ class MusicVideos(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (mvideoid, fileid, title, runtime, director, studio,
|
||||
year, plot, album, artist, genre, track))
|
||||
year, plot, album, artist, genre, track))
|
||||
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, mvideoid, "MusicVideo", "musicvideo", fileid, pathid,
|
||||
checksum=checksum, mediafolderid=viewid)
|
||||
checksum=checksum, mediafolderid=viewid)
|
||||
|
||||
|
||||
# Process cast
|
||||
people = item['People']
|
||||
artists = item['ArtistItems']
|
||||
|
@ -342,7 +336,7 @@ class MusicVideos(common.Items):
|
|||
# Poster with progress bar
|
||||
emby_db = self.emby_db
|
||||
API = api.API(item)
|
||||
|
||||
|
||||
# Get emby information
|
||||
itemid = item['Id']
|
||||
checksum = API.get_checksum()
|
||||
|
@ -354,9 +348,7 @@ class MusicVideos(common.Items):
|
|||
try:
|
||||
mvideoid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
log.info(
|
||||
"Update playstate for musicvideo: %s fileid: %s"
|
||||
% (item['Name'], fileid))
|
||||
log.info("Update playstate for musicvideo: %s fileid: %s", item['Name'], fileid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -386,7 +378,7 @@ class MusicVideos(common.Items):
|
|||
mvideoid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
pathid = emby_dbitem[2]
|
||||
log.info("Removing mvideoid: %s fileid: %s" % (mvideoid, fileid, pathid))
|
||||
log.info("Removing mvideoid: %s fileid: %s pathid: %s", mvideoid, fileid, pathid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -400,7 +392,7 @@ class MusicVideos(common.Items):
|
|||
))
|
||||
kodicursor.execute(query, (mvideoid,))
|
||||
for row in kodicursor.fetchall():
|
||||
|
||||
|
||||
url = row[0]
|
||||
imagetype = row[1]
|
||||
if imagetype in ("poster", "fanart"):
|
||||
|
@ -412,4 +404,4 @@ class MusicVideos(common.Items):
|
|||
kodicursor.execute("DELETE FROM path WHERE idPath = ?", (pathid,))
|
||||
self.embycursor.execute("DELETE FROM emby WHERE emby_id = ?", (itemid,))
|
||||
|
||||
log.info("Deleted musicvideo %s from kodi database" % itemid)
|
||||
log.info("Deleted musicvideo %s from kodi database", itemid)
|
||||
|
|
|
@ -5,11 +5,9 @@
|
|||
import logging
|
||||
import urllib
|
||||
from ntpath import dirname
|
||||
from datetime import datetime
|
||||
|
||||
import api
|
||||
import common
|
||||
import downloadutils
|
||||
import embydb_functions as embydb
|
||||
import kodidb_functions as kodidb
|
||||
from utils import window, settings, language as lang, catch_except
|
||||
|
@ -20,12 +18,12 @@ log = logging.getLogger("EMBY."+__name__)
|
|||
|
||||
##################################################################################################
|
||||
|
||||
|
||||
|
||||
class TVShows(common.Items):
|
||||
|
||||
|
||||
|
||||
def __init__(self, embycursor, kodicursor, pdialog=None):
|
||||
|
||||
|
||||
self.embycursor = embycursor
|
||||
self.emby_db = embydb.Embydb_Functions(self.embycursor)
|
||||
self.kodicursor = kodicursor
|
||||
|
@ -33,7 +31,7 @@ class TVShows(common.Items):
|
|||
self.pdialog = pdialog
|
||||
|
||||
self.new_time = int(settings('newvideotime'))*1000
|
||||
|
||||
|
||||
common.Items.__init__(self)
|
||||
|
||||
def _get_func(self, item_type, action):
|
||||
|
@ -69,7 +67,7 @@ class TVShows(common.Items):
|
|||
pdialog = self.pdialog
|
||||
views = self.emby_db.getView_byType('tvshows')
|
||||
views += self.emby_db.getView_byType('mixed')
|
||||
log.info("Media folders: %s" % views)
|
||||
log.info("Media folders: %s", views)
|
||||
|
||||
# Pull the list of tvshows and episodes in Kodi
|
||||
try:
|
||||
|
@ -118,7 +116,7 @@ class TVShows(common.Items):
|
|||
# Only update if movie is not in Kodi or checksum is different
|
||||
updatelist.append(itemid)
|
||||
|
||||
log.info("TVShows to update for %s: %s" % (viewName, updatelist))
|
||||
log.info("TVShows to update for %s: %s", viewName, updatelist)
|
||||
embytvshows = self.emby.getFullItems(updatelist)
|
||||
self.total = len(updatelist)
|
||||
del updatelist[:]
|
||||
|
@ -137,7 +135,7 @@ class TVShows(common.Items):
|
|||
title = embytvshow['Name']
|
||||
all_embytvshowsIds.add(itemid)
|
||||
self.update_pdialog()
|
||||
|
||||
|
||||
self.add_update(embytvshow, view)
|
||||
self.count += 1
|
||||
|
||||
|
@ -164,7 +162,7 @@ class TVShows(common.Items):
|
|||
# Only update if movie is not in Kodi or checksum is different
|
||||
updatelist.append(itemid)
|
||||
|
||||
log.info("Episodes to update for %s: %s" % (viewName, updatelist))
|
||||
log.info("Episodes to update for %s: %s", viewName, updatelist)
|
||||
embyepisodes = self.emby.getFullItems(updatelist)
|
||||
self.total = len(updatelist)
|
||||
del updatelist[:]
|
||||
|
@ -181,19 +179,19 @@ class TVShows(common.Items):
|
|||
|
||||
##### PROCESS DELETES #####
|
||||
|
||||
log.info("all_embytvshowsIds = %s " % all_embytvshowsIds)
|
||||
log.info("all_embytvshowsIds = %s ", all_embytvshowsIds)
|
||||
|
||||
for koditvshow in all_koditvshows:
|
||||
if koditvshow not in all_embytvshowsIds:
|
||||
self.remove(koditvshow)
|
||||
else:
|
||||
log.info("TVShows compare finished.")
|
||||
|
||||
log.info("TVShows compare finished.")
|
||||
|
||||
for kodiepisode in all_kodiepisodes:
|
||||
if kodiepisode not in all_embyepisodesIds:
|
||||
self.remove(kodiepisode)
|
||||
else:
|
||||
log.info("Episodes compare finished.")
|
||||
|
||||
log.info("Episodes compare finished.")
|
||||
|
||||
return True
|
||||
|
||||
|
@ -207,7 +205,7 @@ class TVShows(common.Items):
|
|||
self.added_episode(all_episodes['Items'])
|
||||
|
||||
def added_season(self, items, total=None, view=None):
|
||||
|
||||
|
||||
update = True if not self.total else False
|
||||
|
||||
for item in super(TVShows, self).added(items, total, update):
|
||||
|
@ -238,7 +236,7 @@ class TVShows(common.Items):
|
|||
API = api.API(item)
|
||||
|
||||
if settings('syncEmptyShows') == "false" and not item.get('RecursiveItemCount'):
|
||||
log.info("Skipping empty show: %s" % item['Name'])
|
||||
log.info("Skipping empty show: %s", item['Name'])
|
||||
return
|
||||
# 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
|
||||
|
@ -249,11 +247,11 @@ class TVShows(common.Items):
|
|||
try:
|
||||
showid = emby_dbitem[0]
|
||||
pathid = emby_dbitem[2]
|
||||
log.info("showid: %s pathid: %s" % (showid, pathid))
|
||||
|
||||
log.info("showid: %s pathid: %s", showid, pathid)
|
||||
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("showid: %s not found." % itemid)
|
||||
log.debug("showid: %s not found", itemid)
|
||||
kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
|
||||
showid = kodicursor.fetchone()[0] + 1
|
||||
|
||||
|
@ -266,7 +264,7 @@ class TVShows(common.Items):
|
|||
except TypeError:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("showid: %s missing from Kodi, repairing the entry." % showid)
|
||||
log.info("showid: %s missing from Kodi, repairing the entry", showid)
|
||||
# Force re-add episodes after the show is re-created.
|
||||
force_episodes = True
|
||||
|
||||
|
@ -274,17 +272,14 @@ class TVShows(common.Items):
|
|||
if view is None:
|
||||
# Get view tag from emby
|
||||
viewtag, viewid, mediatype = emby.getView_embyId(itemid)
|
||||
log.debug("View tag found: %s" % viewtag)
|
||||
log.debug("View tag found: %s", viewtag)
|
||||
else:
|
||||
viewtag = view['name']
|
||||
viewid = view['id']
|
||||
|
||||
# fileId information
|
||||
checksum = API.get_checksum()
|
||||
dateadded = API.get_date_created()
|
||||
userdata = API.get_userdata()
|
||||
playcount = userdata['PlayCount']
|
||||
dateplayed = userdata['LastPlayedDate']
|
||||
|
||||
# item details
|
||||
genres = item['Genres']
|
||||
|
@ -314,13 +309,13 @@ class TVShows(common.Items):
|
|||
emby_other_item = emby_db.getItem_byId(emby_other[0])
|
||||
showid = emby_other_item[0]
|
||||
pathid = emby_other_item[2]
|
||||
log.info("showid: %s pathid: %s" % (showid, pathid))
|
||||
log.info("showid: %s pathid: %s", showid, pathid)
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, showid, "Series", "tvshow", pathid=pathid,
|
||||
checksum=checksum, mediafolderid=viewid)
|
||||
checksum=checksum, mediafolderid=viewid)
|
||||
update_item = True
|
||||
|
||||
|
||||
|
||||
##### GET THE FILE AND PATH #####
|
||||
playurl = API.get_file_path()
|
||||
|
||||
|
@ -347,26 +342,26 @@ class TVShows(common.Items):
|
|||
|
||||
##### UPDATE THE TVSHOW #####
|
||||
if update_item:
|
||||
log.info("UPDATE tvshow itemid: %s - Title: %s" % (itemid, title))
|
||||
log.info("UPDATE tvshow itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Update the tvshow entry
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE tvshow",
|
||||
"SET c00 = ?, c01 = ?, c04 = ?, c05 = ?, c08 = ?, c09 = ?,",
|
||||
"c12 = ?, c13 = ?, c14 = ?, c15 = ?",
|
||||
"WHERE idShow = ?"
|
||||
))
|
||||
kodicursor.execute(query, (title, plot, rating, premieredate, genre, title,
|
||||
tvdb, mpaa, studio, sorttitle, showid))
|
||||
tvdb, mpaa, studio, sorttitle, showid))
|
||||
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
|
||||
|
||||
##### OR ADD THE TVSHOW #####
|
||||
else:
|
||||
log.info("ADD tvshow itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("ADD tvshow itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Add top path
|
||||
toppathid = self.kodi_db.addPath(toplevelpath)
|
||||
query = ' '.join((
|
||||
|
@ -376,21 +371,20 @@ class TVShows(common.Items):
|
|||
"WHERE idPath = ?"
|
||||
))
|
||||
kodicursor.execute(query, (toplevelpath, "tvshows", "metadata.local", 1, toppathid))
|
||||
|
||||
|
||||
# Add path
|
||||
pathid = self.kodi_db.addPath(path)
|
||||
|
||||
|
||||
# Create the tvshow entry
|
||||
query = (
|
||||
'''
|
||||
INSERT INTO tvshow(
|
||||
idShow, c00, c01, c04, c05, c08, c09, c12, c13, c14, c15)
|
||||
INSERT INTO tvshow(idShow, c00, c01, c04, c05, c08, c09, c12, c13, c14, c15)
|
||||
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
'''
|
||||
)
|
||||
kodicursor.execute(query, (showid, title, plot, rating, premieredate, genre,
|
||||
title, tvdb, mpaa, studio, sorttitle))
|
||||
title, tvdb, mpaa, studio, sorttitle))
|
||||
|
||||
# Link the path
|
||||
query = "INSERT INTO tvshowlinkpath(idShow, idPath) values(?, ?)"
|
||||
|
@ -398,7 +392,7 @@ class TVShows(common.Items):
|
|||
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, showid, "Series", "tvshow", pathid=pathid,
|
||||
checksum=checksum, mediafolderid=viewid)
|
||||
checksum=checksum, mediafolderid=viewid)
|
||||
|
||||
# Update the path
|
||||
query = ' '.join((
|
||||
|
@ -408,7 +402,7 @@ class TVShows(common.Items):
|
|||
"WHERE idPath = ?"
|
||||
))
|
||||
kodicursor.execute(query, (path, None, None, 1, pathid))
|
||||
|
||||
|
||||
# Process cast
|
||||
people = artwork.get_people_artwork(item['People'])
|
||||
self.kodi_db.addPeople(showid, people, "tvshow")
|
||||
|
@ -436,7 +430,7 @@ class TVShows(common.Items):
|
|||
|
||||
if force_episodes:
|
||||
# We needed to recreate the show entry. Re-add episodes now.
|
||||
log.info("Repairing episodes for showid: %s %s" % (showid, title))
|
||||
log.info("Repairing episodes for showid: %s %s", showid, title)
|
||||
all_episodes = emby.getEpisodesbyShow(itemid)
|
||||
self.added_episode(all_episodes['Items'], None)
|
||||
|
||||
|
@ -461,9 +455,9 @@ class TVShows(common.Items):
|
|||
show = self.emby.getItem(seriesId)
|
||||
self.add_update(show)
|
||||
return
|
||||
|
||||
|
||||
seasonid = self.kodi_db.addSeason(showid, seasonnum, item['Name'])
|
||||
|
||||
|
||||
if item['LocationType'] != "Virtual":
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(item['Id'], seasonid, "Season", "season", parentid=showid)
|
||||
|
@ -494,11 +488,11 @@ class TVShows(common.Items):
|
|||
episodeid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
pathid = emby_dbitem[2]
|
||||
log.info("episodeid: %s fileid: %s pathid: %s" % (episodeid, fileid, pathid))
|
||||
|
||||
log.info("episodeid: %s fileid: %s pathid: %s", episodeid, fileid, pathid)
|
||||
|
||||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("episodeid: %s not found." % itemid)
|
||||
log.debug("episodeid: %s not found", itemid)
|
||||
# episodeid
|
||||
kodicursor.execute("select coalesce(max(idEpisode),0) from episode")
|
||||
episodeid = kodicursor.fetchone()[0] + 1
|
||||
|
@ -512,7 +506,7 @@ class TVShows(common.Items):
|
|||
except TypeError:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("episodeid: %s missing from Kodi, repairing the entry." % episodeid)
|
||||
log.info("episodeid: %s missing from Kodi, repairing the entry", episodeid)
|
||||
|
||||
# fileId information
|
||||
checksum = API.get_checksum()
|
||||
|
@ -536,12 +530,12 @@ class TVShows(common.Items):
|
|||
seriesId = item['SeriesId']
|
||||
except KeyError:
|
||||
# Missing seriesId, skip
|
||||
log.error("Skipping: %s. SeriesId is missing." % itemid)
|
||||
log.error("Skipping: %s. SeriesId is missing.", itemid)
|
||||
return False
|
||||
|
||||
|
||||
season = item.get('ParentIndexNumber')
|
||||
episode = item.get('IndexNumber', -1)
|
||||
|
||||
|
||||
if season is None:
|
||||
if item.get('AbsoluteEpisodeNumber'):
|
||||
# Anime scenario
|
||||
|
@ -559,7 +553,7 @@ class TVShows(common.Items):
|
|||
airsBeforeEpisode = item.get('AirsBeforeEpisodeNumber')
|
||||
|
||||
# Append multi episodes to title
|
||||
if item.get('IndexNumberEnd'):
|
||||
if item.get('IndexNumberEnd'):
|
||||
title = "| %02d | %s" % (item['IndexNumberEnd'], title)
|
||||
|
||||
# Get season id
|
||||
|
@ -574,12 +568,12 @@ class TVShows(common.Items):
|
|||
try:
|
||||
showid = show[0]
|
||||
except TypeError:
|
||||
log.error("Skipping: %s. Unable to add series: %s." % (itemid, seriesId))
|
||||
log.error("Skipping: %s. Unable to add series: %s", itemid, seriesId)
|
||||
return False
|
||||
|
||||
seasonid = self.kodi_db.addSeason(showid, season)
|
||||
|
||||
|
||||
|
||||
##### GET THE FILE AND PATH #####
|
||||
playurl = API.get_file_path()
|
||||
|
||||
|
@ -593,7 +587,7 @@ class TVShows(common.Items):
|
|||
# Direct paths is set the Kodi way
|
||||
if not self.path_validation(playurl):
|
||||
return False
|
||||
|
||||
|
||||
path = playurl.replace(filename, "")
|
||||
window('emby_pathverified', value="true")
|
||||
else:
|
||||
|
@ -611,47 +605,46 @@ class TVShows(common.Items):
|
|||
|
||||
##### UPDATE THE EPISODE #####
|
||||
if update_item:
|
||||
log.info("UPDATE episode itemid: %s - Title: %s" % (itemid, title))
|
||||
log.info("UPDATE episode itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Update the movie entry
|
||||
if self.kodi_version in (16, 17):
|
||||
# Kodi Jarvis, Krypton
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE episode",
|
||||
"SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?,",
|
||||
"c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idSeason = ?, idShow = ?",
|
||||
"WHERE idEpisode = ?"
|
||||
))
|
||||
kodicursor.execute(query, (title, plot, rating, writer, premieredate,
|
||||
runtime, director, season, episode, title, airsBeforeSeason,
|
||||
airsBeforeEpisode, seasonid, showid, episodeid))
|
||||
kodicursor.execute(query, (title, plot, rating, writer, premieredate, runtime,
|
||||
director, season, episode, title, airsBeforeSeason,
|
||||
airsBeforeEpisode, seasonid, showid, episodeid))
|
||||
else:
|
||||
query = ' '.join((
|
||||
|
||||
|
||||
"UPDATE episode",
|
||||
"SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?,",
|
||||
"c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idShow = ?",
|
||||
"WHERE idEpisode = ?"
|
||||
))
|
||||
kodicursor.execute(query, (title, plot, rating, writer, premieredate,
|
||||
runtime, director, season, episode, title, airsBeforeSeason,
|
||||
airsBeforeEpisode, showid, episodeid))
|
||||
|
||||
kodicursor.execute(query, (title, plot, rating, writer, premieredate, runtime,
|
||||
director, season, episode, title, airsBeforeSeason,
|
||||
airsBeforeEpisode, showid, episodeid))
|
||||
# Update the checksum in emby table
|
||||
emby_db.updateReference(itemid, checksum)
|
||||
# Update parentid reference
|
||||
emby_db.updateParentId(itemid, seasonid)
|
||||
|
||||
|
||||
##### OR ADD THE EPISODE #####
|
||||
else:
|
||||
log.info("ADD episode itemid: %s - Title: %s" % (itemid, title))
|
||||
|
||||
log.info("ADD episode itemid: %s - Title: %s", itemid, title)
|
||||
|
||||
# Add path
|
||||
pathid = self.kodi_db.addPath(path)
|
||||
# Add the file
|
||||
fileid = self.kodi_db.addFile(filename, pathid)
|
||||
|
||||
|
||||
# Create the episode entry
|
||||
if self.kodi_version in (16, 17):
|
||||
# Kodi Jarvis, Krypton
|
||||
|
@ -665,8 +658,8 @@ class TVShows(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (episodeid, fileid, title, plot, rating, writer,
|
||||
premieredate, runtime, director, season, episode, title, showid,
|
||||
airsBeforeSeason, airsBeforeEpisode, seasonid))
|
||||
premieredate, runtime, director, season, episode, title,
|
||||
showid, airsBeforeSeason, airsBeforeEpisode, seasonid))
|
||||
else:
|
||||
query = (
|
||||
'''
|
||||
|
@ -678,12 +671,12 @@ class TVShows(common.Items):
|
|||
'''
|
||||
)
|
||||
kodicursor.execute(query, (episodeid, fileid, title, plot, rating, writer,
|
||||
premieredate, runtime, director, season, episode, title, showid,
|
||||
airsBeforeSeason, airsBeforeEpisode))
|
||||
premieredate, runtime, director, season, episode, title,
|
||||
showid, airsBeforeSeason, airsBeforeEpisode))
|
||||
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, episodeid, "Episode", "episode", fileid, pathid,
|
||||
seasonid, checksum)
|
||||
seasonid, checksum)
|
||||
|
||||
# Update the path
|
||||
query = ' '.join((
|
||||
|
@ -702,7 +695,7 @@ class TVShows(common.Items):
|
|||
"WHERE idFile = ?"
|
||||
))
|
||||
kodicursor.execute(query, (pathid, filename, dateadded, fileid))
|
||||
|
||||
|
||||
# Process cast
|
||||
people = artwork.get_people_artwork(item['People'])
|
||||
self.kodi_db.addPeople(episodeid, people, "episode")
|
||||
|
@ -736,7 +729,7 @@ class TVShows(common.Items):
|
|||
# Poster with progress bar
|
||||
emby_db = self.emby_db
|
||||
API = api.API(item)
|
||||
|
||||
|
||||
# Get emby information
|
||||
itemid = item['Id']
|
||||
checksum = API.get_checksum()
|
||||
|
@ -750,9 +743,7 @@ class TVShows(common.Items):
|
|||
kodiid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
mediatype = emby_dbitem[4]
|
||||
log.info(
|
||||
"Update playstate for %s: %s fileid: %s"
|
||||
% (mediatype, item['Name'], fileid))
|
||||
log.info("Update playstate for %s: %s fileid: %s", mediatype, item['Name'], fileid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -769,7 +760,7 @@ class TVShows(common.Items):
|
|||
resume = API.adjust_resume(userdata['Resume'])
|
||||
total = round(float(runtime), 6)
|
||||
|
||||
log.debug("%s New resume point: %s" % (itemid, resume))
|
||||
log.debug("%s New resume point: %s", itemid, resume)
|
||||
|
||||
self.kodi_db.addPlaystate(fileid, resume, total, playcount, dateplayed)
|
||||
if not self.direct_path and not resume:
|
||||
|
@ -796,18 +787,15 @@ class TVShows(common.Items):
|
|||
def remove(self, itemid):
|
||||
# Remove showid, fileid, pathid, emby reference
|
||||
emby_db = self.emby_db
|
||||
embycursor = self.embycursor
|
||||
kodicursor = self.kodicursor
|
||||
artwork = self.artwork
|
||||
|
||||
emby_dbitem = emby_db.getItem_byId(itemid)
|
||||
try:
|
||||
kodiid = emby_dbitem[0]
|
||||
fileid = emby_dbitem[1]
|
||||
pathid = emby_dbitem[2]
|
||||
parentid = emby_dbitem[3]
|
||||
mediatype = emby_dbitem[4]
|
||||
log.info("Removing %s kodiid: %s fileid: %s" % (mediatype, kodiid, fileid))
|
||||
log.info("Removing %s kodiid: %s fileid: %s", mediatype, kodiid, fileid)
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
@ -816,7 +804,6 @@ class TVShows(common.Items):
|
|||
# Remove the emby reference
|
||||
emby_db.removeItem(itemid)
|
||||
|
||||
|
||||
##### IF EPISODE #####
|
||||
|
||||
if mediatype == "episode":
|
||||
|
@ -829,7 +816,7 @@ class TVShows(common.Items):
|
|||
showid = season[1]
|
||||
except TypeError:
|
||||
return
|
||||
|
||||
|
||||
season_episodes = emby_db.getItem_byParentId(parentid, "episode")
|
||||
if not season_episodes:
|
||||
self.removeSeason(parentid)
|
||||
|
@ -886,7 +873,7 @@ class TVShows(common.Items):
|
|||
else:
|
||||
# Remove emby episodes
|
||||
emby_db.removeItems_byParentId(kodiid, "episode")
|
||||
|
||||
|
||||
# Remove season
|
||||
self.removeSeason(kodiid)
|
||||
|
||||
|
@ -897,14 +884,14 @@ class TVShows(common.Items):
|
|||
self.removeShow(parentid)
|
||||
emby_db.removeItem_byKodiId(parentid, "tvshow")
|
||||
|
||||
log.info("Deleted %s: %s from kodi database" % (mediatype, itemid))
|
||||
log.info("Deleted %s: %s from kodi database", mediatype, itemid)
|
||||
|
||||
def removeShow(self, kodiid):
|
||||
|
||||
kodicursor = self.kodicursor
|
||||
self.artwork.delete_artwork(kodiid, "tvshow", kodicursor)
|
||||
kodicursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodiid,))
|
||||
log.debug("Removed tvshow: %s." % kodiid)
|
||||
log.debug("Removed tvshow: %s", kodiid)
|
||||
|
||||
def removeSeason(self, kodiid):
|
||||
|
||||
|
@ -912,7 +899,7 @@ class TVShows(common.Items):
|
|||
|
||||
self.artwork.delete_artwork(kodiid, "season", kodicursor)
|
||||
kodicursor.execute("DELETE FROM seasons WHERE idSeason = ?", (kodiid,))
|
||||
log.debug("Removed season: %s." % kodiid)
|
||||
log.debug("Removed season: %s", kodiid)
|
||||
|
||||
def removeEpisode(self, kodiid, fileid):
|
||||
|
||||
|
@ -921,4 +908,4 @@ class TVShows(common.Items):
|
|||
self.artwork.delete_artwork(kodiid, "episode", kodicursor)
|
||||
kodicursor.execute("DELETE FROM episode WHERE idEpisode = ?", (kodiid,))
|
||||
kodicursor.execute("DELETE FROM files WHERE idFile = ?", (fileid,))
|
||||
log.debug("Removed episode: %s." % kodiid)
|
||||
log.debug("Removed episode: %s", kodiid)
|
||||
|
|
|
@ -148,10 +148,10 @@ class Service(object):
|
|||
self.shutdown()
|
||||
|
||||
def _startup(self):
|
||||
|
||||
|
||||
ga = GoogleAnalytics()
|
||||
ga.sendEventData("Application", "Startup")
|
||||
|
||||
|
||||
# Start up events
|
||||
self.warn_auth = True
|
||||
|
||||
|
@ -288,7 +288,7 @@ class Service(object):
|
|||
log.exception(error)
|
||||
|
||||
def shutdown(self):
|
||||
|
||||
|
||||
ga = GoogleAnalytics()
|
||||
ga.sendEventData("Application", "Shutdown")
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ if __name__ == "__main__":
|
|||
except Exception as error:
|
||||
ga = GoogleAnalytics()
|
||||
errStrings = ga.formatException()
|
||||
ga.sendEventData("Exception", errStrings[0], errStrings[1])
|
||||
ga.sendEventData("Exception", errStrings[0], errStrings[1])
|
||||
log.exception(error)
|
||||
log.info("Forcing shutdown")
|
||||
service.shutdown()
|
||||
|
|
Loading…
Reference in a new issue