mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 01:52:53 -05:00
Fixed clippy suggestions
This commit is contained in:
parent
4d647971aa
commit
6b3ac348ac
4 changed files with 41 additions and 46 deletions
|
@ -168,8 +168,8 @@ impl ControllerHandle {
|
||||||
},
|
},
|
||||||
ControllerInput {
|
ControllerInput {
|
||||||
player_mail,
|
player_mail,
|
||||||
lib_mail: lib_mail,
|
lib_mail,
|
||||||
queue_mail: queue_mail,
|
queue_mail,
|
||||||
library,
|
library,
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,6 @@ impl Controller {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let queue = queue;
|
|
||||||
|
|
||||||
std::thread::scope(|scope| {
|
std::thread::scope(|scope| {
|
||||||
let queue_mail = queue_mail;
|
let queue_mail = queue_mail;
|
||||||
let a = scope.spawn(|| {
|
let a = scope.spawn(|| {
|
||||||
|
@ -363,7 +361,7 @@ impl Controller {
|
||||||
let LibraryResponse::AllSongs(songs) = lib_mail.recv().await.unwrap() else {
|
let LibraryResponse::AllSongs(songs) = lib_mail.recv().await.unwrap() else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
lib_mail.send(LibraryCommand::Song(np_song.song.uuid.clone())).await.unwrap();
|
lib_mail.send(LibraryCommand::Song(np_song.song.uuid)).await.unwrap();
|
||||||
let LibraryResponse::Song(_, i) = lib_mail.recv().await.unwrap() else {
|
let LibraryResponse::Song(_, i) = lib_mail.recv().await.unwrap() else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
@ -436,7 +434,7 @@ impl Controller {
|
||||||
let QueueResponse::Ok = queue_mail.recv().await.unwrap() else {
|
let QueueResponse::Ok = queue_mail.recv().await.unwrap() else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
queue_mail.send(QueueCommand::Append(QueueItem::from_item_type(QueueItemType::Single(QueueSong { song: song.clone(), location: location })), true)).await.unwrap();
|
queue_mail.send(QueueCommand::Append(QueueItem::from_item_type(QueueItemType::Single(QueueSong { song: song.clone(), location })), true)).await.unwrap();
|
||||||
let QueueResponse::Ok = queue_mail.recv().await.unwrap() else {
|
let QueueResponse::Ok = queue_mail.recv().await.unwrap() else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
@ -508,11 +506,11 @@ impl Controller {
|
||||||
},
|
},
|
||||||
LibraryCommand::ExternalPlaylist(uuid) => {
|
LibraryCommand::ExternalPlaylist(uuid) => {
|
||||||
let playlist = library.query_playlist_uuid(&uuid).unwrap();
|
let playlist = library.query_playlist_uuid(&uuid).unwrap();
|
||||||
lib_mail.send(LibraryResponse::ExternalPlaylist(ExternalPlaylist::from_playlist(playlist, &library))).await.unwrap();
|
lib_mail.send(LibraryResponse::ExternalPlaylist(ExternalPlaylist::from_playlist(playlist, library))).await.unwrap();
|
||||||
}
|
}
|
||||||
LibraryCommand::ImportM3UPlayList(path) => {
|
LibraryCommand::ImportM3UPlayList(path) => {
|
||||||
let playlist = Playlist::from_m3u(path, library).unwrap();
|
let playlist = Playlist::from_m3u(path, library).unwrap();
|
||||||
let uuid = playlist.uuid.clone();
|
let uuid = playlist.uuid;
|
||||||
let name = playlist.title.clone();
|
let name = playlist.title.clone();
|
||||||
library.playlists.items.push(PlaylistFolderItem::List(playlist));
|
library.playlists.items.push(PlaylistFolderItem::List(playlist));
|
||||||
|
|
||||||
|
|
|
@ -67,11 +67,11 @@ impl ExternalLibrary for ITunesLibrary {
|
||||||
key_selected = false;
|
key_selected = false;
|
||||||
|
|
||||||
//end the song to start a new one, and turn turn current song map into iTunesSong
|
//end the song to start a new one, and turn turn current song map into iTunesSong
|
||||||
if song_tags.contains_key(&"Location".to_string()) {
|
if song_tags.contains_key("Location") {
|
||||||
count3 += 1;
|
count3 += 1;
|
||||||
//check for skipped IDs
|
//check for skipped IDs
|
||||||
if &count3.to_string()
|
if &count3.to_string()
|
||||||
!= song_tags.get_key_value(&"Track ID".to_string()).unwrap().1
|
!= song_tags.get_key_value("Track ID").unwrap().1
|
||||||
{
|
{
|
||||||
count3 += 1;
|
count3 += 1;
|
||||||
count4 += 1;
|
count4 += 1;
|
||||||
|
@ -196,10 +196,7 @@ impl ExternalLibrary for ITunesLibrary {
|
||||||
last_played: track.last_played,
|
last_played: track.last_played,
|
||||||
date_added: track.date_added,
|
date_added: track.date_added,
|
||||||
date_modified: track.date_modified,
|
date_modified: track.date_modified,
|
||||||
album_art: match get_art(Path::new(&loc)) {
|
album_art: get_art(Path::new(&loc)).unwrap_or_default(),
|
||||||
Ok(e) => e,
|
|
||||||
Err(_) => Vec::new(),
|
|
||||||
},
|
|
||||||
tags: tags_,
|
tags: tags_,
|
||||||
internal_tags,
|
internal_tags,
|
||||||
};
|
};
|
||||||
|
@ -252,10 +249,7 @@ fn get_art(file: &Path) -> Result<Vec<AlbumArt>, lofty::error::LoftyError> {
|
||||||
}
|
}
|
||||||
Err(_) => blank_tag,
|
Err(_) => blank_tag,
|
||||||
};
|
};
|
||||||
let mut img = match utils::find_images(file) {
|
let mut img = utils::find_images(file).unwrap_or_default();
|
||||||
Ok(e) => e,
|
|
||||||
Err(_) => Vec::new(),
|
|
||||||
};
|
|
||||||
if !img.is_empty() {
|
if !img.is_empty() {
|
||||||
album_art.append(img.as_mut());
|
album_art.append(img.as_mut());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::cmp::Ordering;
|
||||||
// Various std things
|
// Various std things
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::fmt::Display;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::ops::ControlFlow::{Break, Continue};
|
use std::ops::ControlFlow::{Break, Continue};
|
||||||
use std::vec::IntoIter;
|
use std::vec::IntoIter;
|
||||||
|
@ -65,9 +66,10 @@ pub enum Tag {
|
||||||
Field(String),
|
Field(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Tag {
|
|
||||||
fn to_string(&self) -> String {
|
impl Display for Tag {
|
||||||
match self {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let path_str: String = match self {
|
||||||
Self::Title => "TrackTitle".into(),
|
Self::Title => "TrackTitle".into(),
|
||||||
Self::Album => "AlbumTitle".into(),
|
Self::Album => "AlbumTitle".into(),
|
||||||
Self::Artist => "TrackArtist".into(),
|
Self::Artist => "TrackArtist".into(),
|
||||||
|
@ -78,7 +80,9 @@ impl ToString for Tag {
|
||||||
Self::Disk => "DiscNumber".into(),
|
Self::Disk => "DiscNumber".into(),
|
||||||
Self::Key(key) => key.into(),
|
Self::Key(key) => key.into(),
|
||||||
Self::Field(f) => f.into(),
|
Self::Field(f) => f.into(),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
write!(f, "{}", path_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +102,9 @@ pub enum Field {
|
||||||
DateModified(DateTime<Utc>),
|
DateModified(DateTime<Utc>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for Field {
|
impl Display for Field {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
let path_str = match self {
|
||||||
Self::Location(location) => location.to_string(),
|
Self::Location(location) => location.to_string(),
|
||||||
Self::Plays(plays) => plays.to_string(),
|
Self::Plays(plays) => plays.to_string(),
|
||||||
Self::Skips(skips) => skips.to_string(),
|
Self::Skips(skips) => skips.to_string(),
|
||||||
|
@ -112,7 +116,9 @@ impl ToString for Field {
|
||||||
Self::LastPlayed(last) => last.to_rfc2822(),
|
Self::LastPlayed(last) => last.to_rfc2822(),
|
||||||
Self::DateAdded(added) => added.to_rfc2822(),
|
Self::DateAdded(added) => added.to_rfc2822(),
|
||||||
Self::DateModified(modified) => modified.to_rfc2822(),
|
Self::DateModified(modified) => modified.to_rfc2822(),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
write!(f, "{}", path_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +211,7 @@ impl Song {
|
||||||
"rating" => self.rating.map(Field::Rating),
|
"rating" => self.rating.map(Field::Rating),
|
||||||
"duration" => Some(Field::Duration(self.duration)),
|
"duration" => Some(Field::Duration(self.duration)),
|
||||||
"play_time" => Some(Field::PlayTime(self.play_time)),
|
"play_time" => Some(Field::PlayTime(self.play_time)),
|
||||||
"format" => self.format.clone().map(|m| Field::Format(m)),
|
"format" => self.format.clone().map(Field::Format),
|
||||||
_ => todo!(), // Other field types are not yet supported
|
_ => todo!(), // Other field types are not yet supported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +226,7 @@ impl Song {
|
||||||
self.tags.remove(target_key);
|
self.tags.remove(target_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `Song` from a music file
|
/// Creates a [`Song`] from a music file
|
||||||
pub fn from_file<P: ?Sized + AsRef<Path>>(target_file: &P) -> Result<Self, Box<dyn Error>> {
|
pub fn from_file<P: ?Sized + AsRef<Path>>(target_file: &P) -> Result<Self, Box<dyn Error>> {
|
||||||
let normal_options = lofty::config::ParseOptions::new().parsing_mode(lofty::config::ParsingMode::Relaxed);
|
let normal_options = lofty::config::ParseOptions::new().parsing_mode(lofty::config::ParsingMode::Relaxed);
|
||||||
|
|
||||||
|
@ -320,7 +326,7 @@ impl Song {
|
||||||
Ok(new_song)
|
Ok(new_song)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// creates a `Vec<Song>` from a cue file
|
/// creates a [`Vec<Song>`] from a cue file
|
||||||
pub fn from_cue(cuesheet: &Path) -> Result<Vec<(Self, PathBuf)>, Box<dyn Error>> {
|
pub fn from_cue(cuesheet: &Path) -> Result<Vec<(Self, PathBuf)>, Box<dyn Error>> {
|
||||||
let mut tracks = Vec::new();
|
let mut tracks = Vec::new();
|
||||||
|
|
||||||
|
@ -386,18 +392,14 @@ impl Song {
|
||||||
|
|
||||||
// Get some useful tags
|
// Get some useful tags
|
||||||
let mut tags: BTreeMap<Tag, String> = BTreeMap::new();
|
let mut tags: BTreeMap<Tag, String> = BTreeMap::new();
|
||||||
match album_title {
|
if let Some(title) = album_title {
|
||||||
Some(title) => {
|
tags.insert(Tag::Album, title.clone());
|
||||||
tags.insert(Tag::Album, title.clone());
|
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
match album_artist {
|
|
||||||
Some(artist) => {
|
if let Some(artist) = album_artist {
|
||||||
tags.insert(Tag::Artist, artist.clone());
|
tags.insert(Tag::Artist, artist.clone());
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tags.insert(Tag::Track, track.no.parse().unwrap_or((i + 1).to_string()));
|
tags.insert(Tag::Track, track.no.parse().unwrap_or((i + 1).to_string()));
|
||||||
match track.title.clone() {
|
match track.title.clone() {
|
||||||
Some(title) => tags.insert(Tag::Title, title),
|
Some(title) => tags.insert(Tag::Title, title),
|
||||||
|
@ -573,14 +575,15 @@ impl URI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for URI {
|
impl Display for URI {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let path_str = match self {
|
let path_str = match self {
|
||||||
URI::Local(location) => location.as_path().to_string_lossy(),
|
URI::Local(location) => location.as_path().to_string_lossy(),
|
||||||
URI::Cue { location, .. } => location.as_path().to_string_lossy(),
|
URI::Cue { location, .. } => location.as_path().to_string_lossy(),
|
||||||
URI::Remote(_, location) => location.into(),
|
URI::Remote(_, location) => location.into(),
|
||||||
};
|
};
|
||||||
path_str.to_string()
|
|
||||||
|
write!(f, "{}", path_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,7 +632,7 @@ impl Album {
|
||||||
fn tracks(&self) -> Vec<(u16, Uuid)> {
|
fn tracks(&self) -> Vec<(u16, Uuid)> {
|
||||||
let mut songs = Vec::new();
|
let mut songs = Vec::new();
|
||||||
for disc in self.discs.values() {
|
for disc in self.discs.values() {
|
||||||
songs.extend_from_slice(&disc)
|
songs.extend_from_slice(disc)
|
||||||
}
|
}
|
||||||
songs
|
songs
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl PlaylistFolder {
|
||||||
match item {
|
match item {
|
||||||
PlaylistFolderItem::Folder(folder) => return folder.query_uuid(uuid),
|
PlaylistFolderItem::Folder(folder) => return folder.query_uuid(uuid),
|
||||||
PlaylistFolderItem::List(ref playlist) => if &playlist.uuid == uuid {
|
PlaylistFolderItem::List(ref playlist) => if &playlist.uuid == uuid {
|
||||||
return Some(&playlist);
|
return Some(playlist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ impl ExternalPlaylist {
|
||||||
}).collect_vec();
|
}).collect_vec();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
uuid: playlist.uuid.clone(),
|
uuid: playlist.uuid,
|
||||||
title: playlist.title.clone(),
|
title: playlist.title.clone(),
|
||||||
tracks,
|
tracks,
|
||||||
sort_order: playlist.sort_order.clone(),
|
sort_order: playlist.sort_order.clone(),
|
||||||
|
@ -381,7 +381,7 @@ impl ExternalPlaylist {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
if self.contains(uuid) {
|
if self.contains(uuid) {
|
||||||
for track in &self.tracks {
|
for track in &self.tracks {
|
||||||
if &uuid == &track.uuid {
|
if uuid == track.uuid {
|
||||||
return Some(i);
|
return Some(i);
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
Loading…
Reference in a new issue