Parcourir la source

Merge pull request #440 from tehcodedninja/SpotfyId-toURI

Ability to get the Spotify URI from a SpotifyId
Sasha Hilton il y a 4 ans
Parent
commit
dc99cd73c0
1 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 8 0
      core/src/spotify_id.rs

+ 8 - 0
core/src/spotify_id.rs

@@ -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()
     }