Skip to content

Commit

Permalink
Merge pull request #126 from solaluset/suno
Browse files Browse the repository at this point in the history
add Suno support
  • Loading branch information
solaluset authored Mar 25, 2024
2 parents 10c1887 + 4a8e409 commit 39a3b21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion musicbot/linkutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Origins(Enum):


async def get_soup(url: str) -> BeautifulSoup:
async with _session.get(spotify_regex.match(url).group()) as response:
async with _session.get(url) as response:
response.raise_for_status()
page = await response.text()

Expand All @@ -112,6 +112,8 @@ async def get_soup(url: str) -> BeautifulSoup:
async def fetch_spotify(url: str) -> Optional[Union[dict, List[str]]]:
"""Searches YouTube for Spotify song or loads Spotify playlist"""
match = spotify_regex.match(url)
# strip any extra parts
url = match.group()
url_type = match.group("type")
if url_type != "track":
return await fetch_spotify_playlist(url, url_type, match.group("code"))
Expand Down
24 changes: 24 additions & 0 deletions musicbot/yt_dlp_plugins/extractor/suno.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re

from yt_dlp import DownloadError
from yt_dlp.extractor.common import InfoExtractor


class SunoAIIE(InfoExtractor):
_VALID_URL = r"^https?://app\.suno\.ai/song/(?P<code>\w+)"

def _real_extract(self, url):
from musicbot.loader import _loop
from musicbot.linkutils import get_soup

match = re.match(self._VALID_URL, url)
try:
soup = _loop.run_until_complete(get_soup(url))
return {
"id": match.group("code"),
"url": soup.find(property="og:audio")["content"],
"title": re.sub(r" \| Suno$", "", soup.find("title").string),
"thumbnail": soup.find(property="og:image")["content"],
}
except Exception as e:
raise DownloadError(str(e)) from e

0 comments on commit 39a3b21

Please sign in to comment.