Code cleanups

This commit is contained in:
Henrik Friedrichsen
2021-08-15 15:05:49 +02:00
parent 19d87f6b8f
commit 6b8e1d33dc
13 changed files with 38 additions and 44 deletions

View File

@@ -93,7 +93,7 @@ impl From<&FullAlbum> for Album {
fa.tracks
.items
.iter()
.map(|st| Track::from_simplified_track(&st, &fa))
.map(|st| Track::from_simplified_track(st, fa))
.collect(),
);

View File

@@ -65,7 +65,7 @@ pub fn create_credentials() -> Result<RespotCredentials, String> {
.child(controls);
let url = &urls["login_url"];
webbrowser::open(url).ok();
auth_poller(&urls["credentials_url"], &s.cb_sink());
auth_poller(&urls["credentials_url"], s.cb_sink());
s.pop_layer();
s.add_layer(login_view)
})

View File

@@ -1,7 +1,6 @@
use crate::queue::RepeatSetting;
use std::collections::HashMap;
use std::fmt;
use std::iter::FromIterator;
use strum_macros::Display;
@@ -235,7 +234,7 @@ fn handle_aliases(input: &str) -> &str {
pub fn parse(input: &str) -> Option<Command> {
let components: Vec<_> = input.trim().split(' ').collect();
let command = handle_aliases(&components[0]);
let command = handle_aliases(components[0]);
let args = components[1..].to_vec();
match command {

View File

@@ -321,7 +321,7 @@ impl CommandManager {
let kb = self.bindings.borrow();
for (k, _v) in kb.iter() {
if let Some(binding) = Self::parse_keybinding(&k) {
if let Some(binding) = Self::parse_keybinding(k) {
cursive.clear_global_callbacks(binding);
}
}
@@ -331,10 +331,10 @@ impl CommandManager {
let kb = self.bindings.borrow();
for (k, v) in kb.iter() {
if let Some(binding) = Self::parse_keybinding(&k) {
if let Some(binding) = Self::parse_keybinding(k) {
self.register_keybinding(cursive, binding, v.clone());
} else {
error!("Could not parse keybinding: \"{}\"", &k);
error!("Could not parse keybinding: \"{}\"", k);
}
}
}
@@ -521,7 +521,7 @@ impl CommandManager {
None
}
} else {
Some(Self::parse_key(&kb))
Some(Self::parse_key(kb))
}
}
}

View File

@@ -127,7 +127,7 @@ impl Library {
let pos = {
let store = self.playlists.read().expect("can't readlock playlists");
store.iter().position(|ref i| i.id == id)
store.iter().position(|i| i.id == id)
};
if let Some(position) = pos {
@@ -143,7 +143,7 @@ impl Library {
pub fn overwrite_playlist(&self, id: &str, tracks: &[Playable]) {
debug!("saving {} tracks to list {}", tracks.len(), id);
self.spotify.overwrite_playlist(id, &tracks);
self.spotify.overwrite_playlist(id, tracks);
self.fetch_playlists();
self.save_cache(config::cache_path(CACHE_PLAYLISTS), self.playlists.clone());
@@ -152,7 +152,7 @@ impl Library {
pub fn save_playlist(&self, name: &str, tracks: &[Playable]) {
debug!("saving {} tracks to new list {}", tracks.len(), name);
match self.spotify.create_playlist(name, None, None) {
Some(id) => self.overwrite_playlist(&id, &tracks),
Some(id) => self.overwrite_playlist(&id, tracks),
None => error!("could not create new playlist.."),
}
}

View File

@@ -558,7 +558,7 @@ fn run_dbus_server(
let uri_type = UriType::from_uri(&uri);
match uri_type {
Some(UriType::Album) => {
if let Some(a) = spotify.album(&id) {
if let Some(a) = spotify.album(id) {
if let Some(t) = &Album::from(&a).tracks {
queue.clear();
let index = queue.append_next(
@@ -571,14 +571,14 @@ fn run_dbus_server(
}
}
Some(UriType::Track) => {
if let Some(t) = spotify.track(&id) {
if let Some(t) = spotify.track(id) {
queue.clear();
queue.append(Playable::Track(Track::from(&t)));
queue.play(0, false, false)
}
}
Some(UriType::Playlist) => {
if let Some(p) = spotify.playlist(&id) {
if let Some(p) = spotify.playlist(id) {
let mut playlist = Playlist::from(&p);
let spotify = spotify.clone();
playlist.load_tracks(spotify);
@@ -594,7 +594,7 @@ fn run_dbus_server(
}
}
Some(UriType::Show) => {
if let Some(s) = spotify.get_show(&id) {
if let Some(s) = spotify.get_show(id) {
let mut show: Show = (&s).into();
let spotify = spotify.clone();
show.load_all_episodes(spotify);
@@ -612,14 +612,14 @@ fn run_dbus_server(
}
}
Some(UriType::Episode) => {
if let Some(e) = spotify.episode(&id) {
if let Some(e) = spotify.episode(id) {
queue.clear();
queue.append(Playable::Episode(Episode::from(&e)));
queue.play(0, false, false)
}
}
Some(UriType::Artist) => {
if let Some(a) = spotify.artist_top_tracks(&id) {
if let Some(a) = spotify.artist_top_tracks(id) {
queue.clear();
queue.append_next(a.iter().map(|track| Playable::Track(track.clone())).collect());
queue.play(0, false, false)

View File

@@ -58,7 +58,7 @@ impl Playlist {
true => {
if let Some(tracks) = &mut self.tracks {
tracks.remove(index);
library.playlist_update(&self);
library.playlist_update(self);
}
true

View File

@@ -261,7 +261,7 @@ impl Queue {
}
if let Some(track) = &self.queue.read().unwrap().get(index) {
self.spotify.load(&track, true, 0);
self.spotify.load(track, true, 0);
let mut current = self.current_track.write().unwrap();
current.replace(index);
self.spotify.update_track();

View File

@@ -360,12 +360,7 @@ impl Spotify {
position: Option<i32>,
) -> bool {
self.api_with_retry(|api| {
api.user_playlist_add_tracks(
self.user.as_ref().unwrap(),
playlist_id,
&tracks,
position,
)
api.user_playlist_add_tracks(self.user.as_ref().unwrap(), playlist_id, tracks, position)
})
.is_some()
}

View File

@@ -81,7 +81,7 @@ impl From<&SimplifiedTrack> for Track {
let artists = track
.artists
.iter()
.map(|ref artist| artist.name.clone())
.map(|artist| artist.name.clone())
.collect::<Vec<String>>();
let artist_ids = track
.artists
@@ -114,7 +114,7 @@ impl From<&FullTrack> for Track {
let artists = track
.artists
.iter()
.map(|ref artist| artist.name.clone())
.map(|artist| artist.name.clone())
.collect::<Vec<String>>();
let artist_ids = track
.artists
@@ -125,7 +125,7 @@ impl From<&FullTrack> for Track {
.album
.artists
.iter()
.map(|ref artist| artist.name.clone())
.map(|artist| artist.name.clone())
.collect::<Vec<String>>();
Self {
@@ -283,7 +283,7 @@ impl ListItem for Track {
let spotify = queue.get_spotify();
match self.album_id {
Some(ref album_id) => spotify.album(&album_id).map(|ref fa| fa.into()),
Some(ref album_id) => spotify.album(album_id).map(|ref fa| fa.into()),
None => None,
}
}

View File

@@ -26,9 +26,9 @@ impl ArtistView {
let spotify = queue.get_spotify();
let albums_view =
Self::albums_view(&artist, AlbumType::Album, queue.clone(), library.clone());
Self::albums_view(artist, AlbumType::Album, queue.clone(), library.clone());
let singles_view =
Self::albums_view(&artist, AlbumType::Single, queue.clone(), library.clone());
Self::albums_view(artist, AlbumType::Single, queue.clone(), library.clone());
let top_tracks: Arc<RwLock<Vec<Track>>> = Arc::new(RwLock::new(Vec::new()));
{

View File

@@ -256,7 +256,7 @@ impl View for Layout {
if cmdline_visible {
let printer = &printer.offset((0, printer.size.y - 1));
self.cmdline.draw(&printer);
self.cmdline.draw(printer);
}
}

View File

@@ -109,7 +109,7 @@ impl SearchResultsView {
_offset: usize,
_append: bool,
) -> u32 {
if let Some(results) = spotify.track(&query) {
if let Some(results) = spotify.track(query) {
let t = vec![(&results).into()];
let mut r = tracks.write().unwrap();
*r = t;
@@ -126,7 +126,7 @@ impl SearchResultsView {
append: bool,
) -> u32 {
if let Some(SearchResult::Tracks(results)) =
spotify.search(SearchType::Track, &query, 50, offset as u32)
spotify.search(SearchType::Track, query, 50, offset as u32)
{
let mut t = results.items.iter().map(|ft| ft.into()).collect();
let mut r = tracks.write().unwrap();
@@ -148,7 +148,7 @@ impl SearchResultsView {
_offset: usize,
_append: bool,
) -> u32 {
if let Some(results) = spotify.album(&query) {
if let Some(results) = spotify.album(query) {
let a = vec![(&results).into()];
let mut r = albums.write().unwrap();
*r = a;
@@ -165,7 +165,7 @@ impl SearchResultsView {
append: bool,
) -> u32 {
if let Some(SearchResult::Albums(results)) =
spotify.search(SearchType::Album, &query, 50, offset as u32)
spotify.search(SearchType::Album, query, 50, offset as u32)
{
let mut a = results.items.iter().map(|sa| sa.into()).collect();
let mut r = albums.write().unwrap();
@@ -187,7 +187,7 @@ impl SearchResultsView {
_offset: usize,
_append: bool,
) -> u32 {
if let Some(results) = spotify.artist(&query) {
if let Some(results) = spotify.artist(query) {
let a = vec![(&results).into()];
let mut r = artists.write().unwrap();
*r = a;
@@ -204,7 +204,7 @@ impl SearchResultsView {
append: bool,
) -> u32 {
if let Some(SearchResult::Artists(results)) =
spotify.search(SearchType::Artist, &query, 50, offset as u32)
spotify.search(SearchType::Artist, query, 50, offset as u32)
{
let mut a = results.items.iter().map(|fa| fa.into()).collect();
let mut r = artists.write().unwrap();
@@ -226,7 +226,7 @@ impl SearchResultsView {
_offset: usize,
_append: bool,
) -> u32 {
if let Some(result) = spotify.playlist(&query).as_ref() {
if let Some(result) = spotify.playlist(query).as_ref() {
let pls = vec![result.into()];
let mut r = playlists.write().unwrap();
*r = pls;
@@ -243,7 +243,7 @@ impl SearchResultsView {
append: bool,
) -> u32 {
if let Some(SearchResult::Playlists(results)) =
spotify.search(SearchType::Playlist, &query, 50, offset as u32)
spotify.search(SearchType::Playlist, query, 50, offset as u32)
{
let mut pls = results.items.iter().map(|sp| sp.into()).collect();
let mut r = playlists.write().unwrap();
@@ -265,7 +265,7 @@ impl SearchResultsView {
_offset: usize,
_append: bool,
) -> u32 {
if let Some(result) = spotify.get_show(&query).as_ref() {
if let Some(result) = spotify.get_show(query).as_ref() {
let pls = vec![result.into()];
let mut r = shows.write().unwrap();
*r = pls;
@@ -282,7 +282,7 @@ impl SearchResultsView {
append: bool,
) -> u32 {
if let Some(SearchResult::Shows(results)) =
spotify.search(SearchType::Show, &query, 50, offset as u32)
spotify.search(SearchType::Show, query, 50, offset as u32)
{
let mut pls = results.items.iter().map(|sp| sp.into()).collect();
let mut r = shows.write().unwrap();
@@ -304,7 +304,7 @@ impl SearchResultsView {
_offset: usize,
_append: bool,
) -> u32 {
if let Some(result) = spotify.episode(&query).as_ref() {
if let Some(result) = spotify.episode(query).as_ref() {
let e = vec![result.into()];
let mut r = episodes.write().unwrap();
*r = e;
@@ -321,7 +321,7 @@ impl SearchResultsView {
append: bool,
) -> u32 {
if let Some(SearchResult::Episodes(results)) =
spotify.search(SearchType::Episode, &query, 50, offset as u32)
spotify.search(SearchType::Episode, query, 50, offset as u32)
{
let mut e = results.items.iter().map(|se| se.into()).collect();
let mut r = episodes.write().unwrap();