Skip to content

Commit

Permalink
feat: derive Serialize & Deserialize and support program as lib
Browse files Browse the repository at this point in the history
  • Loading branch information
flazepe committed Nov 1, 2024
1 parent 75f803e commit 35b88d5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[package]
name = "clipper"
version = "0.2.1"
edition = "2021"
edition = "2021"

[lib]
path = "src/main.rs"

[dependencies]
serde = { version = "1", features = ["derive"] }
4 changes: 3 additions & 1 deletion src/clipper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use crate::{
error,
ffmpeg::{Encoder, Inputs, Output},
};
use serde::{Deserialize, Serialize};
use std::{
env::args,
process::{exit, Command},
vec::IntoIter,
};

#[derive(Default)]
#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Clipper {
pub inputs: Inputs,
pub encoder: Encoder,
Expand Down
4 changes: 3 additions & 1 deletion src/ffmpeg/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{error, string_vec};
use serde::{Deserialize, Serialize};
use std::vec::IntoIter;

#[derive(Default)]
#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Encoder {
nvenc: bool,
hevc: bool,
Expand Down
3 changes: 3 additions & 0 deletions src/ffmpeg/input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{error, ffmpeg::duration_to_secs};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Input {
pub file: String,
pub segments: Vec<(f64, f64)>,
Expand Down
4 changes: 3 additions & 1 deletion src/ffmpeg/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use crate::{
ffmpeg::{escape_ffmpeg_chars, Input},
string_vec,
};
use serde::{Deserialize, Serialize};
use std::vec::IntoIter;

#[derive(Default)]
#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Inputs {
inputs: Vec<Input>,
fade: f64,
Expand Down
4 changes: 3 additions & 1 deletion src/ffmpeg/output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{error, string_vec};
use serde::{Deserialize, Serialize};
use std::vec::IntoIter;

#[derive(Default)]
#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Output {
file: Option<String>,
force_overwrite: bool,
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod clipper;
mod ffmpeg;

use clipper::Clipper;
pub use clipper::Clipper;

fn main() {
Clipper::new().run();
pub fn main() {
Clipper::from_args().run();
}

0 comments on commit 35b88d5

Please sign in to comment.