jellyfin-kodi/resources/lib/itemtypes.py

100 lines
3.4 KiB
Python
Raw Normal View History

2016-03-31 21:05:41 +00:00
# -*- coding: utf-8 -*-
##################################################################################################
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
from utils import settings
from database import DatabaseConn
from contextlib import closing
2016-03-31 21:05:41 +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-20 07:14:27 +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))
# this is going to open a music connection even if it is not needed but
# I feel that is better than trying to sort out the login yourself
with DatabaseConn('music') as conn:
with closing(conn.cursor()) as cursor_music:
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
if itemtype in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'):
if self.music_enabled:
items_process = itemtypes[itemtype](embycursor, cursor_music, pdialog) # see note above
else:
# Music is not enabled, do not proceed with itemtype
continue
else:
update_videolibrary = True
items_process = itemtypes[itemtype](embycursor, kodicursor, pdialog)
if process == "added":
items_process.add_all(itemtype, itemlist)
elif process == "remove":
items_process.remove_all(itemtype, itemlist)
else:
process_items = self.emby.getFullItems(itemlist)
items_process.process_all(itemtype, process, process_items, total)
2016-03-31 21:05:41 +00:00
2016-10-10 11:14:10 +00:00
return (True, update_videolibrary)