Loop randomly over songs when building playlist
This commit is contained in:
parent
21d435239e
commit
220c68f38b
@ -116,7 +116,7 @@ def main(queue_length):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
mpd_port = 6600
|
mpd_port = 6600
|
||||||
|
|
||||||
# Connect to MPD²
|
# Connect to MPD
|
||||||
client = PersistentMPDClient(host=mpd_host, port=mpd_port)
|
client = PersistentMPDClient(host=mpd_host, port=mpd_port)
|
||||||
if mpd_password is not None:
|
if mpd_password is not None:
|
||||||
client.password(mpd_password)
|
client.password(mpd_password)
|
||||||
@ -149,7 +149,7 @@ def main(queue_length):
|
|||||||
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs WHERE filename=?", (current_song,))
|
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs WHERE filename=?", (current_song,))
|
||||||
current_song_coords = cur.fetchone()
|
current_song_coords = cur.fetchone()
|
||||||
if current_song_coords is None:
|
if current_song_coords is None:
|
||||||
logging.warning("Current song %s is not in db. You should update the db." %
|
logging.error("Current song %s is not in db. You should update the db." %
|
||||||
(current_song,))
|
(current_song,))
|
||||||
client.close()
|
client.close()
|
||||||
client.disconnect()
|
client.disconnect()
|
||||||
@ -179,11 +179,11 @@ def main(queue_length):
|
|||||||
current_song_coords = cached_distances[0]
|
current_song_coords = cached_distances[0]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get all other songs coordinates
|
# Get all other songs coordinates and iterate randomly on them
|
||||||
# TODO: Don't rebuild entire cache if cache is already built
|
|
||||||
closest_song = None
|
closest_song = None
|
||||||
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs")
|
cur.execute("SELECT id, tempo1, tempo2, tempo3, amplitude, frequency, attack, filename FROM songs")
|
||||||
for tmp_song_data in cur.fetchall():
|
songs = random.shuffle([song for song in cur.fetchall()])
|
||||||
|
for tmp_song_data in songs:
|
||||||
if(tmp_song_data["filename"] == current_song_coords["filename"] or
|
if(tmp_song_data["filename"] == current_song_coords["filename"] or
|
||||||
tmp_song_data["filename"] in cached_distances_songs or
|
tmp_song_data["filename"] in cached_distances_songs or
|
||||||
("file: %s" % (tmp_song_data["filename"],)) in client.playlist()):
|
("file: %s" % (tmp_song_data["filename"],)) in client.playlist()):
|
||||||
@ -239,7 +239,6 @@ def main(queue_length):
|
|||||||
conn.rollback()
|
conn.rollback()
|
||||||
|
|
||||||
# Update the closest song
|
# Update the closest song
|
||||||
# TODO: Find a better heuristic?
|
|
||||||
if closest_song is None or distance < closest_song[1]:
|
if closest_song is None or distance < closest_song[1]:
|
||||||
closest_song = (tmp_song_data, distance, similarity)
|
closest_song = (tmp_song_data, distance, similarity)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user