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): def get_items(parent_id, item_type=None, basic=False, params=None):
query = { query = {
@ -178,6 +186,20 @@ def get_albums_by_artist(artist_id):
for items in get_items(None, "MusicAlbum", params=params): for items in get_items(None, "MusicAlbum", params=params):
yield items 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): def _split_list(item_list, size):
# Split up list in pieces of size. Will generate a list of lists # 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)] return [item_list[i:i + size] for i in range(0, len(item_list), size)]

View file

@ -4,6 +4,7 @@
import logging import logging
import emby as mb
import read_embyserver as embyserver import read_embyserver as embyserver
from objects import Movies, MusicVideos, TVShows, Music from objects import Movies, MusicVideos, TVShows, Music
from utils import settings from utils import settings
@ -90,7 +91,7 @@ class Items(object):
elif process == "remove": elif process == "remove":
items_process.remove_all(itemtype, itemlist) items_process.remove_all(itemtype, itemlist)
else: 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) 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 # Prepare items according to process process_type
if process_type == "added": if process_type == "added":
items = self.emby.sortby_mediatype(listItems) items = mb.sortby_mediatype(listItems)
elif process_type in ("userdata", "remove"): elif process_type in ("userdata", "remove"):
items = emby_db.sortby_mediaType(listItems, unsorted=False) items = emby_db.sortby_mediaType(listItems, unsorted=False)
@ -580,7 +580,7 @@ class LibrarySync(threading.Thread):
else: else:
items = emby_db.sortby_mediaType(listItems) items = emby_db.sortby_mediaType(listItems)
if items.get('Unsorted'): 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) doupdate = items_process.itemsbyId(sorted_items, "added", pDialog)
if doupdate: if doupdate:
embyupdate, kodiupdate_video = doupdate embyupdate, kodiupdate_video = doupdate