From 8bbe81f2dc5b3c04a00a9c48871eb1630c6e9e2c Mon Sep 17 00:00:00 2001 From: Reuben Frankel Date: Mon, 26 Feb 2024 04:10:45 +0000 Subject: [PATCH] Define max tracks for audio features stream --- tap_spotify/streams.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tap_spotify/streams.py b/tap_spotify/streams.py index cfe7586..ff52922 100644 --- a/tap_spotify/streams.py +++ b/tap_spotify/streams.py @@ -69,9 +69,17 @@ class _AudioFeaturesStream(SpotifyStream): path = "/audio-features" records_jsonpath = "$.audio_features[*]" schema = AudioFeaturesObject.schema + max_tracks = 100 def __init__(self, tracks_stream: _TracksStream, track_records: Iterable[dict]): super().__init__(tracks_stream._tap) + + total_tracks = len(track_records) + + if total_tracks > self.max_tracks: + msg = f"Cannot get audio features for more than {self.max_tracks} tracks at a time: {total_tracks} requested" + raise ValueError(msg) + self._track_records = track_records def get_url_params(self, *args, **kwargs):