fix: Improvements to spotify country-based url filter and playlist support

This commit is contained in:
Marius Begby committed 2023-08-25 22:33:19 +02:00
1 parent 45b00395a7
commit 4d9353d43a
1 file changed
+4 -3
+4 -3
View File
@@ -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);