Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for open.spotify.com links #392

Merged
merged 4 commits into from
Jan 17, 2021
Merged

Add support for open.spotify.com links #392

merged 4 commits into from
Jan 17, 2021

Conversation

Qluxzz
Copy link
Contributor

@Qluxzz Qluxzz commented Jan 15, 2021

Adds support for open.spotify.com link such as https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC

Same behaviour as with Spotify URI:s, paste them in the searchbar and press enter.

@hrkfdn hrkfdn force-pushed the master branch 8 times, most recently from c9fe357 to 6e0f008 Compare January 16, 2021 11:36
@Qluxzz
Copy link
Contributor Author

Qluxzz commented Jan 17, 2021

Oh wow, I just now saw that you'd already implemented similar functionality here:

ncspot/src/ui/listview.rs

Lines 644 to 700 in d9d6d68

Command::Insert(url) => {
let url = match url.as_ref().map(String::as_str) {
#[cfg(feature = "share_clipboard")]
Some("") | None => read_share().unwrap(),
Some(url) => url.to_owned(),
// do nothing if clipboard feature is disabled and there is no url provided
#[allow(unreachable_patterns)]
_ => return Ok(CommandResult::Consumed(None)),
};
let spotify = self.queue.get_spotify();
let re =
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(&captures[3])
.map(|track| Track::from(&track).as_listitem()),
"album" => spotify
.album(&captures[3])
.map(|album| Album::from(&album).as_listitem()),
"playlist" => spotify
.playlist(&captures[3])
.map(|playlist| Playlist::from(&playlist).as_listitem()),
"artist" => spotify
.artist(&captures[3])
.map(|artist| Artist::from(&artist).as_listitem()),
"episode" => spotify
.episode(&captures[3])
.map(|episode| Episode::from(&episode).as_listitem()),
"show" => spotify
.get_show(&captures[3])
.map(|show| Show::from(&show).as_listitem()),
_ => None,
};
let queue = self.queue.clone();
let library = self.library.clone();
// if item has a dedicated view, show it; otherwise open the context menu
if let Some(target) = target {
let view = target.open(queue.clone(), library.clone());
return match view {
Some(view) => Ok(CommandResult::View(view)),
None => {
let contextmenu = ContextMenu::new(target.as_ref(), queue, library);
Ok(CommandResult::Modal(Box::new(contextmenu)))
}
};
}
}
return Ok(CommandResult::Consumed(None));
}

@hrkfdn
Copy link
Owner

hrkfdn commented Jan 17, 2021

Right, this was implemented in #277. I think this should be merged somehow.

@Qluxzz
Copy link
Contributor Author

Qluxzz commented Jan 17, 2021

The insert command might need to be addressed in a separate PR.
Some media types only result in a box with share being the only option.
image

@hrkfdn hrkfdn merged commit ed0c62a into hrkfdn:master Jan 17, 2021
@hrkfdn
Copy link
Owner

hrkfdn commented Jan 17, 2021

Very nice, thank you for reiterating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants