From 0ae9d89f18bf36407229798a3b4943604fb708e4 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 27 May 2026 20:46:33 +0200 Subject: Add internet streams support --- src/queue.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/queue.rs') diff --git a/src/queue.rs b/src/queue.rs index fc30c86..1742a00 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -87,10 +87,15 @@ pub struct Track { pub artist: Option, pub album: Option, pub duration_secs: Option, + pub is_stream: bool, } impl Track { pub fn from_path(path: PathBuf) -> Self { + let path_str = path.to_string_lossy(); + if path_str.starts_with("http://") || path_str.starts_with("https://") { + return Track::from_url(&path_str); + } let metadata = extract_metadata(&path); let metadata = metadata.as_ref(); Track { @@ -99,6 +104,31 @@ impl Track { artist: metadata.and_then(|m| m.artist.clone()), album: metadata.and_then(|m| m.album.clone()), duration_secs: metadata.and_then(|m| m.duration_secs), + is_stream: false, + } + } + + pub fn from_url(url: &str) -> Self { + let clean_url = url.split('?').next().unwrap_or(url); + let url_path = Path::new(clean_url); + let title = url_path + .file_stem() + .and_then(|s| s.to_str()) + .map(|s| s.to_string()) + .or_else(|| { + url_path + .file_name() + .and_then(|s| s.to_str()) + .map(|s| s.to_string()) + }) + .unwrap_or_else(|| url.to_string()); + Track { + path: PathBuf::from(url), + title: Some(title), + artist: None, + album: None, + duration_secs: None, + is_stream: true, } } -- cgit v1.2.3