mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
fix: Improvements to spotify country-based url filter and playlist support
This commit is contained in:
1 parent
45b00395a7
commit
4d9353d43a
1 file changed
+4
-3
@@ -5,15 +5,16 @@ exports.transformQuery = async (query) => {
|
||||
try {
|
||||
// regex to check for country-based Spotify url
|
||||
const regex = new RegExp(
|
||||
'https://open.spotify.com/((?:[a-z]{2,4}-[a-z]{2,4}/)|(?:[a-z]{2,4}/))?track/([a-zA-Z0-9]+)'
|
||||
'https://open.spotify.com/((?:[a-z]{2,4}-[a-z]{2,4}/)|(?:[a-z]{2,4}/))(track|playlist)/([a-zA-Z0-9]+)'
|
||||
);
|
||||
const isCountryBased = regex.test(query);
|
||||
|
||||
// if country-based, transform to normal Spotify url
|
||||
if (isCountryBased) {
|
||||
logger.debug(`Transforming country-based Spotify url to normal Spotify url from query ${query}.`);
|
||||
const trackId = query.match(regex)[2];
|
||||
query = `https://open.spotify.com/track/${trackId}`;
|
||||
const type = query.match(regex)[2];
|
||||
const trackId = query.match(regex)[3];
|
||||
query = `https://open.spotify.com/${type}/${trackId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
|
||||
Reference in new issue
Block a user