aboutsummaryrefslogtreecommitdiffstats
path: root/src/queue.rs
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-05-27 20:46:33 +0200
committersalmonik <raisersoft@proton.me>2026-05-27 20:46:33 +0200
commit0ae9d89f18bf36407229798a3b4943604fb708e4 (patch)
tree47fbc6ad1d22ddd575f9773d5e1d36dae7bd0815 /src/queue.rs
parentplay [track] [-a/--album] option (diff)
downloadrsplayer-0ae9d89f18bf36407229798a3b4943604fb708e4.tar.gz
rsplayer-0ae9d89f18bf36407229798a3b4943604fb708e4.zip
Add internet streams support
Diffstat (limited to '')
-rw-r--r--src/queue.rs30
1 files changed, 30 insertions, 0 deletions
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 {
87 pub artist: Option<String>, 87 pub artist: Option<String>,
88 pub album: Option<String>, 88 pub album: Option<String>,
89 pub duration_secs: Option<f64>, 89 pub duration_secs: Option<f64>,
90 pub is_stream: bool,
90} 91}
91 92
92impl Track { 93impl Track {
93 pub fn from_path(path: PathBuf) -> Self { 94 pub fn from_path(path: PathBuf) -> Self {
95 let path_str = path.to_string_lossy();
96 if path_str.starts_with("http://") || path_str.starts_with("https://") {
97 return Track::from_url(&path_str);
98 }
94 let metadata = extract_metadata(&path); 99 let metadata = extract_metadata(&path);
95 let metadata = metadata.as_ref(); 100 let metadata = metadata.as_ref();
96 Track { 101 Track {
@@ -99,6 +104,31 @@ impl Track {
99 artist: metadata.and_then(|m| m.artist.clone()), 104 artist: metadata.and_then(|m| m.artist.clone()),
100 album: metadata.and_then(|m| m.album.clone()), 105 album: metadata.and_then(|m| m.album.clone()),
101 duration_secs: metadata.and_then(|m| m.duration_secs), 106 duration_secs: metadata.and_then(|m| m.duration_secs),
107 is_stream: false,
108 }
109 }
110
111 pub fn from_url(url: &str) -> Self {
112 let clean_url = url.split('?').next().unwrap_or(url);
113 let url_path = Path::new(clean_url);
114 let title = url_path
115 .file_stem()
116 .and_then(|s| s.to_str())
117 .map(|s| s.to_string())
118 .or_else(|| {
119 url_path
120 .file_name()
121 .and_then(|s| s.to_str())
122 .map(|s| s.to_string())
123 })
124 .unwrap_or_else(|| url.to_string());
125 Track {
126 path: PathBuf::from(url),
127 title: Some(title),
128 artist: None,
129 album: None,
130 duration_secs: None,
131 is_stream: true,
102 } 132 }
103 } 133 }
104 134