docs: small overall documentation improvements (#1381)

* docs: small overall documentation improvements

- Add documentation comments to various items
- Change web API return types from bool/Option to Result
- Create helper functions with descriptive names instead of comments
- Remove redundant/confusing types
- Fix some documentation comments as instructed by `cargo doc`
- Rename variables to clear names

* docs: small fixes to the documentation update
This commit is contained in:
Thomas Frans
2024-02-01 19:42:53 +01:00
committed by GitHub
parent 8805464b1d
commit c5d666f35c
18 changed files with 312 additions and 151 deletions

View File

@@ -38,7 +38,7 @@ impl Album {
if let Some(ref album_id) = self.id {
let mut collected_tracks = Vec::new();
if let Some(full_album) = spotify.api.album(album_id) {
if let Ok(full_album) = spotify.api.album(album_id) {
let mut tracks_result = Some(full_album.tracks.clone());
while let Some(ref tracks) = tracks_result {
for t in &tracks.items {
@@ -51,11 +51,14 @@ impl Album {
tracks_result = match tracks.next {
Some(_) => {
debug!("requesting tracks again..");
spotify.api.album_tracks(
album_id,
50,
tracks.offset + tracks.items.len() as u32,
)
spotify
.api
.album_tracks(
album_id,
50,
tracks.offset + tracks.items.len() as u32,
)
.ok()
}
None => None,
}
@@ -273,6 +276,7 @@ impl ListItem for Album {
None,
Some(track_ids),
)
.ok()
.map(|r| r.tracks)
.map(|tracks| tracks.iter().map(Track::from).collect());
recommendations.map(|tracks| {

View File

@@ -35,7 +35,7 @@ impl Artist {
fn load_top_tracks(&mut self, spotify: Spotify) {
if let Some(artist_id) = &self.id {
if self.tracks.is_none() {
self.tracks = spotify.api.artist_top_tracks(artist_id);
self.tracks = spotify.api.artist_top_tracks(artist_id).ok();
}
}
}
@@ -182,6 +182,7 @@ impl ListItem for Artist {
let recommendations: Option<Vec<Track>> = spotify
.api
.recommendations(Some(vec![&id]), None, None)
.ok()
.map(|r| r.tracks)
.map(|tracks| tracks.iter().map(Track::from).collect());

View File

@@ -67,6 +67,7 @@ impl Playlist {
match spotify
.api
.delete_tracks(&self.id, &self.snapshot_id, &[playable])
.is_ok()
{
false => false,
true => {
@@ -83,7 +84,11 @@ impl Playlist {
pub fn append_tracks(&mut self, new_tracks: &[Playable], spotify: &Spotify, library: &Library) {
let mut has_modified = false;
if spotify.api.append_tracks(&self.id, new_tracks, None) {
if spotify
.api
.append_tracks(&self.id, new_tracks, None)
.is_ok()
{
if let Some(tracks) = &mut self.tracks {
tracks.append(&mut new_tracks.to_vec());
has_modified = true;
@@ -304,6 +309,7 @@ impl ListItem for Playlist {
None,
Some(track_ids.iter().map(|t| t.as_ref()).collect()),
)
.ok()
.map(|r| r.tracks)
.map(|tracks| tracks.iter().map(Track::from).collect());

View File

@@ -278,6 +278,7 @@ impl ListItem for Track {
spotify
.api
.recommendations(None, None, Some(vec![id]))
.ok()
.map(|r| r.tracks)
.map(|tracks| tracks.iter().map(Self::from).collect())
} else {
@@ -309,7 +310,7 @@ impl ListItem for Track {
let spotify = queue.get_spotify();
match self.album_id {
Some(ref album_id) => spotify.api.album(album_id).map(|ref fa| fa.into()),
Some(ref album_id) => spotify.api.album(album_id).map(|ref fa| fa.into()).ok(),
None => None,
}
}