1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 01:39:28 +02:00

Make SpotifyId understand more URI formats

This commit is contained in:
ashthespy 2019-10-09 19:49:13 +02:00
parent 6786c093ad
commit b96405af82
3 changed files with 42 additions and 19 deletions

View file

@ -5,6 +5,7 @@ use std::fmt;
pub enum SpotifyAudioType {
Track,
Podcast,
NonPlayable,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@ -71,12 +72,18 @@ impl SpotifyId {
pub fn from_uri(uri: &str) -> Result<SpotifyId, SpotifyIdError> {
let parts = uri.split(":").collect::<Vec<&str>>();
if uri.contains(":show:") || uri.contains(":episode:") {
let mut spotify_id = SpotifyId::from_base62(parts[2]).unwrap();
let gid = parts.last().unwrap();
if uri.contains(":episode:") {
let mut spotify_id = SpotifyId::from_base62(gid).unwrap();
let _ = std::mem::replace(&mut spotify_id.audio_type, SpotifyAudioType::Podcast);
Ok(spotify_id)
} else if uri.contains(":track:") {
SpotifyId::from_base62(gid)
} else {
SpotifyId::from_base62(parts[2])
// show/playlist/artist/album/??
let mut spotify_id = SpotifyId::from_base62(gid).unwrap();
let _ = std::mem::replace(&mut spotify_id.audio_type, SpotifyAudioType::NonPlayable);
Ok(spotify_id)
}
}