You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I am trying to get the duration of a file, without having the entire file. I know that this is bitrate / duration but I cannot figure out how to get the metadata of a parital file without getting unexpected end of stream.
/// Returns the length of an mp3 given the urlasyncfnget_content_length(url:&str) -> reqwest::Result<Duration>{let client = Client::new();let client_clone = client.clone();let url_owned = url.to_string();let content_length = tokio::spawn(asyncmove{let response = client_clone.get(url_owned).send().await;match response {Ok(r) => Ok(r
.headers().get(CONTENT_LENGTH).and_then(|val| val.to_str().ok()).and_then(|s| s.parse::<u32>().ok()).expect("content length in header")),Err(e) => Err(e),}});let url_owned = url.to_string();let file_part = tokio::spawn(asyncmove{Ok(client
.get(url_owned)// only grab first 64 kb// .header("Range", "bytes=0-64000").send().await?
.bytes())});println!("attempting to parse partial file to get bitrate");let codecs = symphonia::default::get_codecs();let probe = symphonia::default::get_probe();let cursor = Cursor::new(file_part.await.expect("to join")?.await?);let stream = MediaSourceStream::new(Box::new(cursor),MediaSourceStreamOptions::default());
probe
.format(&Hint::new().with_extension("mp3"),
stream,&FormatOptions::default(),&MetadataOptions::default(),).unwrap();println!("content_length = {}", content_length.await.unwrap()?);// to get compiler to be quietOk(Duration::from_secs(1))}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I am trying to get the duration of a file, without having the entire file. I know that this is bitrate / duration but I cannot figure out how to get the metadata of a parital file without getting unexpected end of stream.
Beta Was this translation helpful? Give feedback.
All reactions