MCPcopy Create free account
hub / github.com/Moosync/Moosync / validate_uri

Function validate_uri

src-tauri/librespot/src/player.rs:169–196  ·  view source on GitHub ↗
(val: &str)

Source from the content-addressed store, hash-verified

167
168#[tracing::instrument(level = "debug", skip(val))]
169fn validate_uri(val: &str) -> (Option<String>, Option<String>) {
170 let track_regex = Regex::new(
171 r"^(?P<urlType>(?:spotify:|(?:https?:\/\/(?:open|play)\.spotify\.com\/)))(?:embed)?\/?(?P<type>album|track|playlist|artist)(?::|\/)((?:[0-9a-zA-Z]){22})"
172 ).unwrap();
173 if let Some(captures) = track_regex.captures(val) {
174 if let Some(url_type) = captures.name("urlType") {
175 if let Some(match_type) = captures.name("type") {
176 if url_type.as_str().starts_with("https") {
177 if let Ok(parsed_url) = Url::parse(val) {
178 if let Some(last_segment) = parsed_url
179 .path_segments()
180 .and_then(|segments| segments.last())
181 {
182 return (
183 Some(format!("spotify:{}:{}", match_type.as_str(), last_segment)),
184 Some(match_type.as_str().to_string()),
185 );
186 }
187 }
188 } else {
189 return (Some(val.to_string()), Some(match_type.as_str().to_string()));
190 }
191 }
192 }
193 }
194
195 (None, None)
196}
197
198#[tracing::instrument(level = "debug", skip(track_uri, session))]
199pub fn get_canvas(track_uri: String, session: Session) -> Result<CanvazResponse> {

Callers 1

get_canvasFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected