Skip to content

Commit

Permalink
fix: support localized Spotify URLs (#1456)
Browse files Browse the repository at this point in the history
* fix: support localized Spotify URLs

* Update changelog and format using cargo fmt
  • Loading branch information
Bettehem authored May 17, 2024
1 parent 9b54ace commit 1ffa03d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/spotify_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 1ffa03d

Please sign in to comment.