1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00

Detect mime-type when playing files

Signed-off-by: Robert Günzler <r@gnzler.io>
This commit is contained in:
Robert Günzler 2024-05-17 13:33:56 +02:00 committed by Michael Hollister
parent be93dcf03d
commit c5259ee07f

View file

@ -59,7 +59,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
.long("mime_type")
.value_name("MIME_TYPE")
.help("Mime type (e.g., video/mp4)")
.required(true)
.required_unless_present("file")
.takes_value(true)
)
.arg(Arg::with_name("file")
@ -189,9 +189,23 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
let mut join_handle: Option<JoinHandle<Result<(), String>>> = None;
if let Some(play_matches) = matches.subcommand_matches("play") {
let file_path = play_matches.value_of("file");
let mime_type = match play_matches.value_of("mime_type") {
Some(s) => s.to_string(),
_ => return Err("MIME type is required.".into())
_ => {
if file_path.is_none() {
return Err("MIME type is required.".into());
}
match file_path.unwrap().split('.').last() {
Some("mkv") => "video/x-matroska".to_string(),
Some("mov") => "video/quicktime".to_string(),
Some("mp4") | Some("m4v") => "video/mp4".to_string(),
Some("mpg") | Some("mpeg") => "video/mpeg".to_string(),
Some("webm") => "video/webm".to_string(),
_ => return Err("MIME type is required.".into()),
}
}
};
let time = match play_matches.value_of("timestamp") {
@ -216,8 +230,6 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
}
).collect::<HashMap<String, String>>());
let file_path = play_matches.value_of("file");
let mut play_message = if let Some(file_path) = file_path {
match local_ip {
Some(lip) => {