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

cleanup rspotify::model imports #620

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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