Added spotify URL parsing

This commit is contained in:
obito1903 2023-01-25 17:07:52 +01:00
parent 2387c64fe6
commit 58125236e1
4 changed files with 34 additions and 7 deletions

View file

@ -15,6 +15,7 @@ use librespot::playback::player::Player;
use librespot::metadata::{Album, Artist, Metadata, Track};
use regex::Regex;
use structopt::StructOpt;
use indicatif::{ProgressBar, ProgressStyle};
@ -142,7 +143,18 @@ async fn main() {
let mut tracks: Vec<SpotifyId> = Vec::new();
for track_url in opt.tracks {
let track = SpotifyId::from_uri(track_url.as_str()).unwrap();
let track = SpotifyId::from_uri(track_url.as_str()).unwrap_or_else(|_| {
let regex = Regex::new(r"https://open.spotify.com/(\w+)/(.*)\?").unwrap();
let results = regex.captures(track_url.as_str()).unwrap();
let uri = format!(
"spotify:{}:{}",
results.get(1).unwrap().as_str(),
results.get(2).unwrap().as_str()
);
SpotifyId::from_uri(&uri).unwrap()
});
match &track.audio_type {
librespot::core::spotify_id::SpotifyAudioType::Track => {
tracks.push(track);