Explorar o código

Merge pull request #440 from tehcodedninja/SpotfyId-toURI

Ability to get the Spotify URI from a SpotifyId
Sasha Hilton %!s(int64=4) %!d(string=hai) anos
pai
achega
dc99cd73c0
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  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()
     }