Skip to content

Commit

Permalink
Merge pull request #62 from Krutyi-4el/fix-spotify
Browse files Browse the repository at this point in the history
add support for new Spotify album links
  • Loading branch information
solaluset authored Jul 7, 2023
2 parents ce35b0a + c5b86ff commit dafc86a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions musicbot/linkutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)+""",
re.VERBOSE,
)
album_regex = re.compile(r"^https://open\.spotify\.com/([^/]+/)?album")

headers = {
"User-Agent": " ".join(
Expand Down Expand Up @@ -68,7 +69,7 @@ async def get_spotify_playlist(url: str) -> list:
if api:
results = None
try:
if "open.spotify.com/album" in url:
if is_sp_album(url):
results = sp_api.album_tracks(code)

if "open.spotify.com/playlist" in url:
Expand Down Expand Up @@ -120,6 +121,10 @@ def get_urls(content: str) -> List[str]:
return url_regex.findall(content)


def is_sp_album(url: str) -> bool:
return bool(album_regex.match(url))


class Sites(Enum):
Spotify = "Spotify"
Spotify_Playlist = "Spotify Playlist"
Expand Down Expand Up @@ -153,10 +158,7 @@ def identify_url(url: Optional[str]) -> Sites:
if re.match(r"^https://open\.spotify\.com/([^/]+/)?track", url):
return Sites.Spotify

if (
"https://open.spotify.com/playlist" in url
or "https://open.spotify.com/album" in url
):
if "https://open.spotify.com/playlist" in url or is_sp_album(url):
return Sites.Spotify_Playlist

if "bandcamp.com/track/" in url:
Expand All @@ -182,10 +184,7 @@ def identify_playlist(url: Optional[str]) -> Union[Sites, Playlist_Types]:
if "playlist?list=" in url:
return Playlist_Types.YouTube_Playlist

if (
"https://open.spotify.com/playlist" in url
or "https://open.spotify.com/album" in url
):
if "https://open.spotify.com/playlist" in url or is_sp_album(url):
return Playlist_Types.Spotify_Playlist

if "bandcamp.com/album/" in url:
Expand Down

0 comments on commit dafc86a

Please sign in to comment.