Move incremental to generator

This commit is contained in:
angelblue05 2018-04-03 18:38:53 -05:00
parent 6736223a86
commit c4669e5b86
4 changed files with 27 additions and 4 deletions

View file

@ -119,6 +119,14 @@ def get_seasons(self, show_id):
#################################################################################################
def get_all(generator):
items = []
for item in generator:
items.extend(item['Items'])
return items
def get_items(parent_id, item_type=None, basic=False, params=None):
query = {
@ -178,6 +186,20 @@ def get_albums_by_artist(artist_id):
for items in get_items(None, "MusicAlbum", params=params):
yield items
def sortby_mediatype(item_ids):
sorted_items = {}
items = get_all(get_item_list(item_ids))
for item in items:
mediatype = item.get('Type')
if mediatype:
sorted_items.setdefault(mediatype, []).append(item)
return sorted_items
def _split_list(item_list, size):
# Split up list in pieces of size. Will generate a list of lists
return [item_list[i:i + size] for i in range(0, len(item_list), size)]

View file

@ -4,6 +4,7 @@
import logging
import emby as mb
import read_embyserver as embyserver
from objects import Movies, MusicVideos, TVShows, Music
from utils import settings
@ -90,7 +91,7 @@ class Items(object):
elif process == "remove":
items_process.remove_all(itemtype, itemlist)
else:
process_items = self.emby.getFullItems(itemlist)
process_items = mb.get_all(mb.get_item_list(itemlist))
items_process.process_all(itemtype, process, process_items, total)

View file

@ -572,7 +572,7 @@ class LibrarySync(threading.Thread):
# Prepare items according to process process_type
if process_type == "added":
items = self.emby.sortby_mediatype(listItems)
items = mb.sortby_mediatype(listItems)
elif process_type in ("userdata", "remove"):
items = emby_db.sortby_mediaType(listItems, unsorted=False)
@ -580,7 +580,7 @@ class LibrarySync(threading.Thread):
else:
items = emby_db.sortby_mediaType(listItems)
if items.get('Unsorted'):
sorted_items = self.emby.sortby_mediatype(items['Unsorted'])
sorted_items = mb.sortby_mediatype(items['Unsorted'])
doupdate = items_process.itemsbyId(sorted_items, "added", pDialog)
if doupdate:
embyupdate, kodiupdate_video = doupdate