Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playlist, artist and album download from web app. #1865

Merged
merged 7 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spotdl/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Version module for spotdl.
"""

__version__ = "4.2.0"
__version__ = "4.2.1"
43 changes: 43 additions & 0 deletions spotdl/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
WebOptions,
)
from spotdl.types.song import Song
from spotdl.types.playlist import Playlist
from spotdl.types.album import Album
from spotdl.types.artist import Artist
from spotdl.utils.arguments import create_parser
from spotdl.utils.config import (
DOWNLOADER_OPTIONS,
Expand Down Expand Up @@ -280,6 +283,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: str):
await app_state.server.shutdown()


# Deprecated
@router.get("/api/song/url", response_model=None)
def song_from_url(url: str) -> Song:
"""
Expand All @@ -295,6 +299,45 @@ def song_from_url(url: str) -> Song:
return Song.from_url(url)


@router.get("/api/url", response_model=None)
def songs_from_url(url: str) -> List[Song]:
"""
Search for a song, playlist, artist or album on spotify using url.

### Arguments
- url: The url to search.

### Returns
- returns a list with Song objects to be downloaded.
"""

if "playlist" in url:
playlist = Playlist.from_url(url)
return list(map(Song.from_url, playlist.urls))
if "album" in url:
album = Album.from_url(url)
return list(map(Song.from_url, album.urls))
if "artist" in url:
artist = Artist.from_url(url)
return list(map(Song.from_url, artist.urls))

return [Song.from_url(url)]


@router.get("/api/version", response_model=None)
def version() -> str:
"""
Get the current version
This method is created to ensure backward compatibility of the web app,
as the web app is updated with the latest regardless of the backend version

### Returns
- returns the version of the app
"""

return __version__


@router.on_event("shutdown")
async def shutdown_event():
"""
Expand Down