Update movie/boxset compare

Also update checksum for boxsets to regular checksum. Seems userdata was
added for them. This will cause all boxsets to update once.
This commit is contained in:
angelblue05 2016-10-18 02:17:10 -05:00
parent e503b87c35
commit 394a67fe33
3 changed files with 107 additions and 97 deletions

View file

@ -170,6 +170,17 @@ class Embydb_Functions():
self.embycursor.execute(query, (mediafolderid,)) self.embycursor.execute(query, (mediafolderid,))
return self.embycursor.fetchall() return self.embycursor.fetchall()
def get_item_by_view(self, view_id):
query = ' '.join((
"SELECT emby_id",
"FROM emby",
"WHERE media_folder = ?"
))
self.embycursor.execute(query, (view_id,))
return self.embycursor.fetchall()
def getItem_byKodiId(self, kodiid, mediatype): def getItem_byKodiId(self, kodiid, mediatype):
query = ' '.join(( query = ' '.join((
@ -217,6 +228,18 @@ class Embydb_Functions():
self.embycursor.execute(query, (mediatype,)) self.embycursor.execute(query, (mediatype,))
return self.embycursor.fetchall() return self.embycursor.fetchall()
def get_checksum_by_view(self, media_type, view_id):
query = ' '.join((
"SELECT emby_id, checksum",
"FROM emby",
"WHERE emby_type = ?",
"AND media_folder = ?"
))
self.embycursor.execute(query, (media_type, view_id,))
return self.embycursor.fetchall()
def getMediaType_byId(self, embyid): def getMediaType_byId(self, embyid):
query = ' '.join(( query = ' '.join((

View file

@ -7,6 +7,7 @@ import logging
import xbmc import xbmc
import xbmcvfs import xbmcvfs
import api
import artwork import artwork
import downloadutils import downloadutils
import read_embyserver as embyserver import read_embyserver as embyserver
@ -132,3 +133,22 @@ class Items(object):
if update: if update:
self.count += 1 self.count += 1
def compare_checksum(self, items, compare_to):
update_list = list()
for item in items:
if self.should_stop():
return False
item_id = item['Id']
if compare_to.get(item_id) != api.API(item).get_checksum():
# Only update if movie is not in Kodi or checksum is different
update_list.append(item_id)
compare_to.pop(item_id, None)
return update_list

View file

@ -56,116 +56,77 @@ class Movies(Items):
def compare_all(self): def compare_all(self):
# Pull the list of movies and boxsets in Kodi # Pull the list of movies and boxsets in Kodi
pdialog = self.pdialog
views = self.emby_db.getView_byType('movies') views = self.emby_db.getView_byType('movies')
views += self.emby_db.getView_byType('mixed') views += self.emby_db.getView_byType('mixed')
log.info("Media folders: %s", views) log.info("Media folders: %s", views)
try: # Process movies
all_kodisets = dict(self.emby_db.get_checksum('BoxSet'))
except ValueError:
all_kodisets = {}
try:
all_kodimovies = dict(self.emby_db.get_checksum('Movie'))
except ValueError:
all_kodimovies = {}
all_embymoviesIds = set()
all_embyboxsetsIds = set()
updatelist = []
for view in views: for view in views:
if self.should_stop(): if self.should_stop():
return False return False
# Get items per view if not self.compare_movies(view):
viewId = view['id']
viewName = view['name']
if pdialog:
pdialog.update(
heading=lang(29999),
message="%s %s..." % (lang(33026), viewName))
all_embymovies = self.emby.getMovies(viewId, basic=True, dialog=pdialog)
for embymovie in all_embymovies['Items']:
if self.should_stop():
return False
API = api.API(embymovie)
itemid = embymovie['Id']
all_embymoviesIds.add(itemid)
if all_kodimovies.get(itemid) != API.get_checksum():
# 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)
embymovies = self.emby.getFullItems(updatelist)
total = len(updatelist)
del updatelist[:]
if pdialog:
pdialog.update(heading="Processing %s / %s items" % (viewName, total))
self.added(embymovies, total, view)
boxsets = self.emby.getBoxset(dialog=pdialog)
embyboxsets = []
if pdialog:
pdialog.update(heading=lang(29999), message=lang(33027))
for boxset in boxsets['Items']:
if self.should_stop():
return False return False
# Boxset has no real userdata, so using etag to compare # Process boxsets
itemid = boxset['Id'] if not self.compare_boxsets():
all_embyboxsetsIds.add(itemid) return False
if all_kodisets.get(itemid) != boxset['Etag']:
# Only update if boxset is not in Kodi or boxset['Etag'] is different
updatelist.append(itemid)
embyboxsets.append(boxset)
log.info("Boxsets to update: %s", updatelist)
self.total = len(updatelist)
if pdialog:
pdialog.update(heading="Processing Boxsets / %s items" % total)
self.count = 0
for boxset in embyboxsets:
# Process individual boxset
if self.should_stop():
return False
self.title = boxset['Name']
self.update_pdialog()
self.add_updateBoxset(boxset)
self.count += 1
##### PROCESS DELETES #####
for kodimovie in all_kodimovies:
if kodimovie not in all_embymoviesIds:
self.remove(kodimovie)
log.info("Movies compare finished.")
for boxset in all_kodisets:
if boxset not in all_embyboxsetsIds:
self.remove(boxset)
log.info("Boxsets compare finished.")
return True return True
def compare_movies(self, view):
view_id = view['id']
view_name = view['name']
if self.pdialog:
self.pdialog.update(heading=lang(29999), message="%s %s..." % (lang(33026), view_name))
movies = dict(self.emby_db.get_checksum_by_view('Movie', view_id))
emby_movies = self.emby.getMovies(view_id, basic=True, dialog=self.pdialog)
update_list = self.compare_checksum(emby_movies['Items'], movies)
log.info("Movies to update for %s: %s", view_name, update_list)
emby_movies = self.emby.getFullItems(update_list)
total = len(update_list)
if self.pdialog:
self.pdialog.update(heading="Processing %s / %s items" % (view_name, total))
# Process additions and updates
if emby_movies:
self.added(emby_movies, total, view)
# Process deletes
if movies:
self.remove_all("Movie", movies.items())
return True
def compare_boxsets(self):
if self.pdialog:
self.pdialog.update(heading=lang(29999), message=lang(33027))
boxsets = dict(self.emby_db.get_checksum('BoxSet'))
emby_boxsets = self.emby.getBoxset(dialog=self.pdialog)
update_list = self.compare_checksum(emby_boxsets['Items'], boxsets)
log.info("Boxsets to update: %s", update_list)
emby_boxsets = self.emby.getFullItems(update_list)
total = len(update_list)
if self.pdialog:
self.pdialog.update(heading="Processing Boxsets / %s items" % total)
# Processing additions and updates
if emby_boxsets:
self.added_boxset(emby_boxsets, total)
# Processing removals
if boxsets:
self.remove_all("BoxSet", boxsets.items())
return True
def added(self, items, total=None, view=None): def added(self, items, total=None, view=None):
@ -173,6 +134,11 @@ class Movies(Items):
if self.add_update(item, view): if self.add_update(item, view):
self.content_pop(item.get('Name', "unknown")) self.content_pop(item.get('Name', "unknown"))
def added_boxset(self, items, total=None):
for item in super(Movies, self).added(items, total):
self.add_updateBoxset(item)
@catch_except() @catch_except()
def add_update(self, item, view=None): def add_update(self, item, view=None):
# Process single movie # Process single movie
@ -381,10 +347,11 @@ class Movies(Items):
emby = self.emby emby = self.emby
emby_db = self.emby_db emby_db = self.emby_db
artwork = self.artwork artwork = self.artwork
API = api.API(boxset)
boxsetid = boxset['Id'] boxsetid = boxset['Id']
title = boxset['Name'] title = boxset['Name']
checksum = boxset['Etag'] checksum = API.get_checksum()
emby_dbitem = emby_db.getItem_byId(boxsetid) emby_dbitem = emby_db.getItem_byId(boxsetid)
try: try:
setid = emby_dbitem[0] setid = emby_dbitem[0]