2023-02-11 17:59:15 +00:00
|
|
|
use flow::Flow;
|
|
|
|
use std::{io::stdin, path::PathBuf, sync::Arc, thread, time::Duration};
|
|
|
|
// use warp::Filter;
|
|
|
|
|
|
|
|
use music_player::{core::Core, database::MemoryIndex};
|
|
|
|
|
|
|
|
/*
|
|
|
|
fn tracks() -> Vec<Track> {
|
|
|
|
vec![
|
|
|
|
Track {
|
|
|
|
track_number: Some(1),
|
|
|
|
name: Some("Underground".to_owned()),
|
|
|
|
album: Some("Artemis".to_owned()),
|
|
|
|
artist: Some("Lindsey Stirling".to_owned()),
|
|
|
|
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/01 - Underground.ogg"),
|
|
|
|
},
|
|
|
|
Track {
|
|
|
|
track_number: Some(2),
|
|
|
|
name: Some("Artemis".to_owned()),
|
|
|
|
album: Some("Artemis".to_owned()),
|
|
|
|
artist: Some("Lindsey Stirling".to_owned()),
|
|
|
|
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/02 - Artemis.ogg"),
|
|
|
|
},
|
|
|
|
Track {
|
|
|
|
track_number: Some(3),
|
|
|
|
name: Some("Til the Light Goes Out".to_owned()),
|
|
|
|
album: Some("Artemis".to_owned()),
|
|
|
|
artist: Some("Lindsey Stirling".to_owned()),
|
|
|
|
path: PathBuf::from(
|
|
|
|
"/mnt/music/Lindsey Stirling/Artemis/03 - Til the Light Goes Out.ogg",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
Track {
|
|
|
|
track_number: Some(4),
|
|
|
|
name: Some("Between Twilight".to_owned()),
|
|
|
|
album: Some("Artemis".to_owned()),
|
|
|
|
artist: Some("Lindsey Stirling".to_owned()),
|
|
|
|
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/04 - Between Twilight.ogg"),
|
|
|
|
},
|
|
|
|
Track {
|
|
|
|
track_number: Some(5),
|
|
|
|
name: Some("Foreverglow".to_owned()),
|
|
|
|
album: Some("Artemis".to_owned()),
|
|
|
|
artist: Some("Lindsey Stirling".to_owned()),
|
|
|
|
path: PathBuf::from("/mnt/music/Lindsey Stirling/Artemis/05 - Foreverglow.ogg"),
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
pub async fn main() {
|
2023-02-17 02:17:23 +00:00
|
|
|
/*
|
2023-02-11 17:59:15 +00:00
|
|
|
match Core::new(Arc::new(MemoryIndex::new())) {
|
|
|
|
Flow::Ok(core) => {
|
|
|
|
let mut buf = String::new();
|
|
|
|
let _ = stdin().read_line(&mut buf).unwrap();
|
|
|
|
core.exit();
|
|
|
|
}
|
|
|
|
Flow::Err(err) => println!("non-fatal error: {:?}", err),
|
|
|
|
Flow::Fatal(err) => println!("fatal error: {:?}", err),
|
|
|
|
}
|
2023-02-17 02:17:23 +00:00
|
|
|
*/
|
2023-02-11 17:59:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
let connection = Connection::new_session().expect("to connect to dbus");
|
|
|
|
|
|
|
|
for player in list_players(connection) {
|
|
|
|
println!("player found: {}", player.identity());
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
let devices = warp::path!("api" / "v1" / "devices")
|
|
|
|
.and(warp::get())
|
|
|
|
.map(|| {
|
|
|
|
let conn = Connection::new_session().expect("to connect to dbus");
|
|
|
|
warp::reply::json(&list_devices(conn))
|
|
|
|
});
|
|
|
|
|
|
|
|
let track_list = warp::path!("api" / "v1" / "tracks")
|
|
|
|
.and(warp::get())
|
|
|
|
.map(|| warp::reply::json(&tracks()));
|
|
|
|
let tracks_for_artist = warp::path!("api" / "v1" / "artist" / String)
|
|
|
|
.and(warp::get())
|
|
|
|
.map(|_artist: String| warp::reply::json(&tracks()));
|
|
|
|
let tracks_for_album = warp::path!("api" / "v1" / "album" / String)
|
|
|
|
.and(warp::get())
|
|
|
|
.map(|_album: String| warp::reply::json(&tracks()));
|
|
|
|
|
|
|
|
let queue = warp::path!("api" / "v1" / "queue")
|
|
|
|
.and(warp::get())
|
|
|
|
.map(|| {
|
|
|
|
let conn = Connection::new_session().expect("to connect to dbus");
|
|
|
|
warp::reply::json(&list_tracks(conn))
|
|
|
|
});
|
|
|
|
|
|
|
|
let playing_status = warp::path!("api" / "v1" / "play-pause")
|
|
|
|
.and(warp::get())
|
|
|
|
.map(|| warp::reply::json(&PlayPause::Paused));
|
|
|
|
|
|
|
|
let routes = devices
|
|
|
|
.or(track_list)
|
|
|
|
.or(tracks_for_album)
|
|
|
|
.or(tracks_for_artist)
|
|
|
|
.or(queue)
|
|
|
|
.or(playing_status);
|
|
|
|
let server = warp::serve(routes);
|
|
|
|
server
|
|
|
|
.run(SocketAddr::new(
|
|
|
|
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
|
|
|
8002,
|
|
|
|
))
|
|
|
|
.await;
|
|
|
|
*/
|
|
|
|
}
|