amélioration de la webapp
This commit is contained in:
@@ -69,10 +69,7 @@ impl QobuzApi {
|
||||
pub async fn login(&mut self, username: &str, password: &str) -> Result<AuthInfo> {
|
||||
info!("Attempting to login to Qobuz as {}", username);
|
||||
|
||||
let params = [
|
||||
("username", username),
|
||||
("password", password),
|
||||
];
|
||||
let params = [("username", username), ("password", password)];
|
||||
|
||||
let response: LoginResponse = self.post("/user/login", ¶ms).await?;
|
||||
|
||||
|
||||
@@ -257,7 +257,12 @@ impl QobuzApi {
|
||||
|
||||
let response: SimilarArtistsResponse =
|
||||
self.get("/artist/getSimilarArtists", ¶ms).await?;
|
||||
Ok(response.artists.items.into_iter().map(Self::parse_artist).collect())
|
||||
Ok(response
|
||||
.artists
|
||||
.items
|
||||
.into_iter()
|
||||
.map(Self::parse_artist)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Récupère les détails d'une playlist
|
||||
@@ -275,7 +280,11 @@ impl QobuzApi {
|
||||
let response: PlaylistResponse = self.get("/playlist/get", ¶ms).await?;
|
||||
|
||||
if let Some(tracks) = response.tracks {
|
||||
Ok(tracks.items.into_iter().map(|t| Self::parse_track(t, None)).collect())
|
||||
Ok(tracks
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|t| Self::parse_track(t, None))
|
||||
.collect())
|
||||
} else {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
@@ -285,7 +294,12 @@ impl QobuzApi {
|
||||
pub async fn get_genres(&self) -> Result<Vec<Genre>> {
|
||||
debug!("Fetching genres");
|
||||
let response: GenresResponse = self.get("/genre/list", &[]).await?;
|
||||
Ok(response.genres.items.into_iter().map(Self::parse_genre).collect())
|
||||
Ok(response
|
||||
.genres
|
||||
.items
|
||||
.into_iter()
|
||||
.map(Self::parse_genre)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Récupère les albums featured (nouveautés, éditeur, etc.)
|
||||
@@ -329,7 +343,12 @@ impl QobuzApi {
|
||||
|
||||
let response: FeaturedPlaylistsResponse =
|
||||
self.get("/playlist/getFeatured", ¶ms).await?;
|
||||
Ok(response.playlists.items.into_iter().map(Self::parse_playlist).collect())
|
||||
Ok(response
|
||||
.playlists
|
||||
.items
|
||||
.into_iter()
|
||||
.map(Self::parse_playlist)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Recherche dans le catalogue
|
||||
@@ -391,10 +410,7 @@ impl QobuzApi {
|
||||
description: response.description,
|
||||
maximum_sampling_rate: response.maximum_sampling_rate,
|
||||
maximum_bit_depth: response.maximum_bit_depth,
|
||||
genres: response
|
||||
.genre
|
||||
.map(|g| vec![g.name])
|
||||
.unwrap_or_default(),
|
||||
genres: response.genre.map(|g| vec![g.name]).unwrap_or_default(),
|
||||
label: response.label.map(|l| l.name),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ impl QobuzApi {
|
||||
pub fn new(app_id: impl Into<String>) -> Result<Self> {
|
||||
let client = Client::builder()
|
||||
.timeout(Duration::from_secs(30))
|
||||
.user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0")
|
||||
.user_agent(
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0",
|
||||
)
|
||||
.build()?;
|
||||
|
||||
Ok(Self {
|
||||
|
||||
@@ -64,11 +64,7 @@ impl QobuzApi {
|
||||
let user_id = self.ensure_authenticated()?;
|
||||
debug!("Fetching favorite artists for user {}", user_id);
|
||||
|
||||
let params = [
|
||||
("user_id", user_id),
|
||||
("type", "artists"),
|
||||
("limit", "1000"),
|
||||
];
|
||||
let params = [("user_id", user_id), ("type", "artists"), ("limit", "1000")];
|
||||
|
||||
let response: FavoritesResponse = self.get("/favorite/getUserFavorites", ¶ms).await?;
|
||||
|
||||
@@ -125,70 +121,75 @@ impl QobuzApi {
|
||||
/// Ajoute un album aux favoris
|
||||
pub async fn add_favorite_album(&self, album_id: &str) -> Result<()> {
|
||||
let user_id = self.ensure_authenticated()?;
|
||||
debug!("Adding album {} to favorites for user {}", album_id, user_id);
|
||||
debug!(
|
||||
"Adding album {} to favorites for user {}",
|
||||
album_id, user_id
|
||||
);
|
||||
|
||||
let params = [
|
||||
("album_id", album_id),
|
||||
("user_id", user_id),
|
||||
];
|
||||
let params = [("album_id", album_id), ("user_id", user_id)];
|
||||
|
||||
self.get::<serde_json::Value>("/favorite/create", ¶ms).await?;
|
||||
self.get::<serde_json::Value>("/favorite/create", ¶ms)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Supprime un album des favoris
|
||||
pub async fn remove_favorite_album(&self, album_id: &str) -> Result<()> {
|
||||
let user_id = self.ensure_authenticated()?;
|
||||
debug!("Removing album {} from favorites for user {}", album_id, user_id);
|
||||
debug!(
|
||||
"Removing album {} from favorites for user {}",
|
||||
album_id, user_id
|
||||
);
|
||||
|
||||
let params = [
|
||||
("album_ids", album_id),
|
||||
("user_id", user_id),
|
||||
];
|
||||
let params = [("album_ids", album_id), ("user_id", user_id)];
|
||||
|
||||
self.get::<serde_json::Value>("/favorite/delete", ¶ms).await?;
|
||||
self.get::<serde_json::Value>("/favorite/delete", ¶ms)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ajoute un track aux favoris
|
||||
pub async fn add_favorite_track(&self, track_id: &str) -> Result<()> {
|
||||
let user_id = self.ensure_authenticated()?;
|
||||
debug!("Adding track {} to favorites for user {}", track_id, user_id);
|
||||
debug!(
|
||||
"Adding track {} to favorites for user {}",
|
||||
track_id, user_id
|
||||
);
|
||||
|
||||
let params = [
|
||||
("track_id", track_id),
|
||||
("user_id", user_id),
|
||||
];
|
||||
let params = [("track_id", track_id), ("user_id", user_id)];
|
||||
|
||||
self.get::<serde_json::Value>("/favorite/create", ¶ms).await?;
|
||||
self.get::<serde_json::Value>("/favorite/create", ¶ms)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Supprime un track des favoris
|
||||
pub async fn remove_favorite_track(&self, track_id: &str) -> Result<()> {
|
||||
let user_id = self.ensure_authenticated()?;
|
||||
debug!("Removing track {} from favorites for user {}", track_id, user_id);
|
||||
debug!(
|
||||
"Removing track {} from favorites for user {}",
|
||||
track_id, user_id
|
||||
);
|
||||
|
||||
let params = [
|
||||
("track_ids", track_id),
|
||||
("user_id", user_id),
|
||||
];
|
||||
let params = [("track_ids", track_id), ("user_id", user_id)];
|
||||
|
||||
self.get::<serde_json::Value>("/favorite/delete", ¶ms).await?;
|
||||
self.get::<serde_json::Value>("/favorite/delete", ¶ms)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ajoute un track à une playlist
|
||||
pub async fn add_to_playlist(&self, playlist_id: &str, track_id: &str) -> Result<()> {
|
||||
let user_id = self.ensure_authenticated()?;
|
||||
debug!("Adding track {} to playlist {} for user {}", track_id, playlist_id, user_id);
|
||||
debug!(
|
||||
"Adding track {} to playlist {} for user {}",
|
||||
track_id, playlist_id, user_id
|
||||
);
|
||||
|
||||
let params = [
|
||||
("playlist_id", playlist_id),
|
||||
("track_ids", track_id),
|
||||
];
|
||||
let params = [("playlist_id", playlist_id), ("track_ids", track_id)];
|
||||
|
||||
self.get::<serde_json::Value>("/playlist/addTracks", ¶ms).await?;
|
||||
self.get::<serde_json::Value>("/playlist/addTracks", ¶ms)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user