Skip to content

Commit

Permalink
All user saved albums (#1945)
Browse files Browse the repository at this point in the history
Co-authored-by: kuba <xnetcat.dev@gmail.com>
  • Loading branch information
edy252 and xnetcat authored Oct 30, 2023
1 parent 912adc9 commit ab5ef17
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
11 changes: 10 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
spotdl download all-user-playlists --user-auth
```

??? info "All user saved albums"
To download all user saved albums run
> `--user-auth` is required

```bash
spotdl download all-user-saved-albums --user-auth
```

You can queue up multiple download tasks by separating the arguments with spaces

```bash
Expand Down Expand Up @@ -353,7 +361,8 @@ Main options:
(ie. 'album:the album name' you can mix these options to get more accurate results).
To download liked songs use 'saved' as the query, to download all user playlists
use 'all-user-playlists, to download all songs from all followed artists use 'all-user-followed-artists'
use 'all-user-playlists, to download all songs from all followed artists use 'all-user-followed-artists',
to download all user saved albums use 'all-user-saved-albums'
For manual audio matching, you can use the format 'YouTubeURL|SpotifyURL'
You can only use album/playlist/tracks urls when downloading/matching youtube urls.
Expand Down
3 changes: 2 additions & 1 deletion spotdl/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def parse_main_options(parser: _ArgumentGroup):
".\n\n"
"To download liked songs use 'saved' as the query, to download all user playlists\n"
"use 'all-user-playlists, to download all songs from all followed artists "
"use 'all-user-followed-artists' \n\n"
"use 'all-user-followed-artists', to download all user saved albums "
"use 'all-user-saved-albums' \n\n"
"For manual audio matching, you can use the format 'YouTubeURL|SpotifyURL'\n"
"You can only use album/playlist/tracks urls when "
"downloading/matching youtube urls.\n"
Expand Down
36 changes: 36 additions & 0 deletions spotdl/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"create_ytm_album",
"create_ytm_playlist",
"get_all_user_playlists",
"get_user_saved_albums",
]

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -262,6 +263,8 @@ def get_simple_songs(
lists.extend(get_all_user_playlists())
elif request == "all-user-followed-artists":
lists.extend(get_user_followed_artists())
elif request == "all-user-saved-albums":
lists.extend(get_user_saved_albums())
elif request.endswith(".spotdl"):
with open(request, "r", encoding="utf-8") as save_file:
for track in json.load(save_file):
Expand Down Expand Up @@ -374,6 +377,39 @@ def get_all_user_playlists(user_url: str = "") -> List[Playlist]:
]


def get_user_saved_albums() -> List[Album]:
"""
Get all user saved albums
### Returns
- List of all user saved albums
"""

spotify_client = SpotifyClient()
if spotify_client.user_auth is False: # type: ignore
raise SpotifyError("You must be logged in to use this function")

user_saved_albums_response = spotify_client.current_user_saved_albums()
if user_saved_albums_response is None:
raise SpotifyError("Couldn't get user saved albums")

user_saved_albums = user_saved_albums_response["items"]

# Fetch all saved tracks
while user_saved_albums_response and user_saved_albums_response["next"]:
response = spotify_client.next(user_saved_albums_response)
if response is None:
break

user_saved_albums_response = response
user_saved_albums.extend(user_saved_albums_response["items"])

return [
Album.from_url(item["album"]["external_urls"]["spotify"], fetch_songs=False)
for item in user_saved_albums
]


def get_user_followed_artists() -> List[Artist]:
"""
Get all user playlists
Expand Down

0 comments on commit ab5ef17

Please sign in to comment.