mirror of
https://github.com/talwat/lowfi
synced 2025-08-14 13:32:37 +00:00
chore: migrate to rodio v0.21.1 feat: add a currently nonfunctional source argument to the scrape command well, this is an important commit for anyone who has some interest in the workings of lowfi, so strap in. rodio finally updated cpal, so that ugly unsafe bit of code to implement send is no longer necessary since cpal did it themselves (a year ago) they also removed output stream handles and some other things which nobody really used anyway. next, the other file types is literally not even code, just adding a feature flag which enables the default rodio feature flags. i do feel a bit silly for thinking it'd be super difficult, so thanks rodio. lastly, the source flag is for a possible switch to the chillhop tracklist. anything embedded into lowfi should be generated with an open source script, hence if lowfi does switch to chillhop, it'll need to be selectable.
112 lines
2.7 KiB
Rust
112 lines
2.7 KiB
Rust
//! An extremely simple lofi player.
|
|
|
|
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use clap::{Parser, Subcommand};
|
|
use eyre::OptionExt;
|
|
|
|
mod messages;
|
|
mod play;
|
|
mod player;
|
|
mod tracks;
|
|
|
|
#[allow(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)]
|
|
mod scrapers;
|
|
|
|
/// An extremely simple lofi player.
|
|
#[derive(Parser, Clone)]
|
|
#[command(about, version)]
|
|
#[allow(clippy::struct_excessive_bools)]
|
|
struct Args {
|
|
/// Use an alternate terminal screen.
|
|
#[clap(long, short)]
|
|
alternate: bool,
|
|
|
|
/// Hide the bottom control bar.
|
|
#[clap(long, short)]
|
|
minimalist: bool,
|
|
|
|
/// Exclude borders in UI.
|
|
#[clap(long, short)]
|
|
borderless: bool,
|
|
|
|
/// Start lowfi paused.
|
|
#[clap(long, short)]
|
|
paused: bool,
|
|
|
|
/// FPS of the UI.
|
|
#[clap(long, short, default_value_t = 12)]
|
|
fps: u8,
|
|
|
|
/// Include ALSA & other logs.
|
|
#[clap(long, short)]
|
|
debug: bool,
|
|
|
|
/// Width of the player, from 0 to 32.
|
|
#[clap(long, short, default_value_t = 3)]
|
|
width: usize,
|
|
|
|
/// Use a custom track list
|
|
#[clap(long, short, alias = "list", short_alias = 'l')]
|
|
track_list: Option<String>,
|
|
|
|
/// Internal song buffer size.
|
|
#[clap(long, short = 's', alias = "buffer", default_value_t = 5)]
|
|
buffer_size: usize,
|
|
|
|
/// The command that was ran.
|
|
/// This is [None] if no command was specified.
|
|
#[command(subcommand)]
|
|
command: Option<Commands>,
|
|
}
|
|
|
|
/// Defines all of the extra commands lowfi can run.
|
|
#[derive(Subcommand, Clone)]
|
|
enum Commands {
|
|
/// Scrapes a music source for files.
|
|
Scrape {
|
|
// The source to scrape from.
|
|
source: scrapers::Sources,
|
|
|
|
/// The file extension to search for, defaults to mp3.
|
|
#[clap(long, short, default_value = "mp3")]
|
|
extension: String,
|
|
|
|
/// Whether to include the full HTTP URL or just the distinguishing part.
|
|
#[clap(long, short)]
|
|
include_full: bool,
|
|
},
|
|
}
|
|
|
|
/// Gets lowfi's data directory.
|
|
pub fn data_dir() -> eyre::Result<PathBuf> {
|
|
let dir = dirs::data_dir()
|
|
.ok_or_eyre("data directory not found, are you *really* running this on wasm?")?
|
|
.join("lowfi");
|
|
|
|
Ok(dir)
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> eyre::Result<()> {
|
|
#[cfg(target_os = "android")]
|
|
compile_error!("Android Audio API not supported due to threading shenanigans");
|
|
|
|
let cli = Args::parse();
|
|
|
|
if let Some(command) = cli.command {
|
|
match command {
|
|
// TODO: Actually distinguish between sources.
|
|
Commands::Scrape {
|
|
source,
|
|
extension,
|
|
include_full,
|
|
} => scrapers::lofigirl::scrape(extension, include_full).await,
|
|
}
|
|
} else {
|
|
play::play(cli).await
|
|
}
|
|
}
|