diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bdfbe23..cab83b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,10 +65,12 @@ jobs: - name: Build ${{ matrix.target }} uses: actions-rs/cargo@v1 env: + PKG_CONFIG_ALLOW_CROSS: 1 SQLITE3_STATIC: true PKG_CONFIG_ALL_STATIC: true DATABASE_URL: "sqlite:///tmp/data.db" with: + use-cross: true command: build args: --bin hifi-rs --release --target=${{ matrix.target }} - name: Tar hifi-rs-${{ matrix.target }}.tar.gz diff --git a/hifirs/src/cli.rs b/hifirs/src/cli.rs index 97de97b..f2e60d6 100644 --- a/hifirs/src/cli.rs +++ b/hifirs/src/cli.rs @@ -321,7 +321,7 @@ pub async fn run() -> Result<(), Error> { } => { let client = qobuz::make_client(cli.username.as_deref(), cli.password.as_deref()).await?; - let results = client.search_all(query, limit.unwrap_or_default()).await?; + let results = client.search_all(&query, limit.unwrap_or_default()).await?; output!(results, output_format); @@ -334,7 +334,7 @@ pub async fn run() -> Result<(), Error> { } => { let client = qobuz::make_client(cli.username.as_deref(), cli.password.as_deref()).await?; - let results = client.search_albums(query.clone(), limit).await?; + let results = client.search_albums(&query, limit).await?; output!(results, output_format); @@ -347,7 +347,7 @@ pub async fn run() -> Result<(), Error> { } => { let client = qobuz::make_client(cli.username.as_deref(), cli.password.as_deref()).await?; - let results = client.search_artists(query.clone(), limit).await?; + let results = client.search_artists(&query, limit).await?; output!(results, output_format); diff --git a/hifirs/src/cursive/mod.rs b/hifirs/src/cursive/mod.rs index d3ddb4f..94bcdc0 100644 --- a/hifirs/src/cursive/mod.rs +++ b/hifirs/src/cursive/mod.rs @@ -959,7 +959,7 @@ pub async fn receive_notifications() { set_current_track(s, first.1, list.list_type()); } - entity_title.set_content(playlist.title.clone()); + entity_title.set_content(&playlist.title); total_tracks.set_content(format!("{:03}", list.total())); } diff --git a/hifirs/src/mpris.rs b/hifirs/src/mpris.rs index 6ef1c3c..2ebea11 100644 --- a/hifirs/src/mpris.rs +++ b/hifirs/src/mpris.rs @@ -177,8 +177,8 @@ pub async fn receive_notifications(conn: Connection) { let tracks = list .cursive_list() .iter() - .map(|t| t.0.clone()) - .collect::>(); + .map(|t| t.0) + .collect::>(); MprisTrackList::track_list_replaced( list_ref.signal_context(), @@ -397,7 +397,7 @@ impl MprisTrackList { #[dbus_interface(signal, name = "TrackListReplaced")] pub async fn track_list_replaced( #[zbus(signal_context)] ctxt: &SignalContext<'_>, - tracks: Vec, + tracks: Vec<&str>, current: &str, ) -> zbus::Result<()>; diff --git a/hifirs/src/player/queue/controls.rs b/hifirs/src/player/queue/controls.rs index b5e0a9e..b2aebe2 100644 --- a/hifirs/src/player/queue/controls.rs +++ b/hifirs/src/player/queue/controls.rs @@ -73,7 +73,7 @@ impl PlayerState { debug!("setting up album to play"); if let Some(album) = self.service.album(album_id.as_str()).await { - let mut tracklist = TrackListValue::new(Some(album.tracks.clone())); + let mut tracklist = TrackListValue::new(Some(&album.tracks)); tracklist.set_album(album); tracklist.set_list_type(TrackListType::Album); tracklist.set_track_status(1, TrackStatus::Playing); @@ -105,7 +105,7 @@ impl PlayerState { let mut queue = BTreeMap::new(); queue.entry(track.position).or_insert_with(|| track.clone()); - let mut tracklist = TrackListValue::new(Some(queue)); + let mut tracklist = TrackListValue::new(Some(&queue)); tracklist.set_list_type(TrackListType::Track); self.replace_list(tracklist.clone()); @@ -123,7 +123,7 @@ impl PlayerState { debug!("setting up playlist to play"); if let Some(playlist) = self.service.playlist(playlist_id).await { - let mut tracklist = TrackListValue::new(Some(playlist.tracks.clone())); + let mut tracklist = TrackListValue::new(Some(&playlist.tracks)); tracklist.set_playlist(playlist); tracklist.set_list_type(TrackListType::Playlist); @@ -332,7 +332,7 @@ impl PlayerState { match entity_type { TrackListType::Album => { if let Some(album) = self.service.album(&last_state.playback_entity_id).await { - self.replace_list(TrackListValue::new(Some(album.tracks.clone()))); + self.replace_list(TrackListValue::new(Some(&album.tracks))); self.tracklist.set_list_type(TrackListType::Album); self.tracklist.set_album(album); @@ -355,7 +355,7 @@ impl PlayerState { ) .await { - self.replace_list(TrackListValue::new(Some(playlist.tracks.clone()))); + self.replace_list(TrackListValue::new(Some(&playlist.tracks))); self.tracklist.set_list_type(TrackListType::Playlist); self.tracklist.set_playlist(playlist); @@ -379,7 +379,7 @@ impl PlayerState { let mut queue = BTreeMap::new(); queue.entry(track.position).or_insert_with(|| track); - let mut tracklist = TrackListValue::new(Some(queue)); + let mut tracklist = TrackListValue::new(Some(&queue)); tracklist.set_list_type(TrackListType::Track); self.replace_list(tracklist); diff --git a/hifirs/src/player/queue/mod.rs b/hifirs/src/player/queue/mod.rs index 37176de..59fa5ad 100644 --- a/hifirs/src/player/queue/mod.rs +++ b/hifirs/src/player/queue/mod.rs @@ -55,15 +55,9 @@ pub struct TrackListValue { impl TrackListValue { #[instrument] - pub fn new(queue: Option>) -> TrackListValue { - let queue = if let Some(q) = queue { - q - } else { - BTreeMap::new() - }; - + pub fn new(queue: Option<&BTreeMap>) -> TrackListValue { TrackListValue { - queue, + queue: queue.unwrap_or(&BTreeMap::new()).clone(), album: None, playlist: None, list_type: TrackListType::Unknown, @@ -194,10 +188,10 @@ impl TrackListValue { .find(|&track| track.status == TrackStatus::Playing) } - pub fn cursive_list(&self) -> Vec<(String, i32)> { + pub fn cursive_list(&self) -> Vec<(&str, i32)> { self.queue .values() - .map(|i| (i.title.clone(), i.id as i32)) - .collect::>() + .map(|i| (i.title.as_str(), i.id as i32)) + .collect::>() } } diff --git a/hifirs/src/qobuz/album.rs b/hifirs/src/qobuz/album.rs index 6b96421..7443a09 100644 --- a/hifirs/src/qobuz/album.rs +++ b/hifirs/src/qobuz/album.rs @@ -51,3 +51,9 @@ impl From for Album { } } } + +impl From<&QobuzAlbum> for Album { + fn from(value: &QobuzAlbum) -> Self { + value.clone().into() + } +} diff --git a/hifirs/src/qobuz/mod.rs b/hifirs/src/qobuz/mod.rs index 54f3c57..a54d99e 100644 --- a/hifirs/src/qobuz/mod.rs +++ b/hifirs/src/qobuz/mod.rs @@ -51,7 +51,7 @@ impl MusicService for QobuzClient { } async fn search(&self, query: &str) -> Option { - match self.search_all(query.to_string(), 100).await { + match self.search_all(query, 100).await { Ok(results) => Some(results.into()), Err(_) => None, } diff --git a/hifirs/src/qobuz/track.rs b/hifirs/src/qobuz/track.rs index d09a028..210ca40 100644 --- a/hifirs/src/qobuz/track.rs +++ b/hifirs/src/qobuz/track.rs @@ -4,7 +4,7 @@ use hifirs_qobuz_api::client::track::Track as QobuzTrack; impl From for Track { fn from(value: QobuzTrack) -> Self { let album = value.album.as_ref().map(|a| { - let album: Album = a.clone().into(); + let album: Album = a.into(); album }); @@ -47,3 +47,9 @@ impl From for Track { } } } + +impl From<&QobuzTrack> for Track { + fn from(value: &QobuzTrack) -> Self { + value.clone().into() + } +} diff --git a/hifirs/src/service.rs b/hifirs/src/service.rs index 4baa9b9..f2601bd 100644 --- a/hifirs/src/service.rs +++ b/hifirs/src/service.rs @@ -139,10 +139,10 @@ impl CursiveFormat for Album { style = style.combine(Effect::Dim).combine(Effect::Strikethrough); } - let mut title = StyledString::styled(self.title.clone(), style.combine(Effect::Bold)); + let mut title = StyledString::styled(self.title.as_str(), style.combine(Effect::Bold)); title.append_styled(" by ", style); - title.append_styled(self.artist.name.clone(), style); + title.append_styled(self.artist.name.as_str(), style); title.append_styled(" ", style); title.append_styled(self.release_year.to_string(), style.combine(Effect::Dim)); @@ -189,6 +189,6 @@ pub struct Playlist { impl CursiveFormat for Artist { fn list_item(&self) -> StyledString { - StyledString::plain(self.name.clone()) + StyledString::plain(self.name.as_str()) } } diff --git a/hifirs/src/sql/db.rs b/hifirs/src/sql/db.rs index a783e00..a76dcac 100755 --- a/hifirs/src/sql/db.rs +++ b/hifirs/src/sql/db.rs @@ -19,7 +19,7 @@ pub async fn init() { url.push("hifi-rs"); if !url.exists() { - std::fs::create_dir_all(url.clone()).expect("failed to create database directory"); + std::fs::create_dir_all(&url).expect("failed to create database directory"); } url.push("data.db"); @@ -85,7 +85,7 @@ pub async fn set_password(password: String) { } } -pub async fn set_user_token(token: String) { +pub async fn set_user_token(token: &String) { if let Ok(mut conn) = acquire!() { query!( r#" @@ -99,7 +99,7 @@ pub async fn set_user_token(token: String) { } } -pub async fn set_app_id(id: String) { +pub async fn set_app_id(id: &String) { if let Ok(mut conn) = acquire!() { query!( r#" @@ -113,7 +113,7 @@ pub async fn set_app_id(id: String) { } } -pub async fn set_active_secret(secret: String) { +pub async fn set_active_secret(secret: &String) { if let Ok(mut conn) = acquire!() { query!( r#" diff --git a/playlist-sync/src/cli.rs b/playlist-sync/src/cli.rs index 274a043..4899097 100644 --- a/playlist-sync/src/cli.rs +++ b/playlist-sync/src/cli.rs @@ -110,7 +110,7 @@ pub async fn run() -> Result<(), Error> { if let (Some(isrc), Some(track_position)) = (existing_track.isrc, existing_track.position) { - let results = qobuz.search(isrc.to_lowercase()).await; + let results = qobuz.search(&isrc.to_lowercase()).await; if !results.is_empty() { if let Some(found) = results.get(0) { qobuz @@ -147,7 +147,7 @@ pub async fn run() -> Result<(), Error> { for missing in missing_tracks { if let Some(isrc) = missing.track.external_ids.get("isrc") { - let results = qobuz.search(isrc.to_lowercase()).await; + let results = qobuz.search(&isrc.to_lowercase()).await; if !results.is_empty() { if let Some(found) = results.get(0) { qobuz diff --git a/playlist-sync/src/qobuz.rs b/playlist-sync/src/qobuz.rs index 1f1f66c..363563a 100644 --- a/playlist-sync/src/qobuz.rs +++ b/playlist-sync/src/qobuz.rs @@ -45,9 +45,9 @@ impl<'q> Qobuz<'q> { Ok(QobuzPlaylist(playlist)) } - pub async fn search(&self, query: String) -> Vec { + pub async fn search(&self, query: &str) -> Vec { self.progress.set_message(format!("{query} searching")); - let results = self.client.search_all(query.clone(), 100).await.unwrap(); + let results = self.client.search_all(query, 100).await.unwrap(); if results.tracks.items.is_empty() { self.progress.set_message(format!("{query} not found")); diff --git a/qobuz-api/src/client/api.rs b/qobuz-api/src/client/api.rs index 26dc7f4..887e060 100644 --- a/qobuz-api/src/client/api.rs +++ b/qobuz-api/src/client/api.rs @@ -17,7 +17,7 @@ use reqwest::{ }; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::collections::HashMap; +use std::{collections::HashMap, fmt::Display}; const BUNDLE_REGEX: &str = r#""#; @@ -106,9 +106,9 @@ enum Endpoint { Search, } -impl Endpoint { - fn as_str(&self) -> &str { - match self { +impl Display for Endpoint { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let endpoint = match self { Endpoint::Album => "album/get", Endpoint::Artist => "artist/get", Endpoint::Login => "user/login", @@ -124,7 +124,9 @@ impl Endpoint { Endpoint::Track => "track/get", Endpoint::TrackURL => "track/getFileUrl", Endpoint::UserPlaylist => "playlist/getUserPlaylists", - } + }; + + f.write_str(endpoint) } } @@ -161,8 +163,8 @@ macro_rules! post { } impl Client { - pub fn quality(&self) -> AudioQuality { - self.default_quality.clone() + pub fn quality(&self) -> &AudioQuality { + &self.default_quality } pub fn signed_in(&self) -> bool { @@ -171,7 +173,7 @@ impl Client { /// Login a user pub async fn login(&mut self, username: &str, password: &str) -> Result<()> { - let endpoint = format!("{}{}", self.base_url, Endpoint::Login.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::Login); if let Some(app_id) = &self.app_id { info!( @@ -185,7 +187,7 @@ impl Client { ("app_id", app_id.as_str()), ]; - match self.make_get_call(endpoint, Some(params)).await { + match self.make_get_call(&endpoint, Some(¶ms)).await { Ok(response) => { let json: Value = serde_json::from_str(response.as_str()).unwrap(); info!("Successfully logged in"); @@ -208,15 +210,15 @@ impl Client { /// Retrieve a list of the user's playlists pub async fn user_playlists(&self) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::UserPlaylist.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::UserPlaylist); let params = vec![("limit", "500"), ("extra", "tracks"), ("offset", "0")]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } /// Retrieve a playlist pub async fn playlist(&self, playlist_id: i64) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::Playlist.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::Playlist); let id_string = playlist_id.to_string(); let params = vec![ ("limit", "500"), @@ -224,16 +226,12 @@ impl Client { ("playlist_id", id_string.as_str()), ("offset", "0"), ]; - let playlist: Result = get!(self, endpoint.clone(), Some(params.clone())); + let playlist: Result = get!(self, &endpoint, Some(¶ms)); if let Ok(mut playlist) = playlist { - if let Ok(all_items_playlist) = self.playlist_items(&mut playlist, endpoint).await { - Ok(all_items_playlist.clone()) - } else { - Err(Error::Api { - message: "error fetching playlist".to_string(), - }) - } + self.playlist_items(&mut playlist, &endpoint).await?; + + Ok(playlist) } else { Err(Error::Api { message: "error fetching playlist".to_string(), @@ -241,21 +239,14 @@ impl Client { } } - async fn playlist_items<'p>( - &self, - playlist: &'p mut Playlist, - endpoint: String, - ) -> Result<&'p Playlist> { + async fn playlist_items<'p>(&self, playlist: &'p mut Playlist, endpoint: &str) -> Result<()> { let total_tracks = playlist.tracks_count as usize; - let mut all_tracks: Vec = Vec::new(); - if let Some(mut tracks) = playlist.tracks.clone() { - all_tracks.append(&mut tracks.items); - - while all_tracks.len() < total_tracks { + if let Some(tracks) = playlist.tracks.as_mut() { + while tracks.items.len() < total_tracks { let id = playlist.id.to_string(); - let limit_string = (total_tracks - all_tracks.len()).to_string(); - let offset_string = all_tracks.len().to_string(); + let limit_string = (total_tracks - tracks.items.len()).to_string(); + let offset_string = tracks.items.len().to_string(); let params = vec![ ("limit", limit_string.as_str()), @@ -264,26 +255,21 @@ impl Client { ("offset", offset_string.as_str()), ]; - let playlist: Result = get!(self, endpoint.clone(), Some(params)); + let playlist: Result = get!(self, endpoint, Some(¶ms)); match &playlist { Ok(playlist) => { debug!("appending tracks to playlist"); if let Some(new_tracks) = &playlist.tracks { - all_tracks.append(&mut new_tracks.clone().items); + tracks.items.append(&mut new_tracks.clone().items); } } Err(error) => error!("{}", error.to_string()), } } - - if !all_tracks.is_empty() { - tracks.items = all_tracks; - playlist.set_tracks(tracks); - } } - Ok(playlist) + Ok(()) } pub async fn create_playlist( @@ -293,7 +279,7 @@ impl Client { description: Option, is_collaborative: Option, ) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistCreate.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistCreate); let mut form_data = HashMap::new(); form_data.insert("name", name.as_str()); @@ -318,16 +304,16 @@ impl Client { }; form_data.insert("description", description.as_str()); - post!(self, endpoint, form_data) + post!(self, &endpoint, form_data) } pub async fn delete_playlist(&self, playlist_id: String) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistDelete.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistDelete); let mut form_data = HashMap::new(); form_data.insert("playlist_id", playlist_id.as_str()); - post!(self, endpoint, form_data) + post!(self, &endpoint, form_data) } /// Add new track to playlist @@ -336,7 +322,7 @@ impl Client { playlist_id: String, track_ids: Vec, ) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistAddTracks.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistAddTracks); let track_ids = track_ids.join(","); @@ -345,7 +331,7 @@ impl Client { form_data.insert("track_ids", track_ids.as_str()); form_data.insert("no_duplicate", "true"); - post!(self, endpoint, form_data) + post!(self, &endpoint, form_data) } /// Add new track to playlist @@ -354,11 +340,7 @@ impl Client { playlist_id: String, playlist_track_ids: Vec, ) -> Result { - let endpoint = format!( - "{}{}", - self.base_url, - Endpoint::PlaylistDeleteTracks.as_str() - ); + let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistDeleteTracks); let playlist_track_ids = playlist_track_ids.join(","); @@ -366,7 +348,7 @@ impl Client { form_data.insert("playlist_id", playlist_id.as_str()); form_data.insert("playlist_track_ids", playlist_track_ids.as_str()); - post!(self, endpoint, form_data) + post!(self, &endpoint, form_data) } /// Update track position in playlist @@ -376,11 +358,7 @@ impl Client { playlist_id: String, track_id: String, ) -> Result { - let endpoint = format!( - "{}{}", - self.base_url, - Endpoint::PlaylistUpdatePosition.as_str() - ); + let endpoint = format!("{}{}", self.base_url, Endpoint::PlaylistUpdatePosition); let index = index.to_string(); @@ -389,31 +367,31 @@ impl Client { form_data.insert("playlist_track_ids", track_id.as_str()); form_data.insert("insert_before", index.as_str()); - post!(self, endpoint, form_data) + post!(self, &endpoint, form_data) } /// Retrieve track information pub async fn track(&self, track_id: i32) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::Track.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::Track); let track_id_string = track_id.to_string(); let params = vec![("track_id", track_id_string.as_str())]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } /// Retrieve url information for a track's audio file pub async fn track_url( &self, track_id: i32, - fmt_id: Option, - sec: Option, + fmt_id: Option<&AudioQuality>, + sec: Option<&str>, ) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::TrackURL.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::TrackURL); let now = format!("{}", chrono::Utc::now().timestamp()); let secret = if let Some(secret) = sec { secret } else if let Some(s) = &self.active_secret { - s.clone() + s } else { return Err(Error::ActiveSecret); }; @@ -444,46 +422,46 @@ impl Client { ("intent", "stream"), ]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } - pub async fn search_all(&self, query: String, limit: i32) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::Search.as_str()); + pub async fn search_all(&self, query: &str, limit: i32) -> Result { + let endpoint = format!("{}{}", self.base_url, Endpoint::Search); let limit = limit.to_string(); - let params = vec![("query", query.as_str()), ("limit", &limit)]; + let params = vec![("query", query), ("limit", &limit)]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } // Retrieve information about an album pub async fn album(&self, album_id: &str) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::Album.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::Album); let params = vec![("album_id", album_id)]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } // Search the database for albums pub async fn search_albums( &self, - query: String, + query: &str, limit: Option, ) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::SearchAlbums.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::SearchAlbums); let limit = if let Some(limit) = limit { limit.to_string() } else { 100.to_string() }; - let params = vec![("query", query.as_str()), ("limit", limit.as_str())]; + let params = vec![("query", query), ("limit", limit.as_str())]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } // Retrieve information about an artist pub async fn artist(&self, artist_id: i32, limit: Option) -> Result { if let Some(app_id) = &self.app_id { - let endpoint = format!("{}{}", self.base_url, Endpoint::Artist.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::Artist); let limit = if let Some(limit) = limit { limit.to_string() } else { @@ -500,7 +478,7 @@ impl Client { ("extra", "albums"), ]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } else { Err(Error::AppID) } @@ -509,18 +487,18 @@ impl Client { // Search the database for artists pub async fn search_artists( &self, - query: String, + query: &str, limit: Option, ) -> Result { - let endpoint = format!("{}{}", self.base_url, Endpoint::SearchArtists.as_str()); + let endpoint = format!("{}{}", self.base_url, Endpoint::SearchArtists); let limit = if let Some(limit) = limit { limit.to_string() } else { 100.to_string() }; - let params = vec![("query", query.as_str()), ("limit", &limit)]; + let params = vec![("query", query), ("limit", &limit)]; - get!(self, endpoint, Some(params)) + get!(self, &endpoint, Some(¶ms)) } // Set a user access token for authentication @@ -542,16 +520,16 @@ impl Client { self.default_quality = quality; } - pub fn get_token(&self) -> Option { - self.user_token.clone() + pub fn get_token(&self) -> Option<&String> { + self.user_token.as_ref() } - pub fn get_active_secret(&self) -> Option { - self.active_secret.clone() + pub fn get_active_secret(&self) -> Option<&String> { + self.active_secret.as_ref() } - pub fn get_app_id(&self) -> Option { - self.app_id.clone() + pub fn get_app_id(&self) -> Option<&String> { + self.app_id.as_ref() } fn client_headers(&self) -> HeaderMap { @@ -578,8 +556,8 @@ impl Client { // Make a GET call to the API with the provided parameters async fn make_get_call( &self, - endpoint: String, - params: Option>, + endpoint: &str, + params: Option<&[(&str, &str)]>, ) -> Result { let headers = self.client_headers(); @@ -596,11 +574,7 @@ impl Client { } // Make a POST call to the API with form data - async fn make_post_call( - &self, - endpoint: String, - params: HashMap<&str, &str>, - ) -> Result { + async fn make_post_call(&self, endpoint: &str, params: HashMap<&str, &str>) -> Result { let headers = self.client_headers(); debug!("calling {} endpoint, with params {params:?}", endpoint); @@ -710,7 +684,7 @@ impl Client { for (timezone, secret) in secrets.iter() { let response = self - .track_url(64868955, Some(AudioQuality::Mp3), Some(secret.to_string())) + .track_url(64868955, Some(&AudioQuality::Mp3), Some(secret)) .await; if response.is_ok() { @@ -768,7 +742,7 @@ async fn can_use_methods() { ".playlists.items[].tracks_count" => "0", }); assert_yaml_snapshot!(client - .search_albums("a love supreme".to_string(), Some(10)) + .search_albums("a love supreme", Some(10)) .await .expect("failed to search for albums"), { @@ -782,7 +756,7 @@ async fn can_use_methods() { .await .expect("failed to get album")); assert_yaml_snapshot!(client - .search_artists("pink floyd".to_string(), Some(10)) + .search_artists("pink floyd", Some(10)) .await .expect("failed to search artists"), { @@ -794,7 +768,7 @@ async fn can_use_methods() { .expect("failed to get artist")); assert_yaml_snapshot!(client.track(155999429).await.expect("failed to get track")); assert_yaml_snapshot!(client - .track_url(64868955, Some(AudioQuality::HIFI96), None) + .track_url(64868955, Some(&AudioQuality::HIFI96), None) .await .expect("failed to get track url"), { ".url" => "[url]" }); diff --git a/qobuz-api/src/client/playlist.rs b/qobuz-api/src/client/playlist.rs index 9d0ff53..642157f 100644 --- a/qobuz-api/src/client/playlist.rs +++ b/qobuz-api/src/client/playlist.rs @@ -63,8 +63,8 @@ pub struct Playlist { } impl Playlist { - pub fn set_tracks(&mut self, tracks: Tracks) { - self.tracks = Some(tracks); + pub fn set_tracks(&mut self, tracks: &Tracks) { + self.tracks = Some(tracks.clone()); } pub fn reverse(&mut self) { @@ -81,37 +81,3 @@ pub struct Playlists { pub total: i64, pub items: Vec, } - -impl From for Vec> { - fn from(playlists: Playlists) -> Self { - playlists - .items - .into_iter() - .map(|i| vec![i.name]) - .collect::>>() - } -} - -impl From for Vec { - fn from(playlist: Playlist) -> Self { - vec![playlist.name] - } -} - -impl From> for Vec { - fn from(playlist: Box) -> Self { - vec![playlist.name] - } -} - -impl From<&Playlist> for Vec { - fn from(playlist: &Playlist) -> Self { - vec![playlist.name.clone()] - } -} - -impl From> for Vec> { - fn from(playlist: Box) -> Self { - vec![playlist.into()] - } -} diff --git a/qobuz-api/src/client/track.rs b/qobuz-api/src/client/track.rs index 5bd7f4f..4f6c78e 100644 --- a/qobuz-api/src/client/track.rs +++ b/qobuz-api/src/client/track.rs @@ -1,5 +1,4 @@ use crate::client::album::Album; -use gstreamer::ClockTime; use serde::{Deserialize, Serialize}; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -44,28 +43,6 @@ pub struct Track { pub version: Option, } -impl Track { - pub fn columns(&self) -> Vec { - let duration = ClockTime::from_seconds(self.duration as u64) - .to_string() - .as_str()[2..7] - .to_string(); - - let performer = if let Some(performer) = &self.performer { - performer.name.clone() - } else { - "".to_string() - }; - - vec![ - self.track_number.to_string(), - self.title.clone(), - performer, - duration, - ] - } -} - #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AudioInfo { pub replaygain_track_gain: f64,