[lint] Improve the code
This commit is contained in:
parent
10543a2cc1
commit
91878512ca
8 changed files with 23 additions and 24 deletions
|
@ -1,8 +1,7 @@
|
|||
use cmus_notify::{
|
||||
cmus::{self, events::CmusEvent, query::CmusQueryResponse},
|
||||
notification, settings,
|
||||
cmus::{self, query::CmusQueryResponse},
|
||||
notification,
|
||||
settings::Settings,
|
||||
track_cover, TrackCover,
|
||||
};
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{process_template_placeholders, settings};
|
||||
use crate::cmus::{Track, TrackStatus};
|
||||
use crate::cmus::player_settings::{AAAMode, PlayerSettings, Shuffle};
|
||||
use crate::{process_template_placeholders};
|
||||
use crate::cmus::{Track};
|
||||
use crate::cmus::player_settings::{PlayerSettings};
|
||||
use crate::notification::Action;
|
||||
use crate::settings::Settings;
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ impl TemplateProcessor for Track {
|
|||
if let Some(value) = match key.as_str() {
|
||||
"status" => Some(status.as_str()),
|
||||
"title" => Some(self.get_name()),
|
||||
_ => self.metadata.get(&key),
|
||||
_ => self.metadata.get(key),
|
||||
} {
|
||||
processed = processed.replace(&format!("{{{key}}}"), value);
|
||||
}
|
||||
|
@ -200,13 +200,13 @@ impl TrackMetadata {
|
|||
/// This function will assume you processed the first 4 lines, and remove them from the iterator.
|
||||
///
|
||||
/// and also assume the all tags is contained in the iterator.
|
||||
fn parse<'a>(mut lines: impl Iterator<Item = &'a str> + Debug) -> Self {
|
||||
fn parse<'a>(lines: impl Iterator<Item = &'a str> + Debug) -> Self {
|
||||
#[cfg(feature = "debug")]
|
||||
info!("Parsing track metadata from lines: {:?}", lines);
|
||||
|
||||
let mut tags = HashMap::new();
|
||||
|
||||
while let Some(line) = lines.next() {
|
||||
for line in lines {
|
||||
#[cfg(feature = "debug")]
|
||||
debug!("Parsing line: {}", line);
|
||||
match line.trim().split_once(' ') {
|
||||
|
@ -240,7 +240,7 @@ impl Track {
|
|||
.split('/')
|
||||
.last()
|
||||
.unwrap_or("")
|
||||
.split_once(".")
|
||||
.split_once('.')
|
||||
.unwrap_or(("", ""))
|
||||
.0
|
||||
})
|
||||
|
@ -268,7 +268,7 @@ pub fn ping_cmus(
|
|||
let output =
|
||||
String::from_utf8(output.stdout).map_err(|e| CmusError::UnknownError(e.to_string()))?;
|
||||
|
||||
CmusQueryResponse::from_str(&output).map_err(|e| CmusError::UnknownError(e.to_string()))
|
||||
CmusQueryResponse::from_str(&output).map_err(CmusError::UnknownError)
|
||||
}
|
||||
|
||||
/// Build the query command.
|
||||
|
|
|
@ -123,7 +123,7 @@ impl FromStr for PlayerSettings {
|
|||
debug!("Parsing line: {}", line);
|
||||
if line.starts_with("set ") {
|
||||
let line = &line[4..];
|
||||
let (key, value) = line.split_once(" ").ok_or(CmusError::UnknownError(
|
||||
let (key, value) = line.split_once(' ').ok_or(CmusError::UnknownError(
|
||||
"Corrupted cmus response".to_string(),
|
||||
))?;
|
||||
|
||||
|
|
|
@ -71,8 +71,8 @@ impl CmusQueryResponse {
|
|||
#[cfg(feature = "debug")]
|
||||
debug!("Track changed: {:?} -> {:?}", other_track, track);
|
||||
events.push(CmusEvent::TrackChanged(
|
||||
other_track.clone(),
|
||||
other_player_settings.clone(),
|
||||
other_track,
|
||||
other_player_settings,
|
||||
));
|
||||
// We don't need to check for other changes, since the track changed.
|
||||
return Ok(events);
|
||||
|
@ -93,7 +93,7 @@ impl CmusQueryResponse {
|
|||
other_track.position, track.position
|
||||
);
|
||||
events.push(CmusEvent::PositionChanged(
|
||||
track.clone(),
|
||||
track,
|
||||
other_player_settings.clone(),
|
||||
));
|
||||
}
|
||||
|
@ -244,8 +244,8 @@ mod tests {
|
|||
let player_settings = player_settings.unwrap();
|
||||
|
||||
assert_eq!(player_settings.aaa_mode, AAAMode::All);
|
||||
assert_eq!(player_settings.repeat, true);
|
||||
assert_eq!(player_settings.repeat_current, false);
|
||||
assert!(player_settings.repeat);
|
||||
assert!(!player_settings.repeat_current);
|
||||
assert_eq!(player_settings.shuffle, Shuffle::Off);
|
||||
assert_eq!(player_settings.volume.left, 17);
|
||||
assert_eq!(player_settings.volume.right, 17);
|
||||
|
|
|
@ -170,9 +170,9 @@ pub fn track_cover(
|
|||
}
|
||||
|
||||
if !no_use_external_cover {
|
||||
let (Ok(regx), path) = (match path.split("/").last() {
|
||||
let (Ok(regx), path) = (match path.split('/').last() {
|
||||
Some(last_pat) if last_pat.contains("r#") => {
|
||||
(regex::Regex::new(&*last_pat.replace("r#", "")),
|
||||
(regex::Regex::new(&last_pat.replace("r#", "")),
|
||||
// Remove the last part of the path
|
||||
path.remove(path.len() - last_pat.len() - 1).to_string())
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#[cfg(feature = "debug")]
|
||||
use log::{debug, info};
|
||||
use log::{info};
|
||||
use notify_rust::Notification;
|
||||
|
||||
use crate::{process_template_placeholders, settings, track_cover, TrackCover};
|
||||
use crate::cmus::{TemplateProcessor, Track, TrackStatus};
|
||||
use crate::{track_cover, TrackCover};
|
||||
use crate::cmus::{TemplateProcessor, Track};
|
||||
use crate::cmus::events::CmusEvent;
|
||||
use crate::cmus::player_settings::PlayerSettings;
|
||||
|
||||
use crate::cmus::query::CmusQueryResponse;
|
||||
use crate::settings::Settings;
|
||||
|
||||
|
|
|
@ -373,7 +373,7 @@ impl Settings {
|
|||
.or(cfg.notification_static_cover);
|
||||
cfg.cover_path_template = args.cover_path_template.or(cfg.cover_path_template);
|
||||
#[cfg(feature = "lyrics")]
|
||||
if args.lyrics_path != None {
|
||||
if args.lyrics_path.is_some() {
|
||||
#[cfg(feature = "debug")]
|
||||
debug!("The user not override the lyrics_path, using the config's lyrics_path. lyrics_path: {:?}", cfg.lyrics_path);
|
||||
cfg.lyrics_path = args.lyrics_path;
|
||||
|
|
Loading…
Reference in a new issue