Quellcode durchsuchen

Merge pull request #440 from tehcodedninja/SpotfyId-toURI

Ability to get the Spotify URI from a SpotifyId
Sasha Hilton vor 4 Jahren
Ursprung
Commit
dc99cd73c0
1 geänderte Dateien mit 8 neuen und 0 gelöschten Zeilen
  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()
     }