use std::process;
use rustfm_scrobble::Scrobbler;
mod auth;
mod config;
mod filter;
mod mainloop;
mod player;
mod track;
use config::ConfigError;
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() {
if std::env::args().any(|arg| arg == "-v" || arg == "--version") {
println!("rescrobbled v{}", VERSION);
return;
}
let config = match config::load_config() {
Ok(config) => config,
Err(ConfigError::Created(path)) => {
println!(
"Config file did not exist; created it at {}\n\
Please update it with your Last.fm/ListenBrainz API information.",
path.to_string_lossy()
);
return;
}
Err(err) => {
eprintln!("Error while loading config: {}", err);
process::exit(1);
}
};
let scrobbler = match (&config.lastfm_key, &config.lastfm_secret) {
(Some(key), Some(secret)) => {
let mut scrobbler = Scrobbler::new(key, secret);
match auth::authenticate(&mut scrobbler) {
Ok(_) => println!("Authenticated with Last.fm successfully!"),
Err(err) => {
eprintln!("Failed to authenticate with Last.fm: {}", err);
process::exit(1);
}
}
Some(scrobbler)
}
(None, None) => None,
_ => {
eprintln!("Last.fm API key or API secret are missing");
process::exit(1);
}
};
if scrobbler.is_none() && config.listenbrainz_token.is_none() {
eprintln!("Warning: both Last.fm and ListenBrainz API credentials are missing");
}
mainloop::run(config, scrobbler);
}