Skip to content

Commit

Permalink
Option to disable gif to mp4 conversion (mcdallas#3)
Browse files Browse the repository at this point in the history
* 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?)
  • Loading branch information
xvca authored Feb 20, 2023
1 parent a04e4f1 commit 8ab9b10
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ USAGE:
gert [FLAGS] [OPTIONS] --subreddit <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
Expand Down Expand Up @@ -116,3 +117,4 @@ _NOTE_: If you have 2FA enabled, please make sure you set `PASSWORD=<password>:<
### Credits

based on https://github.com/manojkarthick/reddsaver

5 changes: 4 additions & 1 deletion src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct Downloader<'a> {
use_human_readable: bool,
ffmpeg_available: bool,
session: &'a reqwest::Client,
conserve_gifs: bool,
supported: Arc<Mutex<u16>>,
skipped: Arc<Mutex<u16>>,
downloaded: Arc<Mutex<u16>>,
Expand All @@ -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,
Expand All @@ -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)),
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -312,6 +321,7 @@ async fn main() -> Result<(), GertError> {
use_human_readable,
ffmpeg_available,
&session,
conserve_gifs,
);

downloader.run().await?;
Expand Down

0 comments on commit 8ab9b10

Please sign in to comment.