2016-03-31 21:05:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2016-10-10 11:14:10 +00:00
|
|
|
|
2016-03-31 21:05:41 +00:00
|
|
|
import read_embyserver as embyserver
|
2016-10-10 08:19:00 +00:00
|
|
|
from objects import Movies, MusicVideos, TVShows, Music
|
2016-10-10 11:14:10 +00:00
|
|
|
from utils import settings, kodiSQL
|
2016-03-31 21:05:41 +00:00
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
|
|
|
|
|
|
|
#################################################################################################
|
2016-03-31 21:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Items(object):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, embycursor, kodicursor):
|
|
|
|
|
|
|
|
self.embycursor = embycursor
|
|
|
|
self.kodicursor = kodicursor
|
|
|
|
|
|
|
|
self.emby = embyserver.Read_EmbyServer()
|
2016-10-10 11:14:10 +00:00
|
|
|
self.music_enabled = settings('enableMusic') == "true"
|
2016-03-31 21:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def itemsbyId(self, items, process, pdialog=None):
|
|
|
|
# Process items by itemid. Process can be added, update, userdata, remove
|
|
|
|
embycursor = self.embycursor
|
|
|
|
kodicursor = self.kodicursor
|
2016-10-10 11:14:10 +00:00
|
|
|
|
2016-03-31 21:05:41 +00:00
|
|
|
itemtypes = {
|
|
|
|
|
|
|
|
'Movie': Movies,
|
|
|
|
'BoxSet': Movies,
|
2016-10-10 08:19:00 +00:00
|
|
|
'MusicVideo': MusicVideos,
|
2016-03-31 21:05:41 +00:00
|
|
|
'Series': TVShows,
|
|
|
|
'Season': TVShows,
|
|
|
|
'Episode': TVShows,
|
|
|
|
'MusicAlbum': Music,
|
|
|
|
'MusicArtist': Music,
|
|
|
|
'AlbumArtist': Music,
|
|
|
|
'Audio': Music
|
|
|
|
}
|
|
|
|
|
|
|
|
update_videolibrary = False
|
|
|
|
total = 0
|
|
|
|
for item in items:
|
|
|
|
total += len(items[item])
|
|
|
|
|
|
|
|
if total == 0:
|
|
|
|
return False
|
|
|
|
|
2016-10-10 11:14:10 +00:00
|
|
|
log.info("Processing %s: %s", process, items)
|
2016-03-31 21:05:41 +00:00
|
|
|
if pdialog:
|
|
|
|
pdialog.update(heading="Processing %s: %s items" % (process, total))
|
|
|
|
|
|
|
|
for itemtype in items:
|
|
|
|
|
|
|
|
# Safety check
|
|
|
|
if not itemtypes.get(itemtype):
|
|
|
|
# We don't process this type of item
|
|
|
|
continue
|
|
|
|
|
|
|
|
itemlist = items[itemtype]
|
|
|
|
if not itemlist:
|
|
|
|
# The list to process is empty
|
|
|
|
continue
|
|
|
|
|
|
|
|
musicconn = None
|
|
|
|
|
|
|
|
if itemtype in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'):
|
2016-10-10 11:14:10 +00:00
|
|
|
if self.music_enabled:
|
2016-06-20 01:17:10 +00:00
|
|
|
musicconn = kodiSQL('music')
|
2016-03-31 21:05:41 +00:00
|
|
|
musiccursor = musicconn.cursor()
|
2016-10-10 08:19:00 +00:00
|
|
|
items_process = itemtypes[itemtype](embycursor, musiccursor, pdialog)
|
2016-03-31 21:05:41 +00:00
|
|
|
else:
|
|
|
|
# Music is not enabled, do not proceed with itemtype
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
update_videolibrary = True
|
2016-10-10 08:19:00 +00:00
|
|
|
items_process = itemtypes[itemtype](embycursor, kodicursor, pdialog)
|
2016-03-31 21:05:41 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:19:00 +00:00
|
|
|
if process == "added":
|
|
|
|
items_process.add_all(itemtype, itemlist)
|
2016-10-10 08:36:02 +00:00
|
|
|
elif process == "remove":
|
|
|
|
items_process.remove_all(itemtype, itemlist)
|
2016-10-10 08:19:00 +00:00
|
|
|
else:
|
2016-10-10 11:14:10 +00:00
|
|
|
process_items = self.emby.getFullItems(itemlist)
|
|
|
|
items_process.process_all(itemtype, process, process_items, total)
|
2016-03-31 21:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
if musicconn is not None:
|
|
|
|
# close connection for special types
|
2016-10-10 11:14:10 +00:00
|
|
|
log.info("updating music database")
|
2016-03-31 21:05:41 +00:00
|
|
|
musicconn.commit()
|
|
|
|
musiccursor.close()
|
|
|
|
|
2016-10-10 11:14:10 +00:00
|
|
|
return (True, update_videolibrary)
|