Start differentiating between mime types of files

This commit is contained in:
Savanni D'Gerinel 2023-03-01 23:54:23 -05:00
parent 226329ab6d
commit 2cc7bf2bca
4 changed files with 69 additions and 214 deletions

View File

@ -87,63 +87,6 @@ dependencies = [
"typenum",
]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote 1.0.23",
"strsim",
"syn 1.0.107",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core",
"quote 1.0.23",
"syn 1.0.107",
]
[[package]]
name = "dbus"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b"
dependencies = [
"libc",
"libdbus-sys",
"winapi",
]
[[package]]
name = "derive_is_enum_variant"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0ac8859845146979953797f03cc5b282fb4396891807cdb3d04929a88418197"
dependencies = [
"heck",
"quote 0.3.15",
"syn 0.11.11",
]
[[package]]
name = "digest"
version = "0.10.6"
@ -154,17 +97,6 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "enum-kinds"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e40a16955681d469ab3da85aaa6b42ff656b3c67b52e1d8d3dd36afe97fd462"
dependencies = [
"proc-macro2",
"quote 1.0.23",
"syn 1.0.107",
]
[[package]]
name = "fallible-iterator"
version = "0.2.0"
@ -205,27 +137,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "from_variants"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd6e0c314d32a210f213d2de7fc205a415498c32477022bffdb8927a95f44493"
dependencies = [
"from_variants_impl",
]
[[package]]
name = "from_variants_impl"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "243da8644e4e4ac28a22f7f30187f9d3f17eafbc219884ff8935edb5ebfe621c"
dependencies = [
"darling",
"proc-macro2",
"quote 1.0.23",
"syn 1.0.107",
]
[[package]]
name = "futures-channel"
version = "0.3.25"
@ -351,15 +262,6 @@ dependencies = [
"http",
]
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.2.6"
@ -427,12 +329,6 @@ dependencies = [
"want",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "0.3.0"
@ -474,15 +370,6 @@ version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "libdbus-sys"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2264f9d90a9b4e60a2dc722ad899ea0374f03c2e96e755fe22a8f551d4d5fb3c"
dependencies = [
"pkg-config",
]
[[package]]
name = "libsqlite3-sys"
version = "0.25.2"
@ -546,19 +433,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "mpris"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e3d377fd27d9d5c7145341cd3affcb83839c24c73e7460488b3ae0a3f9c5166"
dependencies = [
"dbus",
"derive_is_enum_variant",
"enum-kinds",
"from_variants",
"thiserror",
]
[[package]]
name = "multipart"
version = "0.18.0"
@ -581,10 +455,9 @@ dependencies = [
name = "music-player"
version = "0.1.0"
dependencies = [
"dbus",
"flow",
"mime",
"mime_guess",
"mpris",
"rusqlite",
"serde",
"thiserror",
@ -655,8 +528,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
dependencies = [
"proc-macro2",
"quote 1.0.23",
"syn 1.0.107",
"quote",
"syn",
]
[[package]]
@ -698,12 +571,6 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
[[package]]
name = "quote"
version = "1.0.23"
@ -824,8 +691,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote 1.0.23",
"syn 1.0.107",
"quote",
"syn",
]
[[package]]
@ -907,23 +774,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
dependencies = [
"quote 0.3.15",
"synom",
"unicode-xid",
]
[[package]]
name = "syn"
version = "1.0.107"
@ -931,19 +781,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
"proc-macro2",
"quote 1.0.23",
"quote",
"unicode-ident",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
dependencies = [
"unicode-xid",
]
[[package]]
name = "tempfile"
version = "3.3.0"
@ -974,8 +815,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote 1.0.23",
"syn 1.0.107",
"quote",
"syn",
]
[[package]]
@ -1020,8 +861,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote 1.0.23",
"syn 1.0.107",
"quote",
"syn",
]
[[package]]
@ -1158,18 +999,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
[[package]]
name = "url"
version = "2.3.1"

View File

@ -6,10 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dbus = { version = "0.9.7" }
flow = { path = "../../flow" }
mime_guess = "2.0.4"
mpris = { version = "2.0" }
mime = { version = "0.3" }
mime_guess = { version = "2.0" }
rusqlite = { version = "0.28" }
serde = { version = "1.0", features = ["derive"] }
thiserror = { version = "1.0" }

View File

@ -10,7 +10,7 @@ Luminescent Dreams Tools is distributed in the hope that it will be useful, but
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
*/
use serde::Serialize;
use serde::{Serialize, Serializer};
use std::time::Duration;
use thiserror::Error;
@ -46,28 +46,10 @@ pub enum AudioError {
#[error("Play was ordered, but nothing is in the queue")]
NothingInQueue,
#[error("Unknown dbus error")]
DbusError(dbus::Error),
#[error("Unknown problem with mpris")]
MprisError(mpris::DBusError),
#[error("url parse error {0}")]
UrlError(url::ParseError),
}
impl From<dbus::Error> for AudioError {
fn from(err: dbus::Error) -> Self {
Self::DbusError(err)
}
}
impl From<mpris::DBusError> for AudioError {
fn from(err: mpris::DBusError) -> Self {
Self::MprisError(err)
}
}
impl From<url::ParseError> for AudioError {
fn from(err: url::ParseError) -> Self {
Self::UrlError(err)
@ -102,6 +84,15 @@ pub struct TrackInfo {
pub name: Option<String>,
pub album: Option<String>,
pub artist: Option<String>,
#[serde(serialize_with = "serialize_mime")]
pub filetype: mime::Mime,
}
fn serialize_mime<S>(val: &mime::Mime, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s.serialize_str(val.essence_str())
}
#[derive(Clone, Debug, Serialize)]

View File

@ -1,7 +1,7 @@
use crate::audio::{TrackId, TrackInfo};
use std::{
fs::{DirEntry, ReadDir},
path::PathBuf,
path::{Path, PathBuf},
};
use thiserror::Error;
@ -42,7 +42,16 @@ pub struct FileIterator {
impl FileIterator {
fn scan_file(&self, path: PathBuf) -> Result<TrackInfo, ScannerError> {
Ok(TrackInfo {
println!(
"[{:?}] {}",
mime_guess::from_path(path.clone()).first(),
path.to_str().unwrap()
);
let mimetype = mime_guess::from_path(path.clone())
.first()
.ok_or(ScannerError::CannotScan(path.clone()))?;
match (mimetype.type_(), mimetype.subtype().as_str()) {
(mime::AUDIO, "mpeg") => Ok(TrackInfo {
id: TrackId::from(path.to_str().unwrap().to_owned()),
album: None,
artist: None,
@ -51,7 +60,34 @@ impl FileIterator {
.and_then(|s| s.to_str())
.map(|s| s.to_owned()),
track_number: None,
})
filetype: mimetype,
}),
/*
(mime::AUDIO, "ogg") => Ok(TrackInfo {
id: TrackId::from(path.to_str().unwrap().to_owned()),
album: None,
artist: None,
name: path
.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_owned()),
track_number: None,
filetype: mimetype,
}),
(mime::AUDIO, "flac") => Ok(TrackInfo {
id: TrackId::from(path.to_str().unwrap().to_owned()),
album: None,
artist: None,
name: path
.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_owned()),
track_number: None,
filetype: mimetype,
}),
*/
_ => Err(ScannerError::CannotScan(path)),
}
}
}