def get_tracks(self, track_ids): def track_fetcher(track_ids): return self._fetch_by_track_ids( track_ids, lambda track_ids: self.client.tracks(track_ids)["tracks"]) tracks = self._fetch_in_batches(track_ids, track_fetcher) return [Track.from_spotify_track(track) for _, track in tracks]
def get_recommendations_based_on_tracks(self, track_ids, song_attribute_ranges): """ Params: tracks_ids ([str]): max length is 5. song_attribute_ranges (SongAttributeRanges). Returns: ([Track]). """ if len(track_ids) > RECOMMENDATION_SEED_LIMIT: track_ids = track_ids[:RECOMMENDATION_SEED_LIMIT] results = self.client.recommendations( seed_tracks=track_ids, limit=RECOMMENDATIONS_LIMIT, min_danceability=song_attribute_ranges.danceability_range[0], max_danceability=song_attribute_ranges.danceability_range[1], min_energy=song_attribute_ranges.energy_range[0], max_energy=song_attribute_ranges.energy_range[1], min_loudness=song_attribute_ranges.loudness_range[0], max_loudness=song_attribute_ranges.loudness_range[1], min_speechiness=song_attribute_ranges.speechiness_range[0], max_speechiness=song_attribute_ranges.speechiness_range[1], min_acousticness=song_attribute_ranges.acousticness_range[0], max_acousticness=song_attribute_ranges.acousticness_range[1], min_instrumentalness=song_attribute_ranges. instrumentalness_range[0], max_instrumentalness=song_attribute_ranges. instrumentalness_range[1], min_liveness=song_attribute_ranges.liveness_range[0], max_liveness=song_attribute_ranges.liveness_range[1], min_valence=song_attribute_ranges.valence_range[0], max_valence=song_attribute_ranges.valence_range[1], min_tempo=int(song_attribute_ranges.tempo_range[0]), max_tempo=int(song_attribute_ranges.tempo_range[1]), min_duration_ms=int(song_attribute_ranges.duration_ms_range[0]), max_duration_ms=int(song_attribute_ranges.duration_ms_range[1]), min_popularity=song_attribute_ranges.popularity_range[0], max_popularity=song_attribute_ranges.popularity_range[1], ) return [Track.from_spotify_track(track) for track in results['tracks']]