-
Spotify Playlist Archive
+
+
+
+ Spotify Playlist Archive
+
+
diff --git a/src/utils/getPlaylistIdFromUrl.ts b/src/utils/getPlaylistIdFromUrl.ts
new file mode 100644
index 0000000..bbdd9f9
--- /dev/null
+++ b/src/utils/getPlaylistIdFromUrl.ts
@@ -0,0 +1,15 @@
+export const getPlaylistIdFromUrl = (url: string) => {
+ const urlObject = new URL(url);
+ const [collectionName, playlistId] = urlObject.pathname
+ .split('/')
+ .filter(Boolean);
+
+ const isValidPlaylistUrl =
+ urlObject.hostname === 'open.spotify.com' &&
+ collectionName === 'playlist' &&
+ playlistId;
+
+ if (!isValidPlaylistUrl) throw new Error('Invalid playlist URL');
+
+ return playlistId;
+};