Moved the db
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -7,11 +7,23 @@ mod tui;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use rand::distr::weighted::WeightedIndex;
|
||||
use rand::prelude::*;
|
||||
|
||||
fn db_path() -> PathBuf {
|
||||
let data_dir = env::var("XDG_DATA_HOME")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|_| {
|
||||
let home = env::var("HOME").expect("HOME not set");
|
||||
PathBuf::from(home).join(".local/share")
|
||||
});
|
||||
let dir = data_dir.join("playlists");
|
||||
std::fs::create_dir_all(&dir).expect("failed to create data directory");
|
||||
dir.join("playlists.db")
|
||||
}
|
||||
|
||||
fn usage(program: &str) -> ! {
|
||||
eprintln!("Usage:");
|
||||
eprintln!(" {program} index [-v] <directory>");
|
||||
@@ -50,7 +62,7 @@ fn cmd_index(args: &[String]) {
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let conn = db::open("playlists.db").expect("failed to open database");
|
||||
let conn = db::open(&db_path()).expect("failed to open database");
|
||||
let lastfm = lastfm::LastfmClient::new(api_key);
|
||||
let dir = Path::new(rest[0].as_str());
|
||||
|
||||
@@ -166,7 +178,7 @@ fn cmd_build(args: &[String]) {
|
||||
}
|
||||
|
||||
dotenvy::dotenv().ok();
|
||||
let conn = db::open("playlists.db").expect("failed to open database");
|
||||
let conn = db::open(&db_path()).expect("failed to open database");
|
||||
|
||||
let (artist_mbid, seed_name) = if let Some(file_arg) = rest.first() {
|
||||
let path = Path::new(file_arg.as_str());
|
||||
|
||||
Reference in New Issue
Block a user