From c7cef6e7afcf4e30081064177dd8131005254ff6 Mon Sep 17 00:00:00 2001 From: Didier Date: Mon, 8 May 2023 14:45:23 +0200 Subject: [PATCH 1/7] fix: version->tag --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 31a7f93..05dd769 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ fn main() { trace!("Config: {:#?}", &config); debug!("commit: {}", env!("GIT_COMMIT_HASH")); - debug!("version: {}", env!("GIT_TAG")); + debug!("tag: {}", env!("GIT_TAG")); let input_files = files::get_files(&config.files.input_path) .into_iter() From 16395dc57001282c6d5404271ff04da6780fd078 Mon Sep 17 00:00:00 2001 From: Didier Date: Sat, 3 Jun 2023 21:08:44 +0200 Subject: [PATCH 2/7] feat: add workflow --- .github/workflows/build.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..0408992 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,22 @@ +# build.yaml +# --- +# Builds the rust code and verifies that it compiles + +name: build +on: [ 'push' ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: install dependencies + run: | + apt update -y + apt install -y curl + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build + run: cargo build --verbose From 6b1ee28c06df155712dfb902bf1a352ac21dc7cc Mon Sep 17 00:00:00 2001 From: Didier Date: Sat, 3 Jun 2023 21:28:48 +0200 Subject: [PATCH 3/7] multi-commit: cleanup, fix file handling feat: added cleanup feat: added new config key (keep_directory_structure) fix: file handling --- config.example.toml | 1 + src/configuration/mod.rs | 2 ++ src/main.rs | 38 +++++++++++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/config.example.toml b/config.example.toml index 4a7578e..50806ef 100644 --- a/config.example.toml +++ b/config.example.toml @@ -1,6 +1,7 @@ [files] input_path = "/data/input" output_path = "/data/output" +keep_directory_structure = true # keep directory structure when outputting files include = [ 'mp4', 'avi', 'mkv' ] # file extensions to include [files.cleanup] diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index 04a2131..e7eab65 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -32,6 +32,7 @@ pub struct ConfigFilesCleanup { pub struct ConfigFiles { pub input_path: String, pub output_path: String, + pub keep_directory_structure: Option, pub include: Vec, pub cleanup: Option, } @@ -51,6 +52,7 @@ impl Config { files: ConfigFiles { input_path: String::from("/data/input"), output_path: String::from("/data/output"), + keep_directory_structure: None, include: Vec::new(), cleanup: None, }, diff --git a/src/main.rs b/src/main.rs index 05dd769..eeff7cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,9 +47,21 @@ fn start_transcode_run(input_files: &Vec, config: &Config) -> i32 { error!("Failed to process file {}: {}", job.input, remarks); }; - let mut output_path = file.clone(); + let mut output_path = if let Some(keep_directory_structure) = config.files.keep_directory_structure { + if keep_directory_structure { + let mut output_path = PathBuf::from(&config.files.output_path); + output_path.push(file.strip_prefix(&config.files.input_path).unwrap()); + output_path + } else { + PathBuf::from(&config.files.output_path) + .join(file.file_name().unwrap()) + } + } else { + PathBuf::from(&config.files.output_path) + .join(file.file_name().unwrap()) + }; output_path.set_extension(&config.ffmpeg.output.format); - let output_path = PathBuf::from(&config.files.output_path).join(output_path.file_name().unwrap()); // TODO: This is a bit of a mess. + let job = TranscodeJob::new( file.to_str().unwrap(), @@ -87,7 +99,27 @@ fn start_transcode_run(input_files: &Vec, config: &Config) -> i32 { continue; } - // TODO: Cleanup + if let Some(cleanup) = &config.files.cleanup { + if !cleanup.enabled { () } + match cleanup.original_cleanup_behavior { + configuration::ConfigFilesCleanupOriginalBehavior::delete => { + if let Err(e) = std::fs::remove_file(&job.input) { + error!("Failed to delete original file {}: {}", job.input, e); + } + }, + configuration::ConfigFilesCleanupOriginalBehavior::archive => { + let mut archive_path = PathBuf::from(&cleanup.archive.path); + archive_path.push(job.input.strip_prefix(&config.files.input_path).unwrap()); + if let Err(e) = std::fs::create_dir_all(archive_path.parent().unwrap()) { + error!("Failed to create archive directory {}: {}", archive_path.parent().unwrap().to_str().unwrap(), e); + } + if let Err(e) = std::fs::rename(&job.input, &archive_path) { + error!("Failed to archive original file {}: {}", job.input, e); + } + }, + configuration::ConfigFilesCleanupOriginalBehavior::keep => (), + } + } info!("Finished processing file {}.", job.input); success_count += 1; From 799bb6b8cd24eb249c47ade588348be43d553948 Mon Sep 17 00:00:00 2001 From: Didier Date: Sun, 4 Jun 2023 11:16:12 +0200 Subject: [PATCH 4/7] docs: fixed todos --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index afa75fe..5b82b2e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,3 @@ # Bumblebee -Bumblebee is a simple wrapper around FFMPEG for transcoding media. - -## (main) TODO -main things that need to be done. - -- [x] make initial behaviour work. -- [ ] make archiving system work. -- [ ] refactor code so it makes sense. \ No newline at end of file +Bumblebee is a simple wrapper around FFMPEG for transcoding media. \ No newline at end of file From 33ac3ae21351278e7bea74df8cd6b9c04dd44d66 Mon Sep 17 00:00:00 2001 From: Didier Date: Thu, 15 Jun 2023 12:23:41 +0200 Subject: [PATCH 5/7] fix: automation --- .github/workflows/build.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0408992..e71a05d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,10 +13,12 @@ jobs: - name: install dependencies run: | apt update -y - apt install -y curl + apt install -y curl gcc g++ make - uses: actions-rs/toolchain@v1 with: toolchain: stable override: true - - name: Build - run: cargo build --verbose + - uses: actions-rs/cargo@v1 + with: + command: build + args: --verbose --all From 3c4a68cb8f9ad21d7f3fe85a7dc26bb0a6f43fb3 Mon Sep 17 00:00:00 2001 From: Didier Date: Sun, 16 Jul 2023 18:49:06 +0200 Subject: [PATCH 6/7] fix: add github prefix --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e71a05d..66d3753 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,11 +14,11 @@ jobs: run: | apt update -y apt install -y curl gcc g++ make - - uses: actions-rs/toolchain@v1 + - uses: https://github.com/actions-rs/toolchain@v1 with: toolchain: stable override: true - - uses: actions-rs/cargo@v1 + - uses: https://github.com/actions-rs/cargo@v1 with: command: build args: --verbose --all From c76883d3ec30fb14135409b9c5eda98fe5b303a0 Mon Sep 17 00:00:00 2001 From: Didier Date: Sun, 16 Jul 2023 20:09:50 +0200 Subject: [PATCH 7/7] ci: only build on .rs changes --- .github/workflows/build.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 66d3753..2914e7d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,7 +3,10 @@ # Builds the rust code and verifies that it compiles name: build -on: [ 'push' ] +on: + push: + paths: + - '**.rs' jobs: build: