Generators

For music
This commit is contained in:
angelblue05 2018-03-15 05:32:56 -05:00
parent 7ded39d580
commit a2fb25a922
3 changed files with 46 additions and 13 deletions

View file

@ -88,7 +88,7 @@ def show(handler, params):
################################################################################################# #################################################################################################
# Single item functions # Single result functions
################################################################################################# #################################################################################################
@ -107,7 +107,7 @@ def get_seasons(self, show_id):
################################################################################################# #################################################################################################
# Get multiple items (Generator) # Multiple calls to get multiple items (Generator)
''' This should help with memory issues. ''' This should help with memory issues.
for items in generator(...): for items in generator(...):
@ -119,7 +119,7 @@ def get_seasons(self, show_id):
################################################################################################# #################################################################################################
def get_items(parent_id, item_type, basic=False): def get_items(parent_id, item_type=None, basic=False, params=None):
query = { query = {
'url': "Users/{UserId}/Items", 'url': "Users/{UserId}/Items",
@ -127,9 +127,14 @@ def get_items(parent_id, item_type, basic=False):
'ParentId': parent_id, 'ParentId': parent_id,
'IncludeItemTypes': item_type, 'IncludeItemTypes': item_type,
'SortBy': "SortName", 'SortBy': "SortName",
'SortOrder': "Ascending",
'Fields': basic_info() if basic else complete_info() 'Fields': basic_info() if basic else complete_info()
} }
} }
if params:
query['params'].update(params)
for items in _get_items(query): for items in _get_items(query):
yield items yield items
@ -146,6 +151,33 @@ def get_item_list(item_list, basic=False):
for items in _get_items(query): for items in _get_items(query):
yield items yield items
def get_artists(parent_id=None):
query = {
'url': "Artists?UserId={UserId}",
'params': {
'ParentId': parent_id,
'SortBy': "SortName",
'SortOrder': "Ascending",
'Fields': (
"Etag,Genres,SortName,Studios,Writer,ProductionYear,"
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,"
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview,ItemCounts"
)
}
}
for items in _get_items(query):
yield items
def get_albums_by_artist(artist_id):
params = {
'SortBy': "DateCreated",
'ArtistIds': artist_id
}
for items in get_items(None, "MusicAlbum", params=params):
yield 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)]
@ -171,8 +203,7 @@ def _get_items(query):
'EnableTotalRecordCount': False, 'EnableTotalRecordCount': False,
'LocationTypes': "FileSystem,Remote,Offline", 'LocationTypes': "FileSystem,Remote,Offline",
'IsMissing': False, 'IsMissing': False,
'Recursive': True, 'Recursive': True
'SortOrder': "Ascending"
}) })
try: try:

View file

@ -490,8 +490,9 @@ class LibrarySync(threading.Thread):
message="%s Music..." % lang(33021)) message="%s Music..." % lang(33021))
for view in views: for view in views:
all_artists = self.emby.getArtists(view['id'], dialog=pdialog)
music.add_all("MusicArtist", all_artists) for all_artists in mb.get_artists(view['id']):
music.add_all("MusicArtist", all_artists['Items'])
log.debug("Finished syncing music") log.debug("Finished syncing music")
@ -748,7 +749,7 @@ class LibrarySync(threading.Thread):
self.incremental_count = 0 self.incremental_count = 0
window('emby_kodiScan', clear=True) window('emby_kodiScan', clear=True)
if ((not xbmc.Player().isPlaying() or xbmc.getCondVisibility('VideoPlayer.Content(livetv)')) and if ((not xbmc.Player().isPlayingVideo() or xbmc.getCondVisibility('VideoPlayer.Content(livetv)')) and
window('emby_dbScan') != "true" and window('emby_shouldStop') != "true"): window('emby_dbScan') != "true" and window('emby_shouldStop') != "true"):
self.incrementalSync() self.incrementalSync()

View file

@ -6,6 +6,7 @@ import logging
from datetime import datetime from datetime import datetime
import api import api
import emby as mb
import embydb_functions as embydb import embydb_functions as embydb
import musicutils import musicutils
import _kodi_music import _kodi_music
@ -89,7 +90,7 @@ class Music(Items):
artists = dict(self.emby_db.get_checksum('MusicArtist')) artists = dict(self.emby_db.get_checksum('MusicArtist'))
album_artists = dict(self.emby_db.get_checksum('AlbumArtist')) album_artists = dict(self.emby_db.get_checksum('AlbumArtist'))
emby_artists = self.emby.getArtists(dialog=self.pdialog) emby_artists = (items['Items'] for items in mb.get_artists())
for item in emby_artists['Items']: for item in emby_artists['Items']:
@ -151,7 +152,7 @@ class Music(Items):
for item in self.added(items, total): for item in self.added(items, total):
if self.add_updateArtist(item): if self.add_updateArtist(item):
# Add albums # Add albums
all_albums = self.emby.getAlbumsbyArtist(item['Id']) for all_albums in mb.get_albums_by_artist(item['Id']):
self.add_albums(all_albums['Items']) self.add_albums(all_albums['Items'])
def add_albums(self, items, total=None): def add_albums(self, items, total=None):
@ -163,7 +164,7 @@ class Music(Items):
if self.add_updateAlbum(item): if self.add_updateAlbum(item):
# Add songs # Add songs
all_songs = self.emby.getSongsbyAlbum(item['Id']) for all_songs in mb.get_items(item['Id'], "Audio"):
self.add_songs(all_songs['Items']) self.add_songs(all_songs['Items'])
def add_songs(self, items, total=None): def add_songs(self, items, total=None):