mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
rs-terminal: fall back to default mime type when not provided or guessed
This commit is contained in:
parent
cfb30c62c7
commit
4ea7475c44
1 changed files with 11 additions and 9 deletions
|
@ -78,7 +78,6 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.long("mime_type")
|
.long("mime_type")
|
||||||
.value_name("MIME_TYPE")
|
.value_name("MIME_TYPE")
|
||||||
.help("Mime type (e.g., video/mp4)")
|
.help("Mime type (e.g., video/mp4)")
|
||||||
.required_unless_present("file")
|
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -246,21 +245,24 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if let Some(play_matches) = matches.subcommand_matches("play") {
|
if let Some(play_matches) = matches.subcommand_matches("play") {
|
||||||
let file_path = play_matches.value_of("file");
|
let file_path = play_matches.value_of("file");
|
||||||
|
|
||||||
|
fn default_mime_type() -> String {
|
||||||
|
println!("No mime type provided via the `--mime_type` argument. Using default (application/octet-stream)");
|
||||||
|
"application/octet-stream".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
let mime_type = match play_matches.value_of("mime_type") {
|
let mime_type = match play_matches.value_of("mime_type") {
|
||||||
Some(s) => s.to_string(),
|
Some(s) => s.to_string(),
|
||||||
_ => {
|
_ => match file_path {
|
||||||
if file_path.is_none() {
|
Some(path) => match path.split('.').next_back() {
|
||||||
return Err("MIME type is required.".into());
|
|
||||||
}
|
|
||||||
match file_path.unwrap().split('.').next_back() {
|
|
||||||
Some("mkv") => "video/x-matroska".to_string(),
|
Some("mkv") => "video/x-matroska".to_string(),
|
||||||
Some("mov") => "video/quicktime".to_string(),
|
Some("mov") => "video/quicktime".to_string(),
|
||||||
Some("mp4") | Some("m4v") => "video/mp4".to_string(),
|
Some("mp4") | Some("m4v") => "video/mp4".to_string(),
|
||||||
Some("mpg") | Some("mpeg") => "video/mpeg".to_string(),
|
Some("mpg") | Some("mpeg") => "video/mpeg".to_string(),
|
||||||
Some("webm") => "video/webm".to_string(),
|
Some("webm") => "video/webm".to_string(),
|
||||||
_ => return Err("MIME type is required.".into()),
|
_ => default_mime_type(),
|
||||||
}
|
},
|
||||||
}
|
None => default_mime_type(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let time = match play_matches.value_of("timestamp") {
|
let time = match play_matches.value_of("timestamp") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue