Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
major:
- `clap` to `3.0.6`
- `rspotify*` to `0.11.3`
- `tui` to `0.16.0`

Handle nullable track ID in `rspotify::FullTrack`
  • Loading branch information
aome510 committed Jan 12, 2022
1 parent acb8b6b commit 561c7ae
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 292 deletions.
549 changes: 295 additions & 254 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions spotify_player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@ description = "A command driven spotify player"
repository = "https://github.com/aome510/spotify-player"
keywords = ["spotify", "tui", "player"]
readme = "../README.md"
include = ["src/**/*", "LICENSE", "../README.*"]

[dependencies]
anyhow = "1.0.45"
clap = "2.33.3"
anyhow = "1.0.52"
clap = "3.0.6"
config_parser2 = "0.1.2"
crossterm = { version = "0.22.1", features = ["event-stream"] }
dirs-next = "2.0.0"
librespot-connect = { version = "0.3.1", optional = true }
librespot-playback = { version = "0.3.1", optional = true }
librespot-core = "0.3.1"
log = "0.4.14"
lru = "0.7.0"
lru = "0.7.2"
chrono = "0.4.19"
reqwest = { version = "0.11.6", features = ["json"] }
reqwest = { version = "0.11.9", features = ["json"] }
rpassword = "5.0.1"
rspotify = "0.11.2"
serde = { version = "1.0.130", features = ["derive"] }
tokio = { version = "1.13.0", features = ["rt", "rt-multi-thread", "macros"] }
rspotify = "0.11.3"
serde = { version = "1.0.133", features = ["derive"] }
tokio = { version = "1.15.0", features = ["rt", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.8"
toml = "0.5.8"
tui = { version = "0.15.0", default-features = false, features = ["crossterm", "serde"] }
tui = { version = "0.16.0", default-features = false, features = ["crossterm", "serde"] }
unicode-width = "0.1.9"
rand = "0.8.4"
maybe-async = "0.2.6"
async-trait = "0.1.51"
async-trait = "0.1.52"
parking_lot = "0.11.2"
tracing = "0.1.29"
tracing-subscriber = { version = "0.3.1", features = ["env-filter"] }
tracing-subscriber = { version = "0.3.5", features = ["env-filter"] }

[features]
alsa-backend = ["streaming", "librespot-playback/alsa-backend"]
Expand Down
18 changes: 12 additions & 6 deletions spotify_player/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,17 @@ impl Client {

let (tracks, artists, albums, playlists) = (
match track_result {
rspotify_model::SearchResult::Tracks(p) => {
p.items.into_iter().map(|i| i.into()).collect()
}
rspotify_model::SearchResult::Tracks(p) => p
.items
.into_iter()
.map(Track::try_from_full_track)
.flatten()
.collect(),
_ => unreachable!(),
},
match artist_result {
rspotify_model::SearchResult::Artists(p) => {
p.items.into_iter().map(|i| i.into()).collect()
p.items.into_iter().map(|a| a.into()).collect()
}
_ => unreachable!(),
},
Expand Down Expand Up @@ -551,7 +554,9 @@ impl Client {
.await?
.into_iter()
.map(|item| match item.track {
Some(rspotify_model::PlayableItem::Track(track)) => Some(track.into()),
Some(rspotify_model::PlayableItem::Track(track)) => {
Track::try_from_full_track(track)
}
_ => None,
})
.flatten()
Expand Down Expand Up @@ -607,7 +612,8 @@ impl Client {
.artist_top_tracks(artist_id, &rspotify_model::enums::misc::Market::FromToken)
.await?
.into_iter()
.map(|t| t.into())
.map(Track::try_from_full_track)
.flatten()
.collect::<Vec<_>>();

let related_artists = self
Expand Down
7 changes: 3 additions & 4 deletions spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,9 @@ fn handle_global_command(
}
Command::ShowActionsOnCurrentTrack => {
if let Some(track) = state.player.read().current_playing_track() {
ui.popup = Some(PopupState::ActionList(
Item::Track(track.clone().into()),
new_list_state(),
));
if let Some(track) = Track::try_from_full_track(track.clone()) {
ui.popup = Some(PopupState::ActionList(Item::Track(track), new_list_state()));
}
}
}
Command::BrowsePlayingContext => {
Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl KeySequence {
return None;
}
keys.into_iter()
.map(|s| Key::from_str(s))
.map(Key::from_str)
.collect::<Option<Vec<_>>>()
.map(|keys| Self { keys })
}
Expand Down
14 changes: 7 additions & 7 deletions spotify_player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ mod token;
mod ui;
mod utils;

fn init_app_cli_arguments() -> clap::ArgMatches<'static> {
fn init_app_cli_arguments() -> clap::ArgMatches {
clap::App::new("spotify-player")
.version("0.5.1")
.about("A command driven spotify player")
.author("Thang Pham <phamducthang1234@gmail>")
.arg(
clap::Arg::with_name("theme")
.short("t")
clap::Arg::new("theme")
.short('t')
.long("theme")
.value_name("THEME")
.help("Application theme (default: dracula)")
)
.arg(
clap::Arg::with_name("config-folder")
.short("c")
clap::Arg::new("config-folder")
.short('c')
.long("config-folder")
.value_name("FOLDER")
.help("Path to the application's config folder (default: $HOME/.config/spotify-player)")
.next_line_help(true)
)
.arg(
clap::Arg::with_name("cache-folder")
.short("C")
clap::Arg::new("cache-folder")
.short('C')
.long("cache-folder")
.value_name("FOLDER")
.help("Path to the application's cache folder (default: $HOME/.cache/spotify-player)")
Expand Down
12 changes: 6 additions & 6 deletions spotify_player/src/state/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,18 @@ impl Track {
added_at: 0,
})
}
}

impl From<rspotify_model::FullTrack> for Track {
fn from(track: rspotify_model::FullTrack) -> Self {
Self {
id: track.id,
/// tries to convert from a `rspotify_model::FullTrack` into `Track`
pub fn try_from_full_track(track: rspotify_model::FullTrack) -> Option<Self> {
track.id.as_ref()?;
Some(Self {
id: track.id.unwrap(),
name: track.name,
artists: from_simplified_artists_to_artists(track.artists),
album: Album::try_from_simplified_album(track.album),
duration: track.duration,
added_at: 0,
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/state/ui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::model::*;
use crate::{config, key, utils};

use tui::widgets::{ListState, TableState};
use tui::widgets::*;

pub type UIStateGuard<'a> = parking_lot::MutexGuard<'a, UIState>;

Expand Down
3 changes: 2 additions & 1 deletion spotify_player/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ pub fn render_track_table_widget(
let mut active_desc = "";
if let Some(ref playback) = state.player.read().playback {
if let Some(rspotify_model::PlayableItem::Track(ref track)) = playback.item {
playing_track_uri = track.id.uri();
playing_track_uri = track.id.as_ref().map(|id| id.uri()).unwrap_or_default();

active_desc = if !playback.is_playing { "⏸" } else { "▶" };
}
}
Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tui::widgets::{ListState, TableState};
use tui::widgets::*;
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};

/// formats a time duration into a "{minutes}:{seconds}" format
Expand Down

0 comments on commit 561c7ae

Please sign in to comment.