Skip to content

Commit

Permalink
fix too long filename
Browse files Browse the repository at this point in the history
  • Loading branch information
TBS1996 committed May 21, 2024
1 parent 3777621 commit 816e11d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "talecast"
version = "0.1.38"
version = "0.1.39"
edition = "2021"
description = "Simple CLI podcatcher"
license = "MIT"
Expand Down
9 changes: 8 additions & 1 deletion src/episode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,17 @@ impl<'a> DownloadedEpisode<'a> {

fn rename(&mut self) -> Result<(), String> {
let new_name = &self.inner.config.name_pattern;
let new_name = sanitize_filename::sanitize(new_name);
let mut new_name = sanitize_filename::sanitize(new_name);

let new_path = match self.path.extension() {
Some(extension) => {
let max_file_len: usize = 255;
let ext_len = extension.len() + 1; // + 1 for the dot.
let overflow = (new_name.len() + ext_len).saturating_sub(max_file_len);
for _ in 0..overflow {
new_name.pop();
}

let mut new_path = self.path.with_file_name(new_name);
new_path.set_extension(extension);
new_path
Expand Down
1 change: 1 addition & 0 deletions src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ use crate::config::EvalData;
pub trait Evaluate {
fn evaluate(&self, data: EvalData) -> String;

#[allow(dead_code)]
fn path_eval(&self, data: EvalData) -> PathBuf {
let s = self.evaluate(data);
PathBuf::from(s)
Expand Down
6 changes: 0 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::config;
use crate::episode::Episode;
use crate::utils;
use regex::Regex;
use serde::Serialize;
use serde_json::Value;
use std::fs;
use std::fs::File;
Expand Down Expand Up @@ -95,11 +94,6 @@ pub fn truncate_string(s: &str, max_width: usize, append_dots: bool) -> String {
truncated
}

#[derive(Serialize)]
struct BasicPodcast {
url: String,
}

pub fn short_handle_response(
response: Result<reqwest::Response, reqwest::Error>,
) -> Result<reqwest::Response, String> {
Expand Down

0 comments on commit 816e11d

Please sign in to comment.