mirror of
https://github.com/Dangoware/dmp-core.git
synced 2025-04-20 01:22:53 -05:00
Ran cargo fmt
This commit is contained in:
parent
17c2745cdd
commit
b2e7367795
4 changed files with 64 additions and 40 deletions
|
@ -18,10 +18,7 @@ impl MusicController {
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
};
|
};
|
||||||
|
|
||||||
let controller = MusicController {
|
let controller = MusicController { config, library };
|
||||||
config,
|
|
||||||
library,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(controller)
|
Ok(controller)
|
||||||
}
|
}
|
||||||
|
@ -34,10 +31,7 @@ impl MusicController {
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
};
|
};
|
||||||
|
|
||||||
let controller = MusicController {
|
let controller = MusicController { config, library };
|
||||||
config,
|
|
||||||
library,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(controller)
|
Ok(controller)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Crate things
|
// Crate things
|
||||||
//use crate::music_controller::config::Config;
|
//use crate::music_controller::config::Config;
|
||||||
use crate::music_storage::music_db::{URI, Tag};
|
use crate::music_storage::music_db::{Tag, URI};
|
||||||
use crossbeam_channel::bounded;
|
use crossbeam_channel::bounded;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
@ -48,11 +48,11 @@ impl TryInto<gst::State> for PlayerState {
|
||||||
fn try_into(self) -> Result<gst::State, Box<dyn Error>> {
|
fn try_into(self) -> Result<gst::State, Box<dyn Error>> {
|
||||||
match self {
|
match self {
|
||||||
Self::VoidPending => Ok(gst::State::VoidPending),
|
Self::VoidPending => Ok(gst::State::VoidPending),
|
||||||
Self::Playing => Ok(gst::State::Playing),
|
Self::Playing => Ok(gst::State::Playing),
|
||||||
Self::Paused => Ok(gst::State::Paused),
|
Self::Paused => Ok(gst::State::Paused),
|
||||||
Self::Ready => Ok(gst::State::Ready),
|
Self::Ready => Ok(gst::State::Ready),
|
||||||
Self::Null => Ok(gst::State::Null),
|
Self::Null => Ok(gst::State::Null),
|
||||||
state => Err(format!("Invalid gst::State: {:?}", state).into())
|
state => Err(format!("Invalid gst::State: {:?}", state).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,10 +177,22 @@ impl Player {
|
||||||
.expect("Failed to get GStreamer message bus")
|
.expect("Failed to get GStreamer message bus")
|
||||||
.add_watch(move |_bus, msg| {
|
.add_watch(move |_bus, msg| {
|
||||||
match msg.view() {
|
match msg.view() {
|
||||||
gst::MessageView::Eos(_) => {},
|
gst::MessageView::Eos(_) => {}
|
||||||
gst::MessageView::StreamStart(_) => {},
|
gst::MessageView::StreamStart(_) => println!("Stream start"),
|
||||||
gst::MessageView::Error(e) =>
|
gst::MessageView::Error(e) => {
|
||||||
println!("song {}", e.error()),
|
println!("ERROR: {}", e.error());
|
||||||
|
playbin_bus_ctrl
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_state(gst::State::Ready)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
playbin_bus_ctrl
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_state(gst::State::Playing)
|
||||||
|
.unwrap();
|
||||||
|
},
|
||||||
gst::MessageView::Tag(tag) => {
|
gst::MessageView::Tag(tag) => {
|
||||||
if let Some(title) = tag.tags().get::<gst::tags::Title>() {
|
if let Some(title) = tag.tags().get::<gst::tags::Title>() {
|
||||||
println!(" Title: {}", title.get());
|
println!(" Title: {}", title.get());
|
||||||
|
@ -193,10 +205,18 @@ impl Player {
|
||||||
let percent = buffering.percent();
|
let percent = buffering.percent();
|
||||||
if percent < 100 {
|
if percent < 100 {
|
||||||
*buffer_bus_ctrl.write().unwrap() = Some(percent as u8);
|
*buffer_bus_ctrl.write().unwrap() = Some(percent as u8);
|
||||||
playbin_bus_ctrl.write().unwrap().set_state(gst::State::Paused).unwrap();
|
playbin_bus_ctrl
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_state(gst::State::Paused)
|
||||||
|
.unwrap();
|
||||||
} else if *paused_bus_ctrl.read().unwrap() == false {
|
} else if *paused_bus_ctrl.read().unwrap() == false {
|
||||||
*buffer_bus_ctrl.write().unwrap() = None;
|
*buffer_bus_ctrl.write().unwrap() = None;
|
||||||
playbin_bus_ctrl.write().unwrap().set_state(gst::State::Playing).unwrap();
|
playbin_bus_ctrl
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_state(gst::State::Playing)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -239,7 +259,10 @@ impl Player {
|
||||||
self.source = Some(source.clone());
|
self.source = Some(source.clone());
|
||||||
match source {
|
match source {
|
||||||
URI::Cue { start, end, .. } => {
|
URI::Cue { start, end, .. } => {
|
||||||
self.playbin.write().unwrap().set_property("uri", source.as_uri());
|
self.playbin
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_property("uri", source.as_uri());
|
||||||
|
|
||||||
// Set the start and end positions of the CUE file
|
// Set the start and end positions of the CUE file
|
||||||
*self.start.write().unwrap() = Some(Duration::from_std(*start).unwrap());
|
*self.start.write().unwrap() = Some(Duration::from_std(*start).unwrap());
|
||||||
|
@ -258,11 +281,15 @@ impl Player {
|
||||||
panic!("Couldn't seek to beginning of cue track in reasonable time (>20ms)");
|
panic!("Couldn't seek to beginning of cue track in reasonable time (>20ms)");
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.playbin.write().unwrap().set_property("uri", source.as_uri());
|
self.playbin
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set_property("uri", source.as_uri());
|
||||||
|
|
||||||
self.play().unwrap();
|
self.play().unwrap();
|
||||||
|
|
||||||
while uri.get::<&str>().unwrap_or("") == self.property("current-uri").get::<&str>().unwrap_or("")
|
while uri.get::<&str>().unwrap_or("")
|
||||||
|
== self.property("current-uri").get::<&str>().unwrap_or("")
|
||||||
|| self.position().is_none()
|
|| self.position().is_none()
|
||||||
{
|
{
|
||||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||||
|
@ -392,13 +419,11 @@ impl Player {
|
||||||
pub fn state(&mut self) -> PlayerState {
|
pub fn state(&mut self) -> PlayerState {
|
||||||
match *self.buffer.read().unwrap() {
|
match *self.buffer.read().unwrap() {
|
||||||
None => self.playbin.read().unwrap().current_state().into(),
|
None => self.playbin.read().unwrap().current_state().into(),
|
||||||
Some(value) => {
|
Some(value) => PlayerState::Buffering(value),
|
||||||
PlayerState::Buffering(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn property(&self, property: &str) -> glib::Value {
|
pub fn property(&self, property: &str) -> glib::Value {
|
||||||
self.playbin.read().unwrap().property_value(property)
|
self.playbin.read().unwrap().property_value(property)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,12 @@ use std::ops::ControlFlow::{Break, Continue};
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
use file_format::{FileFormat, Kind};
|
use file_format::{FileFormat, Kind};
|
||||||
|
use glib::filename_to_uri;
|
||||||
use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt};
|
use lofty::{AudioFile, ItemKey, ItemValue, ParseOptions, Probe, TagType, TaggedFileExt};
|
||||||
use rcue::parser::parse_from_file;
|
use rcue::parser::parse_from_file;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use glib::filename_to_uri;
|
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
use chrono::{serde::ts_milliseconds_option, DateTime, Utc};
|
use chrono::{serde::ts_milliseconds_option, DateTime, Utc};
|
||||||
|
@ -102,7 +102,7 @@ impl ToString for Field {
|
||||||
Self::Rating(rating) => rating.to_string(),
|
Self::Rating(rating) => rating.to_string(),
|
||||||
Self::Format(format) => match format.short_name() {
|
Self::Format(format) => match format.short_name() {
|
||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
None => format.to_string()
|
None => format.to_string(),
|
||||||
},
|
},
|
||||||
Self::Duration(duration) => duration.as_millis().to_string(),
|
Self::Duration(duration) => duration.as_millis().to_string(),
|
||||||
Self::PlayTime(time) => time.as_millis().to_string(),
|
Self::PlayTime(time) => time.as_millis().to_string(),
|
||||||
|
@ -153,14 +153,14 @@ impl Song {
|
||||||
pub fn get_field(&self, target_field: &str) -> Option<Field> {
|
pub fn get_field(&self, target_field: &str) -> Option<Field> {
|
||||||
let lower_target = target_field.to_lowercase();
|
let lower_target = target_field.to_lowercase();
|
||||||
match lower_target.as_str() {
|
match lower_target.as_str() {
|
||||||
"location" => Some(Field::Location(self.location.clone())),
|
"location" => Some(Field::Location(self.location.clone())),
|
||||||
"plays" => Some(Field::Plays(self.plays)),
|
"plays" => Some(Field::Plays(self.plays)),
|
||||||
"skips" => Some(Field::Skips(self.skips)),
|
"skips" => Some(Field::Skips(self.skips)),
|
||||||
"favorited" => Some(Field::Favorited(self.favorited)),
|
"favorited" => Some(Field::Favorited(self.favorited)),
|
||||||
"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.map(Field::Format),
|
"format" => self.format.map(Field::Format),
|
||||||
_ => todo!(), // Other field types are not yet supported
|
_ => todo!(), // Other field types are not yet supported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,8 +228,12 @@ impl URI {
|
||||||
|
|
||||||
pub fn as_uri(&self) -> String {
|
pub fn as_uri(&self) -> String {
|
||||||
let path_str = match self {
|
let path_str = match self {
|
||||||
URI::Local(location) => filename_to_uri(location, None).expect("couldn't convert path to URI").to_string(),
|
URI::Local(location) => filename_to_uri(location, None)
|
||||||
URI::Cue { location, .. } => filename_to_uri(location, None).expect("couldn't convert path to URI").to_string(),
|
.expect("couldn't convert path to URI")
|
||||||
|
.to_string(),
|
||||||
|
URI::Cue { location, .. } => filename_to_uri(location, None)
|
||||||
|
.expect("couldn't convert path to URI")
|
||||||
|
.to_string(),
|
||||||
URI::Remote(_, location) => location.clone(),
|
URI::Remote(_, location) => location.clone(),
|
||||||
};
|
};
|
||||||
path_str.to_string()
|
path_str.to_string()
|
||||||
|
@ -492,7 +496,7 @@ impl MusicLibrary {
|
||||||
None => blank_tag,
|
None => blank_tag,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
Err(_) => blank_tag,
|
Err(_) => blank_tag,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
use file_format::{FileFormat, Kind};
|
||||||
use std::io::{BufReader, BufWriter};
|
use std::io::{BufReader, BufWriter};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::{error::Error, fs};
|
use std::{error::Error, fs};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use file_format::{FileFormat, Kind};
|
|
||||||
|
|
||||||
use snap;
|
use snap;
|
||||||
|
|
||||||
use super::music_db::{Song, AlbumArt, URI};
|
use super::music_db::{AlbumArt, Song, URI};
|
||||||
use unidecode::unidecode;
|
use unidecode::unidecode;
|
||||||
|
|
||||||
pub(super) fn normalize(input_string: &str) -> String {
|
pub(super) fn normalize(input_string: &str) -> String {
|
||||||
|
@ -76,8 +76,9 @@ pub fn find_images(song_path: &Path) -> Result<Vec<AlbumArt>, Box<dyn Error>> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
{
|
{
|
||||||
if target_file.depth() >= 3 { // Don't recurse very deep
|
if target_file.depth() >= 3 {
|
||||||
break
|
// Don't recurse very deep
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = target_file.path();
|
let path = target_file.path();
|
||||||
|
@ -87,7 +88,7 @@ pub fn find_images(song_path: &Path) -> Result<Vec<AlbumArt>, Box<dyn Error>> {
|
||||||
|
|
||||||
let format = FileFormat::from_file(path)?.kind();
|
let format = FileFormat::from_file(path)?.kind();
|
||||||
if format != Kind::Image {
|
if format != Kind::Image {
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let image_uri = URI::Local(path.to_path_buf().canonicalize().unwrap());
|
let image_uri = URI::Local(path.to_path_buf().canonicalize().unwrap());
|
||||||
|
|
Loading…
Reference in a new issue