Skip to content

Commit

Permalink
✨ Create extra dir fps_changer inside of the temp dir
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
tgotwig committed Jul 19, 2024
1 parent 5d859b5 commit 4797fca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Videos with changed fps from fps_changer will be stored in <TMP_DIR>/fps_changer.
- Selector now case-insensitive, so it selects mp4 and MP4 etc.

## 🎉 [0.3.2] - 2024-01-14
Expand Down
14 changes: 10 additions & 4 deletions src/commanders/fps_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use crate::{
cli::Cli,
commanders,
helpers::{
io_helper::path_bufs_to_sorted_strings, str_helper::gen_input_file_content_for_ffmpeg,
io_helper::{create_dir_for_fps_changer, path_bufs_to_sorted_strings},
str_helper::gen_input_file_content_for_ffmpeg,
},
};
use std::path::Path;
use std::{
collections::{HashMap, HashSet},
path::{Path, PathBuf},
path::PathBuf,
};

pub fn change_fps(
Expand All @@ -18,6 +20,7 @@ pub fn change_fps(
) -> (Vec<PathBuf>, Vec<std::string::String>, std::string::String) {
let matches = Cli::init().get_matches();
let verbose: bool = matches.is_present("verbose");
let tmp_dir_for_fps_changer = create_dir_for_fps_changer(tmp_dir).unwrap();

let mut new_files_to_merge = Vec::new();
let mut map: HashMap<&PathBuf, f32> = HashMap::new();
Expand Down Expand Up @@ -87,8 +90,11 @@ pub fn change_fps(
let fps = get_fps(&file_to_merge);

if fps != fps_goal {
let new_file_to_merge =
commanders::fps_adjuster::adjust_fps(file_to_merge, &fps_goal, tmp_dir);
let new_file_to_merge = commanders::fps_adjuster::adjust_fps(
file_to_merge,
&fps_goal,
&tmp_dir_for_fps_changer,
);
new_files_to_merge.push(new_file_to_merge);
} else {
new_files_to_merge.push(file_to_merge);
Expand Down
9 changes: 8 additions & 1 deletion src/helpers/io_helper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use nanoid::nanoid;
use std::env::temp_dir;
use std::fs::{self, canonicalize, File};
use std::io::{Result, Write};
use std::io::{self, Result, Write};
use std::path::{Path, PathBuf};
use std::process::exit;

Expand Down Expand Up @@ -42,6 +42,13 @@ pub fn create_tmp_dir() -> PathBuf {
dir
}

pub fn create_dir_for_fps_changer(base_path: &Path) -> io::Result<PathBuf> {
let mut new_path = base_path.to_path_buf();
new_path.push("fps_changer");
fs::create_dir_all(&new_path)?;
Ok(new_path)
}

pub fn create(path: &PathBuf, buf: String) -> &PathBuf {
File::create(path)
.unwrap()
Expand Down

0 comments on commit 4797fca

Please sign in to comment.