Merge ed581c57cf into release

This commit is contained in:
github-actions[bot] 2021-04-25 05:08:24 +00:00 committed by GitHub
commit 765a5ae839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 184 additions and 189 deletions

199
Cargo.lock generated
View file

@ -108,8 +108,8 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655"
dependencies = [
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -277,8 +277,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -346,8 +346,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -724,8 +724,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -747,8 +747,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -791,70 +791,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "encoding"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
dependencies = [
"encoding-index-japanese",
"encoding-index-korean",
"encoding-index-simpchinese",
"encoding-index-singlebyte",
"encoding-index-tradchinese",
]
[[package]]
name = "encoding-index-japanese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-korean"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-simpchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-singlebyte"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-tradchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding_index_tests"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
[[package]]
name = "encoding_rs"
version = "0.8.26"
@ -872,8 +808,8 @@ checksum = "7c5f0096a91d210159eceb2ff5e1c4da18388a170e1e3ce948aac9c8fdbbf595"
dependencies = [
"heck",
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -985,8 +921,8 @@ checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -1224,15 +1160,13 @@ checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
[[package]]
name = "id3"
version = "0.5.1"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02c11bb50ce1568516aefbe4b6564c3feaf15a8e5ccbea90fa652012446ae9bf"
checksum = "bbe9b826aaa15b25bfb73c18ca9507a0ced87578a62376a7751dc6a510e3d244"
dependencies = [
"bitflags",
"byteorder",
"encoding",
"flate2",
"lazy_static",
]
[[package]]
@ -1471,8 +1405,8 @@ checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c"
dependencies = [
"migrations_internals",
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -1584,8 +1518,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e12bdd46113e604a98d04f19f79249e1679be21a65eaa1dbadec16ba00c94f7"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -1794,8 +1728,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -1805,8 +1739,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -1921,7 +1855,7 @@ version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid 0.2.1",
"unicode-xid",
]
[[package]]
@ -1952,12 +1886,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.7"
@ -2110,9 +2038,9 @@ dependencies = [
[[package]]
name = "rustfm-scrobble"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d90702f7f49119bcec6ef26efd3f0e9ce600b2e430dc5fb65238132bd9e0f0d9"
checksum = "2c46a75fb6409a528f7e0d8e99826684f88461d1b0d0edeec60d82e3f554dad5"
dependencies = [
"md5",
"serde",
@ -2202,8 +2130,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -2353,10 +2281,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"quote",
"serde",
"serde_derive",
"syn 1.0.54",
"syn",
]
[[package]]
@ -2367,12 +2295,12 @@ checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2",
"quote 1.0.7",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1",
"syn 1.0.54",
"syn",
]
[[package]]
@ -2387,17 +2315,6 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
[[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 0.0.4",
]
[[package]]
name = "syn"
version = "1.0.54"
@ -2405,17 +2322,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"unicode-xid 0.2.1",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
dependencies = [
"unicode-xid 0.0.4",
"quote",
"unicode-xid",
]
[[package]]
@ -2443,8 +2351,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -2509,9 +2417,9 @@ checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote 1.0.7",
"quote",
"standback",
"syn 1.0.54",
"syn",
]
[[package]]
@ -2694,12 +2602,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
[[package]]
name = "unicode-xid"
version = "0.2.1"
@ -2761,8 +2663,8 @@ checksum = "c860ad1273f4eee7006cee05db20c9e60e5d24cba024a32e1094aa8e574f3668"
dependencies = [
"nom",
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
]
[[package]]
@ -2825,8 +2727,8 @@ dependencies = [
"lazy_static",
"log",
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
"wasm-bindgen-shared",
]
@ -2836,7 +2738,7 @@ version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
dependencies = [
"quote 1.0.7",
"quote",
"wasm-bindgen-macro-support",
]
@ -2847,8 +2749,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
dependencies = [
"proc-macro2",
"quote 1.0.7",
"syn 1.0.54",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -2963,12 +2865,13 @@ dependencies = [
[[package]]
name = "wrapped-vec"
version = "0.2.1"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06c29bb4abe93d1c8ef79b60f270d0efcaa6c5c97aaaaaaa0d477ea72f5f9e45"
checksum = "b85e08702c1e919669e1e90213c9c75ea4bb689d0f3970347e2b37c04600b4e5"
dependencies = [
"quote 0.3.15",
"syn 0.11.11",
"proc-macro2",
"quote",
"syn",
]
[[package]]

View file

@ -24,7 +24,7 @@ diesel_migrations = { version = "1.4", features = ["sqlite"] }
futures-util = { version = "0.3" }
getopts = "0.2.15"
http = "0.2.2"
id3 = "0.5.1"
id3 = "0.6.4"
libsqlite3-sys = { version = "0.18", features = ["bundled", "bundled-windows"], optional = true }
lewton = "0.10.1"
log = "0.4.5"
@ -38,7 +38,7 @@ pbkdf2 = "0.6"
rand = "0.7"
rayon = "1.3"
regex = "1.3.9"
rustfm-scrobble = "1.1"
rustfm-scrobble = "1.1.1"
serde = { version = "1.0.111", features = ["derive"] }
serde_derive = "1.0.111"
serde_json = "1.0.53"

View file

@ -27,15 +27,47 @@ pub struct SongTags {
pub has_artwork: bool,
}
impl From<id3::Tag> for SongTags {
fn from(tag: id3::Tag) -> Self {
let artist = tag.artist().map(|s| s.to_string());
let album_artist = tag.album_artist().map(|s| s.to_string());
let album = tag.album().map(|s| s.to_string());
let title = tag.title().map(|s| s.to_string());
let duration = tag.duration();
let disc_number = tag.disc();
let track_number = tag.track();
let year = tag
.year()
.map(|y| y as i32)
.or_else(|| tag.date_released().map(|d| d.year))
.or_else(|| tag.date_recorded().map(|d| d.year));
let has_artwork = tag.pictures().count() > 0;
SongTags {
artist,
album_artist,
album,
title,
duration,
disc_number,
track_number,
year,
has_artwork,
}
}
}
pub fn read(path: &Path) -> Option<SongTags> {
let data = match utils::get_audio_format(path) {
Some(AudioFormat::AIFF) => Some(read_aiff(path)),
Some(AudioFormat::APE) => Some(read_ape(path)),
Some(AudioFormat::FLAC) => Some(read_flac(path)),
Some(AudioFormat::MP3) => Some(read_id3(path)),
Some(AudioFormat::MP3) => Some(read_mp3(path)),
Some(AudioFormat::MP4) => Some(read_mp4(path)),
Some(AudioFormat::MPC) => Some(read_ape(path)),
Some(AudioFormat::OGG) => Some(read_vorbis(path)),
Some(AudioFormat::OPUS) => Some(read_opus(path)),
Some(AudioFormat::WAVE) => Some(read_wave(path)),
None => None,
};
match data {
@ -48,49 +80,46 @@ pub fn read(path: &Path) -> Option<SongTags> {
}
}
fn read_id3(path: &Path) -> Result<SongTags> {
let tag = {
match id3::Tag::read_from_path(&path) {
Ok(t) => Ok(t),
Err(e) => {
if let Some(t) = e.partial_tag {
Ok(t)
} else {
Err(e)
}
}
}?
};
fn read_mp3(path: &Path) -> Result<SongTags> {
let tag = id3::Tag::read_from_path(&path).or_else(|error| {
if let Some(tag) = error.partial_tag {
Ok(tag)
} else {
Err(error)
}
})?;
let duration = {
mp3_duration::from_path(&path)
.map(|d| d.as_secs() as u32)
.ok()
};
let artist = tag.artist().map(|s| s.to_string());
let album_artist = tag.album_artist().map(|s| s.to_string());
let album = tag.album().map(|s| s.to_string());
let title = tag.title().map(|s| s.to_string());
let disc_number = tag.disc();
let track_number = tag.track();
let year = tag
.year()
.map(|y| y as i32)
.or_else(|| tag.date_released().and_then(|d| Some(d.year)))
.or_else(|| tag.date_recorded().and_then(|d| Some(d.year)));
let has_artwork = tag.pictures().count() > 0;
let mut song_tags: SongTags = tag.into();
song_tags.duration = duration; // Use duration from mp3_duration instead of from tags.
Ok(song_tags)
}
Ok(SongTags {
artist,
album_artist,
album,
title,
duration,
disc_number,
track_number,
year,
has_artwork,
})
fn read_aiff(path: &Path) -> Result<SongTags> {
let tag = id3::Tag::read_from_aiff(&path).or_else(|error| {
if let Some(tag) = error.partial_tag {
Ok(tag)
} else {
Err(error)
}
})?;
Ok(tag.into())
}
fn read_wave(path: &Path) -> Result<SongTags> {
let tag = id3::Tag::read_from_wav(&path).or_else(|error| {
if let Some(tag) = error.partial_tag {
Ok(tag)
} else {
Err(error)
}
})?;
Ok(tag.into())
}
fn read_ape_string(item: &ape::Item) -> Option<String> {
@ -282,6 +311,10 @@ fn reads_file_metadata() {
duration: Some(0),
..sample_tags.clone()
};
assert_eq!(
read(Path::new("test-data/formats/sample.aif")).unwrap(),
sample_tags
);
assert_eq!(
read(Path::new("test-data/formats/sample.mp3")).unwrap(),
mp3_sample_tag
@ -306,10 +339,19 @@ fn reads_file_metadata() {
read(Path::new("test-data/formats/sample.ape")).unwrap(),
sample_tags
);
assert_eq!(
read(Path::new("test-data/formats/sample.wav")).unwrap(),
sample_tags
);
}
#[test]
fn reads_embedded_artwork() {
assert!(
read(Path::new("test-data/artwork/sample.aif"))
.unwrap()
.has_artwork
);
assert!(
read(Path::new("test-data/artwork/sample.mp3"))
.unwrap()
@ -325,4 +367,9 @@ fn reads_embedded_artwork() {
.unwrap()
.has_artwork
);
assert!(
read(Path::new("test-data/artwork/sample.wav"))
.unwrap()
.has_artwork
);
}

View file

@ -7,13 +7,15 @@ use crate::utils::AudioFormat;
pub fn read(image_path: &Path) -> Result<DynamicImage> {
match utils::get_audio_format(image_path) {
Some(AudioFormat::AIFF) => read_aiff(image_path),
Some(AudioFormat::APE) => read_ape(image_path),
Some(AudioFormat::FLAC) => read_flac(image_path),
Some(AudioFormat::MP3) => read_id3(image_path),
Some(AudioFormat::MP3) => read_mp3(image_path),
Some(AudioFormat::MP4) => read_mp4(image_path),
Some(AudioFormat::MPC) => read_ape(image_path),
Some(AudioFormat::OGG) => read_vorbis(image_path),
Some(AudioFormat::OPUS) => read_opus(image_path),
Some(AudioFormat::WAVE) => read_wave(image_path),
None => Ok(image::open(image_path)?),
}
}
@ -37,9 +39,25 @@ fn read_flac(path: &Path) -> Result<DynamicImage> {
)))
}
fn read_id3(path: &Path) -> Result<DynamicImage> {
fn read_mp3(path: &Path) -> Result<DynamicImage> {
let tag = id3::Tag::read_from_path(path)?;
read_id3(&path, &tag)
}
fn read_aiff(path: &Path) -> Result<DynamicImage> {
let tag = id3::Tag::read_from_aiff(path)?;
read_id3(&path, &tag)
}
fn read_wave(path: &Path) -> Result<DynamicImage> {
let tag = id3::Tag::read_from_wav(path)?;
read_id3(&path, &tag)
}
fn read_id3(path: &Path, tag: &id3::Tag) -> Result<DynamicImage> {
if let Some(p) = tag.pictures().next() {
return Ok(image::load_from_memory(&p.data)?);
}
@ -88,6 +106,11 @@ fn can_read_artwork_data() {
.to_rgb8();
assert_eq!(folder_img, ext_img);
let aiff_img = read(Path::new("test-data/artwork/sample.aif"))
.unwrap()
.to_rgb8();
assert_eq!(aiff_img, embedded_img);
let ape_img = read(Path::new("test-data/artwork/sample.ape"))
.map(|d| d.to_rgb8())
.ok();
@ -117,4 +140,9 @@ fn can_read_artwork_data() {
.map(|d| d.to_rgb8())
.ok();
assert_eq!(opus_img, None);
let wave_img = read(Path::new("test-data/artwork/sample.wav"))
.unwrap()
.to_rgb8();
assert_eq!(wave_img, embedded_img);
}

View file

@ -14,6 +14,7 @@ pub use crate::match_ignore_case;
#[derive(Debug, PartialEq)]
pub enum AudioFormat {
AIFF,
APE,
FLAC,
MP3,
@ -21,6 +22,7 @@ pub enum AudioFormat {
MPC,
OGG,
OPUS,
WAVE,
}
pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
@ -33,6 +35,8 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
_ => return None,
};
match extension.to_lowercase().as_str() {
"aif" => Some(AudioFormat::AIFF),
"aiff" => Some(AudioFormat::AIFF),
"ape" => Some(AudioFormat::APE),
"flac" => Some(AudioFormat::FLAC),
"mp3" => Some(AudioFormat::MP3),
@ -40,6 +44,7 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
"mpc" => Some(AudioFormat::MPC),
"ogg" => Some(AudioFormat::OGG),
"opus" => Some(AudioFormat::OPUS),
"wav" => Some(AudioFormat::WAVE),
_ => None,
}
}
@ -47,8 +52,20 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
#[test]
fn can_guess_audio_format() {
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.jpg")), None);
assert_eq!(
get_audio_format(Path::new("animals/🐷/my🐖file.aif")),
Some(AudioFormat::AIFF)
);
assert_eq!(
get_audio_format(Path::new("animals/🐷/my🐖file.aiff")),
Some(AudioFormat::AIFF)
);
assert_eq!(
get_audio_format(Path::new("animals/🐷/my🐖file.flac")),
Some(AudioFormat::FLAC)
);
assert_eq!(
get_audio_format(Path::new("animals/🐷/my🐖file.wav")),
Some(AudioFormat::WAVE)
);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.