Fetch album if input is album url
extern crate unicode_width;
-use super::super::app::{ActiveBlock, App, RouteId};
+use super::super::app::{ActiveBlock, AlbumTableContext, App, RouteId, SelectedFullAlbum};
use crate::event::Key;
use rspotify::spotify::senum::Country;
use std::convert::TryInto;
@@ -48,6 +48,32 @@ pub fn handler(key: Key, app: &mut App) {
let country =
Country::from_str(&user.country.unwrap_or_else(|| "".to_string())).ok();
let input_str: String = app.input.iter().collect();
+
+ let album_url_prefix = "https://open.spotify.com/album/";
+
+ if input_str.starts_with(album_url_prefix) {
+ let album_id = input_str.trim_start_matches(album_url_prefix);
+ match spotify.album(&album_id) {
+ Ok(album) => {
+ let selected_album = SelectedFullAlbum {
+ album,
+ selected_index: 0,
+ };
+
+ app.selected_album_full = Some(selected_album);
+ app.album_table_context = AlbumTableContext::Full;
+ app.push_navigation_stack(
+ RouteId::AlbumTracks,
+ ActiveBlock::AlbumTracks,
+ )
+ }
+ Err(e) => {
+ app.handle_error(e);
+ }
+ }
+ return;
+ }
+
// Can I run these functions in parellel?
match spotify.search_track(&input_str, app.small_search_limit, 0, country) {
Ok(result) => {
