Skip to content

Commit 0dac568

Browse files
committed
fix: move file paths into main function
1 parent 50af3c3 commit 0dac568

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/ffmpeg.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn run_command(command: &str) {
2020
println!("{}", result);
2121
}
2222

23-
pub fn create_preview_gif(input: &str, output: &str) {
24-
let path = format!("{}/gif", output);
23+
pub fn create_preview_gif(input: &str, subpath: &str, output: &str) {
24+
let path = format!("{}/{}", output, subpath);
2525
if fs::metadata(&path).is_err() {
2626
fs::create_dir_all(&path).unwrap();
2727
}
@@ -33,8 +33,8 @@ pub fn create_preview_gif(input: &str, output: &str) {
3333
run_command(&command);
3434
}
3535

36-
pub fn create_preview_image(input: &str, output: &str) {
37-
let path = format!("{}/lg", output);
36+
pub fn create_preview_image(input: &str, subpath: &str, output: &str) {
37+
let path = format!("{}/{}", output, subpath);
3838
if fs::metadata(&path).is_err() {
3939
fs::create_dir_all(&path).unwrap();
4040
}
@@ -47,10 +47,10 @@ pub fn create_preview_image(input: &str, output: &str) {
4747
run_command(&command);
4848
}
4949

50-
pub fn create_thumbnails(input: &str, output: &str) {
50+
pub fn create_thumbnails(input: &str, subpath: &str, output: &str) {
5151
println!("\ncreate_thumbnails");
5252

53-
let thumbs_path = format!("{}/thumbs", output);
53+
let thumbs_path = format!("{}/{}", output, subpath);
5454

5555
println!("Path: {}", thumbs_path);
5656
if fs::metadata(&thumbs_path).is_err() {
@@ -65,11 +65,13 @@ pub fn create_thumbnails(input: &str, output: &str) {
6565
run_command(&command);
6666
}
6767

68-
pub fn create_hls_encoding(input: &str, output: &str) {
68+
pub fn create_hls_encoding(input: &str, subpath: &str, output: &str) {
6969
println!("\npub create_hls_encoding");
7070

71-
if fs::metadata(output).is_err() {
72-
fs::create_dir_all(output).unwrap();
71+
let hls_path = format!("{}/{}", output, subpath);
72+
73+
if fs::metadata(&hls_path).is_err() {
74+
fs::create_dir_all(&hls_path).unwrap();
7375
}
7476

7577
// TODO: Sub add paths
@@ -91,7 +93,7 @@ pub fn create_hls_encoding(input: &str, output: &str) {
9193
-window_size 0 -adaptation_sets \"id=0,streams=v id=1,streams=a\" -hls_playlist 1 -seg_duration 4 \
9294
-streaming 0 -f dash \
9395
-hls_segment_filename \
94-
-hls_playlist_type {}/vod \
95-
{}/720p_%03d.m3u8 {}/720p.m3u8", input, output, output, output);
96+
-hls_playlist_type {}/vod \
97+
{}/720p_%03d.m3u8 {}/720p.m3u8", input, hls_path, hls_path, hls_path);
9698
run_command(&command);
9799
}

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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, &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, &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, &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, &path);
126+
create_preview_gif(&out.file_name, "gif", &path);
127127
}
128128

129129
/*
@@ -141,7 +141,7 @@ fn main() {
141141
[x] HLS
142142
[x] DASH
143143
xx] Metadata
144-
[ ] Move hard coded path out of functions and into main
144+
[x] Move hard coded path out of functions and into main
145145
[ ] Refactor to get rid of unwraps and panics
146146
[ ] Upload metadata to database
147147
[ ] Create queue watcher to start running jobs (watches queueu every 5 seconds)

0 commit comments

Comments
 (0)