move podcasts to within nested podcasts folder (significant breaking change)
This commit is contained in:
@@ -7,8 +7,10 @@ use std::collections::{HashMap, BTreeMap, HashSet};
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use sanitise_file_name::sanitise;
|
use sanitise_file_name::sanitise;
|
||||||
|
|
||||||
|
use crate::folders;
|
||||||
use crate::rss;
|
use crate::rss;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||||
pub(crate) struct Specification<'a> {
|
pub(crate) struct Specification<'a> {
|
||||||
files: HashMap<Cow<'a, str>, Cow<'a, path::Path>>,
|
files: HashMap<Cow<'a, str>, Cow<'a, path::Path>>,
|
||||||
@@ -98,10 +100,10 @@ pub(crate) fn update_podcast(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
|
||||||
// Create output directory
|
// Create output directory
|
||||||
let output = root.join(sanitise(&alias));
|
let output = folders::podcast_folder(root, alias);
|
||||||
if !output.exists() {
|
if !output.exists() {
|
||||||
fs::create_dir(&output)
|
fs::create_dir_all(&output)
|
||||||
.with_context(|| format!("failed to create output directory for podcast {}", alias))?;
|
.context(format!("failed to create output directory for podcast {}", alias))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(r#"[info] scanning feed for "{}""#, 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("User-Agent", "podcast-downloader")
|
||||||
.with_header("Accept", "*/*")
|
.with_header("Accept", "*/*")
|
||||||
.send()
|
.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 {
|
if response.status_code != 200 {
|
||||||
eprintln!(r#"[error] feed "{}" for alias {} responded with non-200 ({}) status code"#, feed_url, alias, response.status_code);
|
eprintln!(r#"[error] feed "{}" for alias {} responded with non-200 ({}) status code"#, feed_url, alias, response.status_code);
|
||||||
|
|||||||
12
src/folders.rs
Normal file
12
src/folders.rs
Normal 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))
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
mod rss;
|
mod rss;
|
||||||
mod input;
|
mod input;
|
||||||
mod tagging;
|
mod tagging;
|
||||||
|
mod folders;
|
||||||
mod download;
|
mod download;
|
||||||
|
|
||||||
use input::{Command, ListenStatus};
|
use input::{Command, ListenStatus};
|
||||||
@@ -8,7 +9,6 @@ use input::{Command, ListenStatus};
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use sanitise_file_name::sanitise;
|
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Command::List { status, podcast } => {
|
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_file = output.join("spec.toml");
|
||||||
|
|
||||||
let spec = download::Specification::read_from(&spec_file)?;
|
let spec = download::Specification::read_from(&spec_file)?;
|
||||||
@@ -64,7 +64,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Command::Mark { status, podcast } => {
|
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 spec_file = output.join("spec.toml");
|
||||||
|
|
||||||
let mut spec = download::Specification::read_from(&spec_file)?;
|
let mut spec = download::Specification::read_from(&spec_file)?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{fs, path};
|
use std::{fs, path};
|
||||||
|
|
||||||
use crate::download;
|
use crate::{folders, download};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ pub(crate) fn generate_m3u(
|
|||||||
alias: &str,
|
alias: &str,
|
||||||
root: &path::Path,
|
root: &path::Path,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let output = root.join(sanitise(&alias));
|
let output = folders::podcast_folder(root, alias);
|
||||||
let spec_file = output.join("spec.toml");
|
let spec_file = output.join("spec.toml");
|
||||||
|
|
||||||
let spec = download::Specification::read_from(&spec_file)?;
|
let spec = download::Specification::read_from(&spec_file)?;
|
||||||
@@ -54,7 +54,7 @@ pub(crate) fn strip_tags(
|
|||||||
alias: &str,
|
alias: &str,
|
||||||
root: &path::Path,
|
root: &path::Path,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let output = root.join(sanitise(&alias));
|
let output = folders::podcast_folder(root, alias);
|
||||||
let spec_file = output.join("spec.toml");
|
let spec_file = output.join("spec.toml");
|
||||||
|
|
||||||
let spec = download::Specification::read_from(&spec_file)?;
|
let spec = download::Specification::read_from(&spec_file)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user