diff --git a/src/client.rs b/src/client.rs index cf9f161..24dbbd1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -111,8 +111,8 @@ impl State { // I consider a missing path as fatal... there is absolutely nothing we can do about it // and we need all files from the playlist. - let path_and_query = uri.path_and_query().expect("No path and query").as_str(); - let filename = Path::new(path_and_query) + let path = uri.path(); + let filename = Path::new(path) . file_name() . expect("no filename in path_and_query"); let mut file = File::create(filename).await @@ -163,17 +163,19 @@ impl State { } } - fn uri_relative_path_and_query(uri: &Uri) -> anyhow::Result + fn uri_relative_path(uri: &Uri) -> anyhow::Result { - let filename = Path::new(uri.path()) + Self::relative_path(uri.path()) + } + + fn relative_path(path: &str) -> anyhow::Result + { + let filename = Path::new(path) . file_name() . ok_or(anyhow!("name error"))? . to_str() . ok_or(anyhow!("Error getting filename from uri"))?; - let query = uri.query() - . map(|q| "?".to_owned() + q) - . unwrap_or("".to_string()); - Ok((filename.to_owned() + &query).to_string()) + Ok(filename.to_string()) } async fn request(&mut self, uri: &Uri) -> anyhow::Result> @@ -198,11 +200,17 @@ impl State { let mut new_segment = s.clone(); Ok(match Uri::try_from(s.uri.clone()) { Ok(uri) => { - new_segment.uri = Self::uri_relative_path_and_query(&uri)?; + new_segment.uri = Self::uri_relative_path(&uri)?; new_segment } - Err(_) => new_segment + Err(_) => { + let uri = s.uri.split_once('?') + . map(|(s,_)| s) + . unwrap_or(&s.uri); + new_segment.uri = Self::relative_path(uri)?; + new_segment + } }) }).collect();