Check and use correct paths for generating HLS playlist

This also should prevent generating the playlist if it already exists
and uses a better ffmpeg command for transcoding the video.
This commit is contained in:
Cameron Cordes
2020-07-14 15:45:10 -04:00
parent c39bf970be
commit ca761f605b
2 changed files with 28 additions and 12 deletions

View File

@@ -126,12 +126,17 @@ async fn generate_video(_claims: Claims, body: web::Json<ThumbnailRequest>) -> i
let filename = PathBuf::from(&body.path);
if let Some(name) = filename.file_stem() {
let filename = name.to_str().expect("Filename should conver to string");
create_playlist(&body.path, &format!("tmp/{}.m3u8", filename));
let filename = name.to_str().expect("Filename should convert to string");
let playlist = format!("tmp/{}.m3u8", filename);
if let Some(path) = is_valid_path(&body.path) {
create_playlist(&path.to_str().unwrap(), &playlist);
} else {
return HttpResponse::BadRequest().finish();
}
HttpResponse::Ok()
HttpResponse::Ok().json(playlist)
} else {
HttpResponse::BadRequest()
HttpResponse::BadRequest().finish()
}
}
@@ -149,10 +154,10 @@ async fn stream_video(request: HttpRequest, path: web::Query<ThumbnailRequest>)
#[get("/video/{path}")]
async fn get_video_part(request: HttpRequest, path: web::Path<ThumbnailRequest>) -> impl Responder {
let playlist = &path.path;
println!("Video part: {}", playlist);
let part = &path.path;
println!("Video part: {}", part);
if let Ok(file) = NamedFile::open(String::from("tmp/") + playlist) {
if let Ok(file) = NamedFile::open(String::from("tmp/") + part) {
file.into_response(&request).unwrap()
} else {
HttpResponse::NotFound().finish()