2016-03-31 21:05:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2016-03-31 21:05:41 +00:00
|
|
|
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
|
2016-10-10 08:19:00 +00:00
|
|
|
from objects import Movies, MusicVideos, TVShows, Music
|
2016-07-24 08:59:48 +00:00
|
|
|
from utils import window, settings, language as lang, 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.doUtils = downloadutils.DownloadUtils()
|
|
|
|
|
2016-06-17 21:42:48 +00:00
|
|
|
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
|
2016-03-31 21:05:41 +00:00
|
|
|
|
|
|
|
self.artwork = artwork.Artwork()
|
|
|
|
self.emby = embyserver.Read_EmbyServer()
|
|
|
|
self.emby_db = embydb.Embydb_Functions(embycursor)
|
|
|
|
self.kodi_db = kodidb.Kodidb_Functions(kodicursor)
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
'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-07-24 08:59:48 +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))
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
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'):
|
|
|
|
if 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":
|
|
|
|
processItems = itemlist
|
|
|
|
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:
|
|
|
|
processItems = emby.getFullItems(itemlist)
|
|
|
|
items_process.process_all(itemtype, process, processItems, total)
|
2016-03-31 21:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
if musicconn is not None:
|
|
|
|
# close connection for special types
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Updating music database.")
|
2016-03-31 21:05:41 +00:00
|
|
|
musicconn.commit()
|
|
|
|
musiccursor.close()
|
|
|
|
|
2016-10-10 08:19:00 +00:00
|
|
|
return (True, update_videolibrary)
|