From 78ba963e35453409e6a02c53438d8fc433a96a02 Mon Sep 17 00:00:00 2001 From: Aaron Abebe Date: Wed, 28 Feb 2024 11:21:27 +0100 Subject: [PATCH] fix: add_tracks should return a list of tracks (#19) --- docs/usage/library.md | 8 +++++--- src/nendo/library/sqlalchemy_library.py | 7 +++---- src/nendo/schema/plugin.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/usage/library.md b/docs/usage/library.md index 9ed9b21..7bd91f9 100644 --- a/docs/usage/library.md +++ b/docs/usage/library.md @@ -82,11 +82,13 @@ The first step in most AI audio workflows is to import existing assets for analy !!! example ```pycon - >>> new_collection = nendo.library.add_tracks("/path/to/my/files/") - >>> type(new_collection) - + >>> added_tracks = nendo.library.add_tracks("/path/to/my/files/") + >>> type(added_tracks) + >>> len(new_collection) 32 + >>> type(added_tracks[0]) + ``` === "Creating a collection" diff --git a/src/nendo/library/sqlalchemy_library.py b/src/nendo/library/sqlalchemy_library.py index 89477e0..43a7219 100644 --- a/src/nendo/library/sqlalchemy_library.py +++ b/src/nendo/library/sqlalchemy_library.py @@ -1022,7 +1022,7 @@ def add_tracks( user_id: Optional[Union[str, uuid.UUID]] = None, copy_to_library: Optional[bool] = None, skip_duplicate: bool = True, - ) -> schema.NendoCollection: + ) -> List[schema.NendoTrack]: """Scan the provided path and upsert the information into the library. Args: @@ -1030,7 +1030,7 @@ def add_tracks( track_type (str, optional): Track type for the new tracks user_id (UUID, optional): The ID of the user adding the track. copy_to_library (bool): Copy and convert the data into the nendo Library? - skip_duplicate (bool): Skip adding duplicates? + skip_duplicate (bool): Skip adding duplicates. Returns: tracks (list[NendoTrack]): The tracks that were added to the Library @@ -1047,14 +1047,13 @@ def add_tracks( if AudioFileUtils().is_supported_filetype(file) ], ) - tracks = self._add_tracks_db( + return self._add_tracks_db( file_paths=file_list, track_type=track_type, copy_to_library=copy_to_library, skip_duplicate=skip_duplicate, user_id=user_id, ) - return self.add_collection(name=path, track_ids=[t.id for t in tracks]) def add_track_relationship( self, diff --git a/src/nendo/schema/plugin.py b/src/nendo/schema/plugin.py index 9ec742d..fca3afb 100644 --- a/src/nendo/schema/plugin.py +++ b/src/nendo/schema/plugin.py @@ -1280,7 +1280,7 @@ def add_tracks( user_id: Optional[Union[str, uuid.UUID]] = None, copy_to_library: Optional[bool] = None, skip_duplicate: bool = True, - ) -> NendoCollection: + ) -> List[NendoTrack]: """Scan the provided path and upsert the information into the library. Args: @@ -1295,7 +1295,7 @@ def add_tracks( file checksum. Defaults to None. Returns: - collection (NendoCollection): The collection of tracks that were added to the Library + List[NendoTrack]: List of tracks that were added to the library. """ raise NotImplementedError