#[allow(unused_imports)]
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde;
mod actions;
mod command;
mod download;
mod executor;
mod parser;
mod playback;
mod structs;
mod utils;
use self::structs::*;
use anyhow::Result;
use command::*;
use futures::future;
use std::io::Write;
use std::thread;
use async_compat::Compat;
const VERSION: &str = "0.18.0";
fn main() -> Result<()> {
let num_threads = num_cpus::get().max(1);
for _ in 0..num_threads {
thread::spawn(|| smol::spawn(future::pending::<()>()));
}
smol::block_on(Compat::new(async {
utils::create_directories()?;
let app = parser::get_app(&VERSION);
let matches = app.clone().get_matches();
let is_quiet = matches.occurrences_of("quiet") != 0;
let config = Config::load()?.unwrap_or_default();
if !config.quiet.unwrap_or(false) && !is_quiet {
let path = utils::get_podcast_dir()?;
writeln!(std::io::stdout().lock(), "Using PODCAST dir: {:?}", &path).ok();
}
let state = State::new(VERSION, config).await?;
let command = parse_command(state, app, matches);
let new_state = run_command(command).await?;
let public_state: PublicState = new_state.into();
public_state.save()?;
Ok(())
}))
}