Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct Config
pub colors: AppColors,
pub filename_prefix: String,
pub filename_suffix: String,
pub short_filename: bool,
}

/// A temporary struct used to deserialize data from the TOML configuration
Expand All @@ -73,6 +74,7 @@ struct ConfigFromToml
colors: Option<AppColorsFromToml>,
filename_prefix: Option<String>,
filename_suffix: Option<String>,
short_filename: Option<bool>,
}

/// A temporary struct used to deserialize keybinding data from the TOML
Expand Down Expand Up @@ -202,6 +204,7 @@ impl Config
colors: Some(colors),
filename_prefix: None,
filename_suffix: None,
short_filename: None,
}
}
};
Expand Down Expand Up @@ -315,6 +318,7 @@ fn config_with_defaults(config_toml: ConfigFromToml) -> Result<Config>
colors: colors,
filename_prefix: filename_prefix,
filename_suffix: filename_suffix,
short_filename: config_toml.short_filename.unwrap_or(false),
});
}

Expand Down
9 changes: 8 additions & 1 deletion src/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn download_list(
max_retries: usize,
filename_prefix: &str,
filename_suffix: &str,
short_filename: bool,
threadpool: &Threadpool,
tx_to_main: Sender<Message>,
) {
Expand All @@ -54,7 +55,7 @@ pub fn download_list(
let prefix = filename_prefix.to_owned();
let suffix = filename_suffix.to_owned();
threadpool.execute(move || {
let result = download_file(ep, dest2, max_retries, prefix, suffix);
let result = download_file(ep, dest2, max_retries, prefix, suffix, short_filename);
tx.send(Message::Dl(result))
.expect("Thread messaging error");
});
Expand All @@ -69,6 +70,7 @@ fn download_file(
mut max_retries: usize,
filename_prefix: String,
filename_suffix: String,
short_filename: bool,
) -> DownloadMsg
{
let agent_builder = ureq::builder()
Expand Down Expand Up @@ -133,6 +135,11 @@ fn download_file(
pubdate.format(&filename_suffix)
);
}

// If short_filename is enabled, truncate to 140 characters to stay under Windows path limits
if short_filename && file_name.len() > 140 {
file_name.truncate(140);
}

let mut file_path = dest;
file_path.push(format!("{file_name}.{ext}"));
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ fn main() -> Result<()>
"Sets a custom config file location. Can also be set with environment variable."
)
)
.arg(Arg::new("short-filename")
.short('s')
.long("short-filename")
.global(true)
.help(
"Truncates filenames to 140 characters to stay under Windows path length limits."
)
)
.subcommand(Command::new("sync")
.about("Syncs all podcasts in database")
.arg(Arg::new("quiet")
Expand Down Expand Up @@ -132,7 +140,8 @@ fn main() -> Result<()>
);
process::exit(1);
});
let config = Config::new(&config_path)?;
let mut config = Config::new(&config_path)?;
config.short_filename = args.is_present("short-filename");

let mut db_path = config_path;
if !db_path.pop()
Expand Down
1 change: 1 addition & 0 deletions src/main_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ impl MainController
self.config.max_retries,
&self.config.filename_prefix,
&self.config.filename_suffix,
self.config.short_filename,
&self.threadpool,
self.tx_to_main.clone(),
);
Expand Down