Merge pull request #440 from tehcodedninja/SpotfyId-toURI

Ability to get the Spotify URI from a SpotifyId
This commit is contained in:
Sasha Hilton 2020-07-25 03:19:44 +01:00 committed by GitHub
commit dc99cd73c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -104,6 +104,14 @@ impl SpotifyId {
std::str::from_utf8(&data).unwrap().to_owned()
}
pub fn to_uri(&self) -> String {
match self.audio_type {
SpotifyAudioType::Track => format!("spotify:track:{}", self.to_base62()),
SpotifyAudioType::Podcast => format!("spotify:episode:{}", self.to_base62()),
SpotifyAudioType::NonPlayable => format!("spotify:unknown:{}", self.to_base62()),
}
}
pub fn to_raw(&self) -> [u8; 16] {
self.id.to_be_bytes()
}