mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-26 02:36:10 +00:00
Optimize network calls for music syncing
This commit is contained in:
parent
da21f49928
commit
5f34222712
2 changed files with 81 additions and 44 deletions
|
@ -189,31 +189,40 @@ def get_items(parent_id, item_type=None, basic=False, params=None):
|
||||||
yield items
|
yield items
|
||||||
|
|
||||||
|
|
||||||
def get_artists(parent_id=None, basic=False, params=None, server_id=None):
|
def get_artists(parent_id=None):
|
||||||
|
|
||||||
query = {
|
url = "Artists"
|
||||||
'url': "Artists",
|
|
||||||
'params': {
|
params = {
|
||||||
'UserId': "{UserId}",
|
'UserId': "{UserId}",
|
||||||
'ParentId': parent_id,
|
'ParentId': parent_id,
|
||||||
'SortBy': "SortName",
|
'SortBy': "SortName",
|
||||||
'SortOrder': "Ascending",
|
'SortOrder': "Ascending",
|
||||||
'Fields': api.basic_info() if basic else api.music_info(),
|
'Fields': api.music_info(),
|
||||||
'CollapseBoxSetItems': False,
|
'CollapseBoxSetItems': False,
|
||||||
'IsVirtualUnaired': False,
|
'IsVirtualUnaired': False,
|
||||||
'EnableTotalRecordCount': False,
|
'EnableTotalRecordCount': False,
|
||||||
'LocationTypes': "FileSystem,Remote,Offline",
|
'LocationTypes': "FileSystem,Remote,Offline",
|
||||||
'IsMissing': False,
|
'IsMissing': False,
|
||||||
'Recursive': True
|
'Recursive': True
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if params:
|
return _get(url, params)
|
||||||
query['params'].update(params)
|
|
||||||
|
|
||||||
for items in _get_items(query, server_id):
|
|
||||||
yield items
|
|
||||||
|
|
||||||
|
def get_library_items(library_id, item_type):
|
||||||
|
url = "Users/{UserId}/Items"
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'ParentId': library_id,
|
||||||
|
'IncludeItemTypes': item_type,
|
||||||
|
'SortBy': "SortName",
|
||||||
|
'SortOrder': "Ascending",
|
||||||
|
'Fields': api.info(),
|
||||||
|
'Recursive': True,
|
||||||
|
}
|
||||||
|
|
||||||
|
return _get(url, params)
|
||||||
|
|
||||||
def get_albums_by_artist(artist_id, basic=False):
|
def get_albums_by_artist(artist_id, basic=False):
|
||||||
|
|
||||||
|
|
|
@ -407,36 +407,64 @@ class FullSync(object):
|
||||||
with Database('jellyfin') as jellyfindb:
|
with Database('jellyfin') as jellyfindb:
|
||||||
obj = Music(self.server, jellyfindb, musicdb, self.direct_path)
|
obj = Music(self.server, jellyfindb, musicdb, self.direct_path)
|
||||||
|
|
||||||
for items in server.get_artists(library['Id'], False, self.sync['RestorePoint'].get('params')):
|
library_id = library['Id']
|
||||||
|
artists_data = server.get_artists(library_id)
|
||||||
|
artists = artists_data['Items']
|
||||||
|
num_artists = artists_data['TotalRecordCount']
|
||||||
|
albums = server.get_library_items(library_id, 'MusicAlbum')['Items']
|
||||||
|
songs = server.get_library_items(library_id, 'Audio')['Items']
|
||||||
|
|
||||||
self.sync['RestorePoint'] = items['RestorePoint']
|
for index, artist in enumerate(artists):
|
||||||
start_index = items['RestorePoint']['params']['StartIndex']
|
artist_name = artist.get('Name')
|
||||||
|
|
||||||
for index, artist in enumerate(items['Items']):
|
percent = int((float(index) / float(num_artists)) * 100)
|
||||||
|
message = artist_name
|
||||||
|
dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message)
|
||||||
|
|
||||||
percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100)
|
obj.artist(artist, library=library)
|
||||||
message = artist['Name']
|
artist_albums = [ album for album in albums if artist_name in album.get('Artists') ]
|
||||||
dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message)
|
for album in artist_albums:
|
||||||
obj.artist(artist, library=library)
|
obj.album(album)
|
||||||
|
album_id = album.get('Id')
|
||||||
|
album_songs = [ song for song in songs if album_id == song.get('AlbumId') ]
|
||||||
|
for song in album_songs:
|
||||||
|
dialog.update(percent,
|
||||||
|
message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
|
||||||
|
obj.song(song)
|
||||||
|
|
||||||
for albums in server.get_albums_by_artist(artist['Id']):
|
|
||||||
|
|
||||||
for album in albums['Items']:
|
|
||||||
obj.album(album)
|
|
||||||
|
|
||||||
for songs in server.get_items(album['Id'], "Audio"):
|
|
||||||
for song in songs['Items']:
|
|
||||||
|
|
||||||
dialog.update(percent,
|
|
||||||
message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
|
|
||||||
obj.song(song)
|
|
||||||
|
|
||||||
for songs in server.get_songs_by_artist(artist['Id']):
|
|
||||||
for song in songs['Items']:
|
|
||||||
|
|
||||||
dialog.update(percent, message="%s/%s" % (message, song['Name']))
|
|
||||||
obj.song(song)
|
|
||||||
|
|
||||||
|
# for items in server.get_artists(library['Id'], False, self.sync['RestorePoint'].get('params')):
|
||||||
|
#
|
||||||
|
# self.sync['RestorePoint'] = items['RestorePoint']
|
||||||
|
# start_index = items['RestorePoint']['params']['StartIndex']
|
||||||
|
#
|
||||||
|
# for index, artist in enumerate(items['Items']):
|
||||||
|
#
|
||||||
|
# percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100)
|
||||||
|
# message = artist['Name']
|
||||||
|
# dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message)
|
||||||
|
# obj.artist(artist, library=library)
|
||||||
|
#
|
||||||
|
# import web_pdb; web_pdb.set_trace()
|
||||||
|
# for albums in server.get_albums_by_artist(artist['Id']):
|
||||||
|
#
|
||||||
|
# for album in albums['Items']:
|
||||||
|
# obj.album(album)
|
||||||
|
#
|
||||||
|
# for songs in server.get_items(album['Id'], "Audio"):
|
||||||
|
# for song in songs['Items']:
|
||||||
|
#
|
||||||
|
# dialog.update(percent,
|
||||||
|
# message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
|
||||||
|
# obj.song(song)
|
||||||
|
#
|
||||||
|
# for songs in server.get_songs_by_artist(artist['Id']):
|
||||||
|
# for song in songs['Items']:
|
||||||
|
#
|
||||||
|
# dialog.update(percent, message="%s/%s" % (message, song['Name']))
|
||||||
|
# obj.song(song)
|
||||||
|
#
|
||||||
if self.update_library:
|
if self.update_library:
|
||||||
self.music_compare(library, obj, jellyfindb)
|
self.music_compare(library, obj, jellyfindb)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue