-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parse Spotify playlist ids from playlists with a share id query …
…parameter correctly (#76) * fix: parse id from URLs with tracking(?) query parameter Such as [https://open.spotify.com/playlist/37i9dQZF1DX5KpP2LN299J?si=asdf](open.spotify.com/playlist/37i9dQZF1DX5KpP2LN299J?si=asdf) * refactor: make this a classmethod * chore: add tests * refactor: don't cache regex
- Loading branch information
1 parent
6a502ef
commit 42690d8
Showing
2 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
|
||
from spotify_to_ytmusic.spotify import extract_playlist_id_from_url | ||
|
||
|
||
class TestParsing(unittest.TestCase): | ||
def test_idFromSpotifyUrl(self): | ||
url = "https://open.spotify.com/playlist/37i9dQZF1DX5KpP2LN299J" | ||
self.assertEqual(extract_playlist_id_from_url(url), "37i9dQZF1DX5KpP2LN299J") | ||
|
||
def test_idFromSpotifyUrlWithShareId(self): | ||
url = "http://open.spotify.com/playlist/37i9dQZF1DZ06evO3siF1W?si=grips" | ||
self.assertEqual(extract_playlist_id_from_url(url), "37i9dQZF1DZ06evO3siF1W") | ||
|
||
def test_idFromSpotifyUrlRejectBadId(self): | ||
url = "https://open.spotify.com/playlist/420" | ||
self.assertRaisesRegex(ValueError, r"Bad playlist id", extract_playlist_id_from_url, url) | ||
|
||
def test_idFromSpotifyUrlRejectBadUrl(self): | ||
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" | ||
self.assertRaises(ValueError, extract_playlist_id_from_url, url) |