Skip to content

Commit

Permalink
cleanup rspotify::model imports (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
aome510 authored Nov 30, 2024
1 parent 9fc65c6 commit 29a1524
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 195 deletions.
29 changes: 13 additions & 16 deletions spotify_player/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ use crate::{
cli::Request,
client::{Client, PlayerRequest},
config::get_cache_folder_path,
state::{Context, ContextId, Playback, PlaybackMetadata, SharedState},
};
use rspotify::{
model::{
AlbumId, ArtistId, CurrentPlaybackContext, Id, PlayableId, PlaylistId, SearchResult,
SearchType, TrackId,
state::{
AlbumId, ArtistId, Context, ContextId, Id, PlayableId, Playback, PlaybackMetadata,
PlaylistId, SharedState, TrackId,
},
prelude::{BaseClient, OAuthClient},
};
use rspotify::prelude::{BaseClient, OAuthClient};

use super::{
Command, Deserialize, GetRequest, IdOrName, ItemId, ItemType, Key, PlaylistCommand, Response,
Expand Down Expand Up @@ -96,7 +93,7 @@ async fn send_response(
async fn current_playback(
client: &Client,
state: Option<&SharedState>,
) -> Result<Option<CurrentPlaybackContext>> {
) -> Result<Option<rspotify::model::CurrentPlaybackContext>> {
// get current playback from the application's state, if exists, or by making an API request
match state {
Some(state) => Ok(state.player.read().current_playback()),
Expand Down Expand Up @@ -230,11 +227,11 @@ async fn get_spotify_id(client: &Client, typ: ItemType, id_or_name: IdOrName) ->
IdOrName::Id(id) => ItemId::Playlist(PlaylistId::from_id(id)?),
IdOrName::Name(name) => {
let results = client
.search_specific_type(&name, SearchType::Playlist)
.search_specific_type(&name, rspotify::model::SearchType::Playlist)
.await?;

match results {
SearchResult::Playlists(page) => {
rspotify::model::SearchResult::Playlists(page) => {
if page.items.is_empty() {
anyhow::bail!("Cannot find playlist with name='{name}'");
}
Expand All @@ -248,11 +245,11 @@ async fn get_spotify_id(client: &Client, typ: ItemType, id_or_name: IdOrName) ->
IdOrName::Id(id) => ItemId::Album(AlbumId::from_id(id)?),
IdOrName::Name(name) => {
let results = client
.search_specific_type(&name, SearchType::Album)
.search_specific_type(&name, rspotify::model::SearchType::Album)
.await?;

match results {
SearchResult::Albums(page) => {
rspotify::model::SearchResult::Albums(page) => {
if !page.items.is_empty() && page.items[0].id.is_some() {
ItemId::Album(page.items[0].id.clone().unwrap())
} else {
Expand All @@ -267,11 +264,11 @@ async fn get_spotify_id(client: &Client, typ: ItemType, id_or_name: IdOrName) ->
IdOrName::Id(id) => ItemId::Artist(ArtistId::from_id(id)?),
IdOrName::Name(name) => {
let results = client
.search_specific_type(&name, SearchType::Artist)
.search_specific_type(&name, rspotify::model::SearchType::Artist)
.await?;

match results {
SearchResult::Artists(page) => {
rspotify::model::SearchResult::Artists(page) => {
if page.items.is_empty() {
anyhow::bail!("Cannot find artist with name='{name}'");
}
Expand All @@ -285,11 +282,11 @@ async fn get_spotify_id(client: &Client, typ: ItemType, id_or_name: IdOrName) ->
IdOrName::Id(id) => ItemId::Track(TrackId::from_id(id)?),
IdOrName::Name(name) => {
let results = client
.search_specific_type(&name, SearchType::Track)
.search_specific_type(&name, rspotify::model::SearchType::Track)
.await?;

match results {
SearchResult::Tracks(page) => {
rspotify::model::SearchResult::Tracks(page) => {
if !page.items.is_empty() && page.items[0].id.is_some() {
ItemId::Track(page.items[0].id.clone().unwrap())
} else {
Expand Down
5 changes: 2 additions & 3 deletions spotify_player/src/client/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Context;
use rspotify::model::PlayableItem;
use tracing::Instrument;

use crate::{
Expand Down Expand Up @@ -54,13 +53,13 @@ fn handle_playback_change_event(
player.buffered_playback.as_ref(),
player.currently_playing(),
) {
(Some(playback), Some(PlayableItem::Track(track))) => (
(Some(playback), Some(rspotify::model::PlayableItem::Track(track))) => (
playback,
PlayableId::Track(track.id.clone().expect("null track_id")),
&track.name,
track.duration,
),
(Some(playback), Some(PlayableItem::Episode(episode))) => (
(Some(playback), Some(rspotify::model::PlayableItem::Episode(episode))) => (
playback,
PlayableId::Episode(episode.id.clone()),
&episode.name,
Expand Down
Loading

0 comments on commit 29a1524

Please sign in to comment.