ipod syncing; updated readme; rust 2024; version bump
This commit is contained in:
@@ -10,6 +10,7 @@ use sanitise_file_name::sanitise;
|
||||
|
||||
use crate::{
|
||||
rss,
|
||||
input,
|
||||
folders,
|
||||
manage::{
|
||||
Specification,
|
||||
@@ -33,9 +34,14 @@ fn download_to_file(url: &str, path: &path::Path) -> anyhow::Result<()> {
|
||||
pub(crate) fn update_podcast(
|
||||
alias: &str,
|
||||
root: &path::Path,
|
||||
feed_location: &str,
|
||||
source: &input::Source,
|
||||
) -> anyhow::Result<()> {
|
||||
|
||||
if source.skip_download() {
|
||||
println!(r#"[info] skipping download for "{}""#, alias);
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
// Create output directory
|
||||
let output = folders::podcast_folder(root, alias);
|
||||
if !output.exists() {
|
||||
@@ -45,32 +51,32 @@ pub(crate) fn update_podcast(
|
||||
|
||||
println!(r#"[info] scanning feed for "{}""#, alias);
|
||||
|
||||
if feed_location.starts_with("http") {
|
||||
let feed_url = feed_location;
|
||||
match source.source() {
|
||||
input::SourceKind::Url(feed_url) => {
|
||||
// Get the podcast feed
|
||||
let response = minreq::get(feed_url)
|
||||
// For SquareSpace which refuses requests with no User-Agent
|
||||
.with_header("User-Agent", "podcast-downloader")
|
||||
.with_header("Accept", "*/*")
|
||||
.send()
|
||||
.context(format!(r#"error when requesting feed url "{}" for {}"#, feed_url, alias))?;
|
||||
|
||||
// Get the podcast feed
|
||||
let response = minreq::get(feed_url)
|
||||
// For SquareSpace which refuses requests with no User-Agent
|
||||
.with_header("User-Agent", "podcast-downloader")
|
||||
.with_header("Accept", "*/*")
|
||||
.send()
|
||||
.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);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if response.status_code != 200 {
|
||||
eprintln!(r#"[error] feed "{}" for alias {} responded with non-200 ({}) status code"#, feed_url, alias, response.status_code);
|
||||
return Ok(());
|
||||
let feed = response.as_str()?.to_owned();
|
||||
update_podcast_from_feed(&output, &feed)
|
||||
}
|
||||
|
||||
let feed = response.as_str()?.to_owned();
|
||||
update_podcast_from_feed(&output, &feed)
|
||||
} else {
|
||||
let feed_path = root.join(feed_location);
|
||||
|
||||
match fs::read_to_string(&feed_path) {
|
||||
Ok(feed) => update_podcast_from_feed(&output, &feed),
|
||||
Err(err) => {
|
||||
eprintln!(r#"[error] failed to read path "{}" with error {}"#, feed_path.display(), err);
|
||||
Ok(())
|
||||
input::SourceKind::Path(feed_location) => {
|
||||
let feed_path = root.join(feed_location);
|
||||
match fs::read_to_string(&feed_path) {
|
||||
Ok(feed) => update_podcast_from_feed(&output, &feed),
|
||||
Err(err) => {
|
||||
eprintln!(r#"[error] failed to read path "{}" with error {}"#, feed_path.display(), err);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,7 +155,7 @@ pub(crate) fn update_podcast_from_feed(
|
||||
|
||||
let channel = feed.rss.channel;
|
||||
|
||||
let spec_file = output.join("spec.toml");
|
||||
let spec_file = output.join(folders::SPEC_FILE);
|
||||
|
||||
let mut spec = Specification::read_from_with_default(&spec_file)?;
|
||||
|
||||
@@ -243,11 +249,21 @@ pub(crate) fn update_podcast_from_feed(
|
||||
match download_to_file(enclosure.url.as_ref(), &file_path) {
|
||||
Ok(()) => {
|
||||
let file_path = file_path.canonicalize().unwrap();
|
||||
let relative_path = file_path.strip_prefix(&output).unwrap();
|
||||
|
||||
spec.insert_into_files(
|
||||
if let Some(previous) = spec.insert_into_files(
|
||||
id.to_owned(),
|
||||
file_path.strip_prefix(&output).unwrap().to_owned(),
|
||||
)?;
|
||||
relative_path.to_owned(),
|
||||
) {
|
||||
println!("[warning] duplicate id {:?} for episodes {:?} and {:?}", id, previous, relative_path);
|
||||
|
||||
// Revert to the previous file
|
||||
spec.insert_into_files(id.to_owned(), previous);
|
||||
// Delete the newly downloaded file
|
||||
fs::remove_file(file_path)?;
|
||||
// Skip
|
||||
continue;
|
||||
}
|
||||
|
||||
let episode = Episode::new_downloaded(title, description, id.to_owned());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user