reducing memory footprint for running playlists

This commit is contained in:
andy 2021-06-05 09:52:31 +01:00
parent ebc9a0cfa1
commit a33d91dba4
2 changed files with 6 additions and 6 deletions

View File

@ -80,7 +80,7 @@ def run_user_playlist(user: User, playlist: Playlist, spotnet: SpotNetwork = Non
raise NameError(f'No Spotify network returned ({username} / {playlist_name})') raise NameError(f'No Spotify network returned ({username} / {playlist_name})')
try: try:
user_playlists = spotnet.playlists() user_playlists = [(i.name, i.uri) for i in spotnet.playlists()]
except SpotifyNetworkException as e: except SpotifyNetworkException as e:
logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}') logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}')
raise e raise e
@ -102,16 +102,16 @@ def run_user_playlist(user: User, playlist: Playlist, spotnet: SpotNetwork = Non
log_name = uri log_name = uri
except ValueError: # is a playlist name except ValueError: # is a playlist name
part_playlist = next((i for i in user_playlists if i.name == part_name), None) part_playlist = next((i for i in user_playlists if i[0] == part_name), None)
if part_playlist is None: if part_playlist is None:
logger.warning(f'playlist {part_name} not found {username} / {playlist_name}') logger.warning(f'playlist {part_name} not found {username} / {playlist_name}')
continue continue
uri = part_playlist.uri uri = part_playlist[1]
log_name = part_playlist.name log_name = part_playlist[0]
try: try:
_tracks = spotnet.playlist_tracks(uri=uri) _tracks = spotnet.playlist_tracks(uri=uri, reduced_mem=True)
if _tracks and len(_tracks) > 0: if _tracks and len(_tracks) > 0:
playlist_tracks += _tracks playlist_tracks += _tracks
else: else:

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "music" name = "music"
version = "1.0.0" version = "1.0.1"
description = "Spotify smart playlist generator. Last.fm integration for listening statistics" description = "Spotify smart playlist generator. Last.fm integration for listening statistics"
authors = ["andy <andy@sarsoo.xyz>"] authors = ["andy <andy@sarsoo.xyz>"]
readme = "README.md" readme = "README.md"