Skip to content

Commit c3c4f3c

Browse files
committed
fix: replace unwraps with Result
1 parent 0dac568 commit c3c4f3c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/ffmpeg.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fs, process::Command};
1+
use std::{fs, io, process::Command};
22

33
fn run_command(command: &str) {
44
let cmd = Command::new("sh")
@@ -20,7 +20,7 @@ fn run_command(command: &str) {
2020
println!("{}", result);
2121
}
2222

23-
pub fn create_preview_gif(input: &str, subpath: &str, output: &str) {
23+
pub fn create_preview_gif(input: &str, subpath: &str, output: &str) -> io::Result<()> {
2424
let path = format!("{}/{}", output, subpath);
2525
if fs::metadata(&path).is_err() {
2626
fs::create_dir_all(&path).unwrap();
@@ -31,9 +31,10 @@ pub fn create_preview_gif(input: &str, subpath: &str, output: &str) {
3131
);
3232

3333
run_command(&command);
34+
Ok(())
3435
}
3536

36-
pub fn create_preview_image(input: &str, subpath: &str, output: &str) {
37+
pub fn create_preview_image(input: &str, subpath: &str, output: &str) -> io::Result<()> {
3738
let path = format!("{}/{}", output, subpath);
3839
if fs::metadata(&path).is_err() {
3940
fs::create_dir_all(&path).unwrap();
@@ -45,9 +46,10 @@ pub fn create_preview_image(input: &str, subpath: &str, output: &str) {
4546
);
4647

4748
run_command(&command);
49+
Ok(())
4850
}
4951

50-
pub fn create_thumbnails(input: &str, subpath: &str, output: &str) {
52+
pub fn create_thumbnails(input: &str, subpath: &str, output: &str) -> io::Result<()> {
5153
println!("\ncreate_thumbnails");
5254

5355
let thumbs_path = format!("{}/{}", output, subpath);
@@ -63,9 +65,10 @@ pub fn create_thumbnails(input: &str, subpath: &str, output: &str) {
6365
);
6466

6567
run_command(&command);
68+
Ok(())
6669
}
6770

68-
pub fn create_hls_encoding(input: &str, subpath: &str, output: &str) {
71+
pub fn create_hls_encoding(input: &str, subpath: &str, output: &str) -> io::Result<()> {
6972
println!("\npub create_hls_encoding");
7073

7174
let hls_path = format!("{}/{}", output, subpath);
@@ -96,4 +99,5 @@ pub fn create_hls_encoding(input: &str, subpath: &str, output: &str) {
9699
-hls_playlist_type {}/vod \
97100
{}/720p_%03d.m3u8 {}/720p.m3u8", input, hls_path, hls_path, hls_path);
98101
run_command(&command);
102+
Ok(())
99103
}

src/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ffmpeg::{create_preview_gif, create_preview_image};
22
use clap::{App, Arg};
3-
use std::process;
3+
use std::{io, process};
44

55
enum Flags {
66
Gif,
@@ -52,7 +52,7 @@ mod fileio;
5252
mod media_info;
5353
mod metadata;
5454

55-
fn main() {
55+
fn main() -> io::Result<()> {
5656
let matches = App::new("tape-encoder")
5757
.version("1.0")
5858
.author("Matt Carrier")
@@ -108,22 +108,22 @@ fn main() {
108108

109109
let gen_thumbs = matches.is_present(Flags::Thumbnails.as_str());
110110
if gen_thumbs {
111-
create_thumbnails(&out.file_name, "thumbs", &path);
111+
create_thumbnails(&out.file_name, "thumbs", &path)?;
112112
}
113113

114114
let gen_preview_image = matches.is_present(Flags::PreviewImage.as_str());
115115
if gen_preview_image {
116-
create_preview_image(&out.file_name, "lg", &path);
116+
create_preview_image(&out.file_name, "lg", &path)?;
117117
}
118118

119119
let gen_hls = matches.is_present(Flags::Hls.as_str());
120120
if gen_hls {
121-
create_hls_encoding(&out.file_name, "hls", &path);
121+
create_hls_encoding(&out.file_name, "hls", &path)?;
122122
}
123123

124124
let gen_gif = matches.is_present(Flags::Gif.as_str());
125125
if gen_gif {
126-
create_preview_gif(&out.file_name, "gif", &path);
126+
create_preview_gif(&out.file_name, "gif", &path)?;
127127
}
128128

129129
/*
@@ -147,4 +147,5 @@ fn main() {
147147
[ ] Create queue watcher to start running jobs (watches queueu every 5 seconds)
148148
- On new item run generator process
149149
*/
150+
Ok(())
150151
}

0 commit comments

Comments
 (0)