From 1ffa03daaf6e54ab42d837304404d1f277b19c56 Mon Sep 17 00:00:00 2001 From: Bettehem Date: Fri, 17 May 2024 22:01:06 +0300 Subject: [PATCH] fix: support localized Spotify URLs (#1456) * fix: support localized Spotify URLs * Update changelog and format using cargo fmt --- CHANGELOG.md | 6 ++++++ src/spotify_url.rs | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b77f8d..46c6011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Handling localized Spotify URLs + ## [1.1.1] - 2024-05-10 ### Added diff --git a/src/spotify_url.rs b/src/spotify_url.rs index 4642e7c..1b5daa9 100644 --- a/src/spotify_url.rs +++ b/src/spotify_url.rs @@ -47,8 +47,11 @@ impl SpotifyUrl { let mut path_segments = url.path_segments()?; - let entity = path_segments.next()?; + let mut entity = path_segments.next()?; + if entity.to_lowercase().as_str().starts_with("intl-") { + entity = path_segments.next()? + } let uri_type = match entity.to_lowercase().as_str() { "album" => Some(UriType::Album), "artist" => Some(UriType::Artist), @@ -93,6 +96,10 @@ mod tests { "https://open.spotify.com/track/6fRJg3R90w0juYoCJXxj2d", SpotifyUrl::new("6fRJg3R90w0juYoCJXxj2d", UriType::Track), ); + test_cases.insert( + "https://open.spotify.com/intl-pt/track/3Kj2M9gRU1Lwf5eiNjBtBp", + SpotifyUrl::new("3Kj2M9gRU1Lwf5eiNjBtBp", UriType::Track), + ); test_cases.insert( "https://open.spotify.com/user/~villainy~/playlist/0OgoSs65CLDPn6AF6tsZVg", SpotifyUrl::new("0OgoSs65CLDPn6AF6tsZVg", UriType::Playlist),