From 8ab9b107f89e32b210fcc6a1defa024837764a8b Mon Sep 17 00:00:00 2001 From: lucavin <39647640+lucavin@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:14:04 +1100 Subject: [PATCH] Option to disable gif to mp4 conversion (#3) * Initial commit. Added -c flag which allows the user to disable gif to mp4 conversion. * small change to readme and help * removed weird readme changes (autoformat?) --- README.md | 2 ++ src/download.rs | 5 ++++- src/main.rs | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b99a29b..6423181 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ USAGE: gert [FLAGS] [OPTIONS] --subreddit ... FLAGS: + -c --conserve-gifs Disable gif to mp4 conversion --debug Show the current config being used -r, --dry-run Dry run and print the URLs of saved media to download -h, --help Prints help information @@ -116,3 +117,4 @@ _NOTE_: If you have 2FA enabled, please make sure you set `PASSWORD=:< ### Credits based on https://github.com/manojkarthick/reddsaver + diff --git a/src/download.rs b/src/download.rs index 5ba1eca..ba7d031 100644 --- a/src/download.rs +++ b/src/download.rs @@ -73,6 +73,7 @@ pub struct Downloader<'a> { use_human_readable: bool, ffmpeg_available: bool, session: &'a reqwest::Client, + conserve_gifs: bool, supported: Arc>, skipped: Arc>, downloaded: Arc>, @@ -88,6 +89,7 @@ impl<'a> Downloader<'a> { use_human_readable: bool, ffmpeg_available: bool, session: &'a reqwest::Client, + conserve_gifs: bool, ) -> Downloader<'a> { Downloader { posts, @@ -96,6 +98,7 @@ impl<'a> Downloader<'a> { use_human_readable, ffmpeg_available, session, + conserve_gifs, supported: Arc::new(Mutex::new(0)), skipped: Arc::new(Mutex::new(0)), downloaded: Arc::new(Mutex::new(0)), @@ -596,7 +599,7 @@ impl<'a> Downloader<'a> { return Ok(download_path); }; - if task.extension == GIF_EXTENSION { + if task.extension == GIF_EXTENSION && !self.conserve_gifs { //If ffmpeg is installed convert gifs to mp4 let output_file = download_path.replace(".gif", ".mp4"); if check_path_present(&output_file) { diff --git a/src/main.rs b/src/main.rs index 0ce1a00..c53c6dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -136,6 +136,14 @@ async fn main() -> Result<(), GertError> { .takes_value(true) .default_value("0"), ) + .arg( + Arg::with_name("conserve_gifs") + .short("c") + .long("conserve-gifs") + .value_name("conserve_gifs") + .help("Disable gif to mp4 conversion") + .takes_value(false), + ) .get_matches(); let env_file = matches.value_of("environment"); @@ -182,6 +190,7 @@ async fn main() -> Result<(), GertError> { }, None => regex::Regex::new(".*").unwrap(), }; + let conserve_gifs: bool = matches.is_present("conserve_gifs"); // initialize logger for the app and set logging level to info if no environment variable present let env = Env::default().filter("RS_LOG").default_filter_or("info"); @@ -312,6 +321,7 @@ async fn main() -> Result<(), GertError> { use_human_readable, ffmpeg_available, &session, + conserve_gifs, ); downloader.run().await?;