Spotify URL handling improvements (#320)

* Fixed regex for handling links via ctrl+v shortcut.
Fixed the whole url getting passed to get data on each link type instead of only the id.
Fixed MPRIS OpenUri function not handling an user&id in the link correctly.
This commit is contained in:
Bettehem
2020-11-15 20:17:15 +02:00
committed by GitHub
parent 9baed7ae98
commit e0cfc40639
2 changed files with 8 additions and 8 deletions

View File

@@ -579,28 +579,28 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
let spotify = self.queue.get_spotify();
let re =
Regex::new("https://open\\.spotify\\.com/(user/[^/]+/)?([a-z]+)/.+").unwrap();
Regex::new(r"https?://open\.spotify\.com/(user/[^/]+/)?(\S+)/(\S+)(\?si=\S+)?").unwrap();
let captures = re.captures(&url);
if let Some(captures) = captures {
let target: Option<Box<dyn ListItem>> = match &captures[2] {
"track" => spotify
.track(&url)
.track(&captures[3])
.map(|track| Track::from(&track).as_listitem()),
"album" => spotify
.album(&url)
.album(&captures[3])
.map(|album| Album::from(&album).as_listitem()),
"playlist" => spotify
.playlist(&url)
.playlist(&captures[3])
.map(|playlist| Playlist::from(&playlist).as_listitem()),
"artist" => spotify
.artist(&url)
.artist(&captures[3])
.map(|artist| Artist::from(&artist).as_listitem()),
"episode" => spotify
.episode(&url)
.episode(&captures[3])
.map(|episode| Episode::from(&episode).as_listitem()),
"show" => spotify
.get_show(&url)
.get_show(&captures[3])
.map(|show| Show::from(&show).as_listitem()),
_ => None,
};