From 3c59d3e7a2b1b71499b238af4625d7dde61fe203 Mon Sep 17 00:00:00 2001 From: Michael Skyba Date: Mon, 4 Nov 2024 16:22:42 -0500 Subject: [PATCH 1/4] [ie/suno] add /song mp3 extractor --- yt_dlp/extractor/_extractors.py | 1 + yt_dlp/extractor/suno.py | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 yt_dlp/extractor/suno.py diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py index ff5ddb249..5371d38be 100644 --- a/yt_dlp/extractor/_extractors.py +++ b/yt_dlp/extractor/_extractors.py @@ -1983,6 +1983,7 @@ from .stripchat import StripchatIE from .stv import STVPlayerIE from .substack import SubstackIE +from .suno import SunoIE from .sunporno import SunPornoIE from .sverigesradio import ( SverigesRadioEpisodeIE, diff --git a/yt_dlp/extractor/suno.py b/yt_dlp/extractor/suno.py new file mode 100644 index 000000000..3e15ddba6 --- /dev/null +++ b/yt_dlp/extractor/suno.py @@ -0,0 +1,41 @@ +from .common import InfoExtractor + + +class SunoIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?suno\.com/song/(?P[-a-f0-9]+)' + _TESTS = [ + { + 'url': 'https://suno.com/song/ab39a04d-b2e6-463b-9b8e-ddea725422f5', + 'md5': 'ef850763b175d8a3c7fba5e2dbdc6bc5', + 'info_dict': { + 'id': 'ab39a04d-b2e6-463b-9b8e-ddea725422f5', + 'title': 'Life\'s a Soundtrack · AI Funk Factory @ YT by @funk | Suno', + 'description': 'groovy funk, melodic song. Listen and make your own with Suno.', + 'thumbnail': 'https://cdn2.suno.ai/image_903f2bd7-ccc0-4029-a76a-887f07ebc2df.jpeg', + 'ext': 'mp3', + }, + }, + { + 'url': 'https://suno.com/song/9cbcb5f4-f367-4f1c-8a32-23ec62bdc47e', + 'md5': '2f038badef88d189891d5f8cd8d8804d', + 'info_dict': { + 'id': '9cbcb5f4-f367-4f1c-8a32-23ec62bdc47e', + 'title': 'Pequenos Prazeres da Vida by @groovebot | Suno', + 'description': 'pop bossa nova song. Listen and make your own with Suno.', + 'thumbnail': 'https://cdn2.suno.ai/image_9cbcb5f4-f367-4f1c-8a32-23ec62bdc47e.jpeg', + 'ext': 'mp3', + }, + }, + ] + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + return { + 'id': video_id, + 'title': self._og_search_title(webpage), + 'description': self._og_search_description(webpage), + 'thumbnail': self._og_search_thumbnail(webpage), + 'url': self._og_search_property('audio', webpage), + } From 6ec19e942dc96b468c282097f82a98fdbc5f7931 Mon Sep 17 00:00:00 2001 From: Michael Skyba Date: Mon, 4 Nov 2024 22:56:29 -0500 Subject: [PATCH 2/4] [ie/suno] add playlist extractor --- yt_dlp/extractor/_extractors.py | 2 +- yt_dlp/extractor/suno.py | 92 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/yt_dlp/extractor/_extractors.py b/yt_dlp/extractor/_extractors.py index 5371d38be..7a8cbc7b8 100644 --- a/yt_dlp/extractor/_extractors.py +++ b/yt_dlp/extractor/_extractors.py @@ -1983,7 +1983,7 @@ from .stripchat import StripchatIE from .stv import STVPlayerIE from .substack import SubstackIE -from .suno import SunoIE +from .suno import SunoIE, SunoPlaylistIE from .sunporno import SunPornoIE from .sverigesradio import ( SverigesRadioEpisodeIE, diff --git a/yt_dlp/extractor/suno.py b/yt_dlp/extractor/suno.py index 3e15ddba6..b3c751012 100644 --- a/yt_dlp/extractor/suno.py +++ b/yt_dlp/extractor/suno.py @@ -1,4 +1,7 @@ +import re + from .common import InfoExtractor +from ..utils import ExtractorError, unescapeHTML class SunoIE(InfoExtractor): @@ -39,3 +42,92 @@ def _real_extract(self, url): 'thumbnail': self._og_search_thumbnail(webpage), 'url': self._og_search_property('audio', webpage), } + + +class SunoPlaylistIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?suno\.com/playlist/(?P[-a-f0-9]+)' + _TESTS = [ + { + 'url': 'https://suno.com/playlist/01f2ac32-c32e-4d26-b10c-221107c02946', + 'info_dict': { + 'id': '01f2ac32-c32e-4d26-b10c-221107c02946', + 'title': 'Main 0 by @contemplativetranspositions367 | Suno', + 'description': 'Hopefully the test case passed', + 'thumbnail': 'https://cdn2.suno.ai/image_19d6d518-1b87-43b3-90b9-2a476ca5824a.jpeg', + }, + 'playlist': [{ + 'info_dict': { + 'id': '19d6d518-1b87-43b3-90b9-2a476ca5824a', + 'title': 'Ceaseless ', + 'ext': 'mp3', + }, + }], + 'playlist_count': 1, + }, + { + 'url': 'https://www.suno.com/playlist/568eeaab-dfbf-4da6-aa0a-0fb1a32330de', + 'info_dict': { + 'id': '568eeaab-dfbf-4da6-aa0a-0fb1a32330de', + 'title': 'Piano by @kunal | Suno', + 'description': 'Here are some good piano ', + 'thumbnail': 'https://cdn2.suno.ai/image_0ecc0956-3b17-4d4b-8504-55849dd75e22.jpeg', + }, + 'playlist': [ + { + 'info_dict': { + 'id': '0ecc0956-3b17-4d4b-8504-55849dd75e22', + 'title': 'ST', + 'ext': 'mp3', + }, + }, + { + 'info_dict': { + 'id': '3fef7d44-c5a3-4181-9de3-d81542af23ef', + 'title': 'ST', + 'ext': 'mp3', + }, + }, + { + 'info_dict': { + 'id': '15e797fa-06c0-4e11-8cc0-3b2580476039', + 'title': 'ST - 2', + 'ext': 'mp3', + }, + }, + ], + 'playlist_count': 3, + }, + ] + + def _real_extract(self, url): + playlist_id = self._match_id(url) + webpage = self._download_webpage(url, playlist_id) + + # There are s whose href is a song/ID path. The s directly + # within them have the respective song title as their innerHTML. + # Alternatively, this info can be extracted through parsing an escaped + # JSON object inside a