Преглед изворни кода

Added to_uri function to spotify_id

Michael Pivonka пре 5 година
родитељ
комит
8939954bd7
1 измењених фајлова са 14 додато и 0 уклоњено
  1. 14 0
      core/src/spotify_id.rs

+ 14 - 0
core/src/spotify_id.rs

@@ -104,6 +104,20 @@ 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()
     }