scene: move mixxx playlist importing into the session
This commit is contained in:
+4
-21
@@ -467,28 +467,11 @@ impl App {
|
|||||||
|
|
||||||
fn reload_mixxx_playlist(&mut self) {
|
fn reload_mixxx_playlist(&mut self) {
|
||||||
// TODO: Should have some status message which states how many tracks are in the playlist
|
// TODO: Should have some status message which states how many tracks are in the playlist
|
||||||
self.direction.current_playlist.clear();
|
if let Err(err) = self.direction.reload_mixxx_playlist() {
|
||||||
let connection = sqlite::Connection::open_thread_safe_with_flags("mixxxdb.sqlite", OpenFlags::new().with_read_only()).unwrap();
|
self.next_actions.push(ConversationEntry::SystemMessage(format!("Error while loading mixxx playlist: {:?}", err)));
|
||||||
let query = "SELECT id FROM Playlists WHERE name = ? ORDER BY id DESC LIMIT 1";
|
} else {
|
||||||
let mut statement = connection.prepare(query).unwrap();
|
self.next_actions.push(ConversationEntry::SystemMessage(format!("Mixxx playlist reloaded. {} tracks found.", self.direction.current_playlist.len()).into()));
|
||||||
statement.bind((1, format!("BFF.fm - Episode {}", self.direction.episode_number).as_str())).unwrap();
|
|
||||||
statement.next().unwrap();
|
|
||||||
let latest_id = statement.read::<i64, _>("id").unwrap();
|
|
||||||
|
|
||||||
let query = "SELECT title, artist, album, comment, url, bpm FROM library LEFT JOIN PlaylistTracks ON PlaylistTracks.track_id = library.id WHERE PlaylistTracks.playlist_id = ? ORDER BY position";
|
|
||||||
for track in connection.prepare(query).unwrap().into_iter().bind((1, latest_id)).unwrap().map(|row| row.unwrap()) {
|
|
||||||
let title = track.try_read::<&str, _>("title").unwrap_or("Untitled Track");
|
|
||||||
let artist = track.try_read::<&str, _>("artist").unwrap_or("Unknown Artist");
|
|
||||||
let album = track.try_read::<&str, _>("album").unwrap_or("Unknown Album");
|
|
||||||
let bpm = track.try_read::<f64, _>("bpm").unwrap_or(0.);
|
|
||||||
self.direction.current_playlist.push(PlaylistEntry {
|
|
||||||
artist: artist.into(),
|
|
||||||
album: album.into(),
|
|
||||||
title: title.into(),
|
|
||||||
bpm
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
self.next_actions.push(ConversationEntry::SystemMessage("Mixxx playlist reloaded.".into()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,45 @@ pub struct StageDirection {
|
|||||||
pub current_playlist: Vec<PlaylistEntry>
|
pub current_playlist: Vec<PlaylistEntry>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MixxxError {
|
||||||
|
Sql(sqlite::Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<sqlite::Error> for MixxxError {
|
||||||
|
fn from(value: sqlite::Error) -> Self {
|
||||||
|
Self::Sql(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StageDirection {
|
||||||
|
pub fn reload_mixxx_playlist(&mut self) -> Result<(), MixxxError> {
|
||||||
|
self.current_playlist.clear();
|
||||||
|
let connection = sqlite::Connection::open_thread_safe_with_flags("mixxxdb.sqlite", OpenFlags::new().with_read_only())?;
|
||||||
|
let query = "SELECT id FROM Playlists WHERE name = ? ORDER BY id DESC LIMIT 1";
|
||||||
|
let mut statement = connection.prepare(query)?;
|
||||||
|
statement.bind((1, format!("BFF.fm - Episode {}", self.episode_number).as_str()))?;
|
||||||
|
statement.next()?;
|
||||||
|
let latest_id = statement.read::<i64, _>("id").unwrap();
|
||||||
|
|
||||||
|
let query = "SELECT title, artist, album, comment, url, bpm FROM library LEFT JOIN PlaylistTracks ON PlaylistTracks.track_id = library.id WHERE PlaylistTracks.playlist_id = ? ORDER BY position";
|
||||||
|
for track in connection.prepare(query).unwrap().into_iter().bind((1, latest_id)).unwrap().map(|row| row.unwrap()) {
|
||||||
|
let title = track.try_read::<&str, _>("title").unwrap_or("Untitled Track");
|
||||||
|
let artist = track.try_read::<&str, _>("artist").unwrap_or("Unknown Artist");
|
||||||
|
let album = track.try_read::<&str, _>("album").unwrap_or("Unknown Album");
|
||||||
|
let bpm = track.try_read::<f64, _>("bpm").unwrap_or(0.);
|
||||||
|
self.current_playlist.push(PlaylistEntry {
|
||||||
|
artist: artist.into(),
|
||||||
|
album: album.into(),
|
||||||
|
title: title.into(),
|
||||||
|
bpm
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct StageActions {
|
pub struct StageActions {
|
||||||
pub direction: StageDirection,
|
pub direction: StageDirection,
|
||||||
|
|||||||
Reference in New Issue
Block a user