Skip to content

Commit

Permalink
Fix spotify_id lookup (#139)
Browse files Browse the repository at this point in the history
* Fix spotify_id lookup

* fix tests
  • Loading branch information
amCap1712 authored May 28, 2024
1 parent b433c46 commit 53d90f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tests/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def test_submit_to_spotify(self, mock_requests):

# track 2 in playlist doesn't have a mbid and is skipped from request to lookup track ids
self.assertEqual(history[0].json(), [
{"[recording_mbid]": "87dfa566-21c3-45ed-bc42-1d345b8563fa"},
{"[recording_mbid]": "ec0da94e-fbfe-4eb0-968e-024d4c32d1d0"},
{"[recording_mbid]": "93726547-f8c0-4efd-8e16-d2dee76500f6"},
{"[recording_mbid]": "395bd5a1-79cc-4e04-8869-ca9eabc78d09"}
{"recording_mbid": "87dfa566-21c3-45ed-bc42-1d345b8563fa"},
{"recording_mbid": "ec0da94e-fbfe-4eb0-968e-024d4c32d1d0"},
{"recording_mbid": "93726547-f8c0-4efd-8e16-d2dee76500f6"},
{"recording_mbid": "395bd5a1-79cc-4e04-8869-ca9eabc78d09"}
])

self.assertEqual(history[1].json(), {
Expand Down
6 changes: 2 additions & 4 deletions troi/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import troi
from abc import ABC, abstractmethod

from troi.playlist import PlaylistElement
from troi.logging_utils import set_log_level
from troi.recording_search_service import RecordingSearchByTagService, RecordingSearchByArtistService

Expand Down Expand Up @@ -144,14 +145,11 @@ def generate_playlist(self):
* desc: Override the algorithms that generate a playlist description and use this description instead.
* min-recordings: The minimum number of recordings that must be present in a playlist to consider it complete. If it doesn't have sufficient numbers of tracks, ignore the playlist and don't submit it. Default: Off, a playlist with at least one track will be considere complete.
* spotify: if present, attempt to submit the playlist to spotify as well. should be a dict and contain the spotify user id, spotify auth token with appropriate permissions, whether the playlist should be public, private or collaborative. it can also optionally have the existing urls to update playlists instead of creating new ones.
:param args: the arguments to pass to the patch, may contain one of more of the following keys:
"""

try:
set_log_level(self.patch_args.get("quiet", False))
playlist = troi.playlist.PlaylistElement()
playlist = PlaylistElement()
playlist.set_sources(self.pipeline)
logger.info("Troi playlist generation starting...")
result = playlist.generate(self.quiet)
Expand Down
2 changes: 1 addition & 1 deletion troi/tools/spotify_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def lookup_spotify_ids(recordings):
and add those to the recordings. """
response = requests.post(
SPOTIFY_IDS_LOOKUP_URL,
json=[{"[recording_mbid]": recording.mbid} for recording in recordings]
json=[{"recording_mbid": recording.mbid} for recording in recordings]
)
response.raise_for_status()
spotify_data = response.json()
Expand Down

0 comments on commit 53d90f0

Please sign in to comment.