move podcasts to within nested podcasts folder (significant breaking change)

This commit is contained in:
Aaron Manning
2025-08-29 21:46:22 +10:00
parent cb47ff0cb8
commit 07b43ba2dc
6 changed files with 65 additions and 51 deletions

View File

@@ -7,8 +7,10 @@ use std::collections::{HashMap, BTreeMap, HashSet};
use anyhow::Context;
use sanitise_file_name::sanitise;
use crate::folders;
use crate::rss;
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
pub(crate) struct Specification<'a> {
files: HashMap<Cow<'a, str>, Cow<'a, path::Path>>,
@@ -98,10 +100,10 @@ pub(crate) fn update_podcast(
) -> anyhow::Result<()> {
// Create output directory
let output = root.join(sanitise(&alias));
let output = folders::podcast_folder(root, alias);
if !output.exists() {
fs::create_dir(&output)
.with_context(|| format!("failed to create output directory for podcast {}", alias))?;
fs::create_dir_all(&output)
.context(format!("failed to create output directory for podcast {}", alias))?;
}
println!(r#"[info] scanning feed for "{}""#, alias);
@@ -115,7 +117,7 @@ pub(crate) fn update_podcast(
.with_header("User-Agent", "podcast-downloader")
.with_header("Accept", "*/*")
.send()
.with_context(|| format!(r#"error when requesting feed url "{}" for {}"#, feed_url, alias))?;
.context(format!(r#"error when requesting feed url "{}" for {}"#, feed_url, alias))?;
if response.status_code != 200 {
eprintln!(r#"[error] feed "{}" for alias {} responded with non-200 ({}) status code"#, feed_url, alias, response.status_code);

12
src/folders.rs Normal file
View File

@@ -0,0 +1,12 @@
use std::path;
use sanitise_file_name::sanitise;
pub(crate) const PODCASTS_DIR: &str = "Podcasts";
pub(crate) fn podcast_folder(
root: &path::Path,
alias: &str,
) -> path::PathBuf {
root.join(PODCASTS_DIR).join(sanitise(alias))
}

View File

@@ -1,6 +1,7 @@
mod rss;
mod input;
mod tagging;
mod folders;
mod download;
use input::{Command, ListenStatus};
@@ -8,7 +9,6 @@ use input::{Command, ListenStatus};
use std::fs;
use anyhow::Context;
use sanitise_file_name::sanitise;
fn main() -> anyhow::Result<()> {
@@ -48,7 +48,7 @@ fn main() -> anyhow::Result<()> {
}
},
Command::List { status, podcast } => {
let output = root.join(sanitise(&podcast));
let output = folders::podcast_folder(root, &podcast);
let spec_file = output.join("spec.toml");
let spec = download::Specification::read_from(&spec_file)?;
@@ -64,7 +64,7 @@ fn main() -> anyhow::Result<()> {
}
},
Command::Mark { status, podcast } => {
let output = root.join(sanitise(&podcast));
let output = folders::podcast_folder(root, &podcast);
let spec_file = output.join("spec.toml");
let mut spec = download::Specification::read_from(&spec_file)?;

View File

@@ -1,6 +1,6 @@
use std::{fs, path};
use crate::download;
use crate::{folders, download};
use anyhow::Context;
@@ -10,7 +10,7 @@ pub(crate) fn generate_m3u(
alias: &str,
root: &path::Path,
) -> anyhow::Result<()> {
let output = root.join(sanitise(&alias));
let output = folders::podcast_folder(root, alias);
let spec_file = output.join("spec.toml");
let spec = download::Specification::read_from(&spec_file)?;
@@ -54,7 +54,7 @@ pub(crate) fn strip_tags(
alias: &str,
root: &path::Path,
) -> anyhow::Result<()> {
let output = root.join(sanitise(&alias));
let output = folders::podcast_folder(root, alias);
let spec_file = output.join("spec.toml");
let spec = download::Specification::read_from(&spec_file)?;