From 1cc75e202eaa99f9f91ff1d83523380bd0198817 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 22 Mar 2022 17:50:38 +0100 Subject: [PATCH] Update dependencies --- .gitignore | 1 + Cargo.lock | 386 ++++++++++++++++++++++++++--------- Cargo.toml | 10 +- src/bin/id3-image-embed.rs | 9 +- src/bin/id3-image-extract.rs | 15 +- src/bin/id3-image-remove.rs | 4 +- src/lib.rs | 51 +++-- tests/test_processing.rs | 13 +- 8 files changed, 358 insertions(+), 131 deletions(-) diff --git a/.gitignore b/.gitignore index 53eaa21..2bb8d25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target **/*.rs.bk +.idea diff --git a/Cargo.lock b/Cargo.lock index e5588fe..6f50632 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,11 +1,19 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "adler32" version = "1.2.0" @@ -14,9 +22,9 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" [[package]] name = "autocfg" @@ -24,6 +32,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + [[package]] name = "bitflags" version = "1.2.1" @@ -31,10 +45,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] -name = "bytemuck" -version = "1.5.0" +name = "bumpalo" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a4bad0c5981acc24bc09e532f35160f952e35422603f0563cd7a73c2c2e65a0" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" + +[[package]] +name = "bytemuck" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e851ca7c24871e7336801608a4797d7376545b6928a10d32d75685687141ead" [[package]] name = "byteorder" @@ -128,12 +148,11 @@ dependencies = [ [[package]] name = "deflate" -version = "0.8.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" +checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" dependencies = [ "adler32", - "byteorder", ] [[package]] @@ -142,6 +161,31 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "exr" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4badb9489a465cb2c555af1f00f0bfd8cecd6fc12ac11da9d5b40c5dd5f0200" +dependencies = [ + "bit_field", + "deflate", + "flume", + "half", + "inflate", + "lebe", + "smallvec", + "threadpool", +] + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + [[package]] name = "flate2" version = "1.0.20" @@ -155,14 +199,41 @@ dependencies = [ ] [[package]] -name = "getrandom" -version = "0.2.2" +name = "flume" +version = "0.10.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "843c03199d0c0ca54bc1ea90ac0d507274c28abcc4f691ae8b4eaa375087c76a" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[package]] +name = "futures-sink" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" + +[[package]] +name = "getrandom" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -175,6 +246,12 @@ dependencies = [ "weezl", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "heck" version = "0.3.2" @@ -195,9 +272,9 @@ dependencies = [ [[package]] name = "id3" -version = "0.6.2" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7757528cac50df8681481dc91fd0b0e4a9886f78db9b6579d3c181d1184c7d94" +checksum = "7a3598f9ed06d8a7ff358dc1a52f07f98d6625b996ad60588805b3d8cfd4d0cd" dependencies = [ "bitflags", "byteorder", @@ -217,15 +294,16 @@ dependencies = [ [[package]] name = "image" -version = "0.23.13" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "293f07a1875fa7e9c5897b51aa68b2d8ed8271b87e1a44cb64b9c3d98aabbc0d" +checksum = "db207d030ae38f1eb6f240d5a1c1c88ff422aa005d10f8c6c6fc5e75286ab30e" dependencies = [ "bytemuck", "byteorder", "color_quant", + "exr", "gif", - "jpeg-decoder", + "jpeg-decoder 0.2.2", "num-iter", "num-rational", "num-traits", @@ -234,27 +312,84 @@ dependencies = [ "tiff", ] +[[package]] +name = "inflate" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" +dependencies = [ + "adler32", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "jpeg-decoder" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" + +[[package]] +name = "jpeg-decoder" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "105fb082d64e2100074587f59a74231f771750c664af903f1f9f76c9dedfc6f1" dependencies = [ "rayon", ] +[[package]] +name = "js-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lebe" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7efd1d698db0759e6ef11a7cd44407407399a910c774dd804c64c032da7826ff" + [[package]] name = "libc" version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +[[package]] +name = "lock_api" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +dependencies = [ + "cfg-if", +] + [[package]] name = "memoffset" version = "0.6.1" @@ -264,25 +399,34 @@ dependencies = [ "autocfg", ] -[[package]] -name = "miniz_oxide" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" -dependencies = [ - "adler32", -] - [[package]] name = "miniz_oxide" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" dependencies = [ - "adler", + "adler 0.2.3", "autocfg", ] +[[package]] +name = "miniz_oxide" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" +dependencies = [ + "adler 1.0.2", +] + +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -306,9 +450,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ "autocfg", "num-integer", @@ -335,23 +479,37 @@ dependencies = [ ] [[package]] -name = "png" -version = "0.16.8" +name = "pin-project" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" +checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "png" +version = "0.17.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" dependencies = [ "bitflags", "crc32fast", "deflate", - "miniz_oxide 0.3.7", + "miniz_oxide 0.5.1", ] -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -394,46 +552,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core", -] - [[package]] name = "rayon" version = "1.5.0" @@ -461,9 +579,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.5" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" dependencies = [ "bitflags", ] @@ -490,10 +608,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] -name = "structopt" -version = "0.3.21" +name = "smallvec" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "spin" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +dependencies = [ + "lock_api", +] + +[[package]] +name = "structopt" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ "clap", "lazy_static", @@ -502,9 +635,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.14" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", "proc-macro-error", @@ -515,9 +648,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.60" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" dependencies = [ "proc-macro2", "quote", @@ -526,13 +659,13 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if", + "fastrand", "libc", - "rand", "redox_syscall", "remove_dir_all", "winapi", @@ -548,13 +681,22 @@ dependencies = [ ] [[package]] -name = "tiff" -version = "0.6.1" +name = "threadpool" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" dependencies = [ - "jpeg-decoder", - "miniz_oxide 0.4.3", + "num_cpus", +] + +[[package]] +name = "tiff" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0247608e998cb6ce39dfc8f4a16c50361ce71e5b52e6d24ea1227ea8ea8ee0b2" +dependencies = [ + "flate2", + "jpeg-decoder 0.1.22", "weezl", ] @@ -588,6 +730,60 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasm-bindgen" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" + [[package]] name = "weezl" version = "0.1.4" diff --git a/Cargo.toml b/Cargo.toml index 40e4c93..f0068e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,10 @@ categories = [ "command-line-utilities", "filesystem", "multimedia" ] travis-ci = { repository = "AndrewRadev/id3-image" } [dependencies] -anyhow = "1.0.38" -id3 = "0.6.2" -image = "0.23.13" -structopt = { version = "0.3.21", default-features = false } +anyhow = "1.0.56" +id3 = "1.0.2" +image = "0.24.1" +structopt = { version = "0.3.26", default-features = false } [dev-dependencies] -tempfile = "3.2.0" +tempfile = "3.3.0" diff --git a/src/bin/id3-image-embed.rs b/src/bin/id3-image-embed.rs index c1a3043..40f828f 100644 --- a/src/bin/id3-image-embed.rs +++ b/src/bin/id3-image-embed.rs @@ -1,8 +1,8 @@ -use std::process; use std::path::PathBuf; +use std::process; -use structopt::StructOpt; use id3_image::embed_image; +use structopt::StructOpt; #[derive(StructOpt, Debug)] #[structopt(name = "id3-image-embed")] @@ -28,8 +28,9 @@ fn main() { let opt = Opt::from_args(); let verbosity = if opt.quiet { -1 } else { opt.verbose }; let music_filename = opt.music_filename; - let image_filename = opt.image_filename. - unwrap_or_else(|| music_filename.with_extension("jpg")); + let image_filename = opt + .image_filename + .unwrap_or_else(|| music_filename.with_extension("jpg")); if let Err(e) = embed_image(&music_filename, &image_filename) { if verbosity >= 0 { diff --git a/src/bin/id3-image-extract.rs b/src/bin/id3-image-extract.rs index 96f80fc..7f7f1c8 100644 --- a/src/bin/id3-image-extract.rs +++ b/src/bin/id3-image-extract.rs @@ -1,8 +1,8 @@ -use std::process; use std::path::PathBuf; +use std::process; -use structopt::StructOpt; use id3_image::extract_first_image; +use structopt::StructOpt; #[derive(StructOpt, Debug)] #[structopt(name = "id3-image-embed")] @@ -28,8 +28,10 @@ fn main() { let opt = Opt::from_args(); let verbosity = if opt.quiet { -1 } else { opt.verbose }; - let image_filename = opt.image_filename.clone(). - unwrap_or_else(|| opt.music_filename.with_extension("jpg")); + let image_filename = opt + .image_filename + .clone() + .unwrap_or_else(|| opt.music_filename.with_extension("jpg")); if let Err(e) = extract_first_image(&opt.music_filename, &image_filename) { if verbosity >= 0 { @@ -43,6 +45,9 @@ fn main() { println!("{}", image_filename.display()); } else if verbosity >= 2 { // show a longer status message: - println!("Extracted cover art from {:?} to {:?}", opt.music_filename, image_filename); + println!( + "Extracted cover art from {:?} to {:?}", + opt.music_filename, image_filename + ); } } diff --git a/src/bin/id3-image-remove.rs b/src/bin/id3-image-remove.rs index 7592697..021cbac 100644 --- a/src/bin/id3-image-remove.rs +++ b/src/bin/id3-image-remove.rs @@ -1,9 +1,9 @@ -use std::process; use std::io::{self, Write}; use std::path::PathBuf; +use std::process; -use structopt::StructOpt; use id3_image::remove_images; +use structopt::StructOpt; #[derive(StructOpt, Debug)] #[structopt(name = "id3-image-remove")] diff --git a/src/lib.rs b/src/lib.rs index cc1fb6c..2cc4f37 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,11 @@ //! A command-line tool to embed images into mp3 files. The real work is done by the "id3" crate, //! but this project makes it easier to deal with embedded cover art in particular. +use std::io::Cursor; use std::path::Path; use anyhow::anyhow; +use id3::TagLike; use image::DynamicImage; /// Embed the image from `image_filename` into `music_filename`, in-place. Any errors reading ID3 @@ -15,8 +17,8 @@ use image::DynamicImage; /// Tags get written as ID3v2.3. /// pub fn embed_image(music_filename: &Path, image_filename: &Path) -> anyhow::Result<()> { - let image = image::open(&image_filename). - map_err(|e| anyhow!("Error reading image {:?}: {}", image_filename, e))?; + let image = image::open(&image_filename) + .map_err(|e| anyhow!("Error reading image {:?}: {}", image_filename, e))?; embed_image_from_memory(music_filename, &image) } @@ -27,22 +29,33 @@ pub fn embed_image(music_filename: &Path, image_filename: &Path) -> anyhow::Resu /// The image is encoded as a JPEG with a 90% quality setting, and embedded as a "Front cover". /// Tags get written as ID3v2.3. /// -pub fn embed_image_from_memory(music_filename: &Path, image: &image::DynamicImage) -> anyhow::Result<()> { +pub fn embed_image_from_memory( + music_filename: &Path, + image: &image::DynamicImage, +) -> anyhow::Result<()> { let mut tag = read_tag(music_filename)?; - let mut encoded_image_bytes = Vec::new(); + let mut encoded_image_bytes = Cursor::new(Vec::new()); // Unwrap: Writing to a Vec should always succeed; - image.write_to(&mut encoded_image_bytes, image::ImageOutputFormat::Jpeg(90)).unwrap(); + image + .write_to(&mut encoded_image_bytes, image::ImageOutputFormat::Jpeg(90)) + .unwrap(); - tag.add_picture(id3::frame::Picture { + tag.add_frame(id3::frame::Picture { mime_type: "image/jpeg".to_string(), picture_type: id3::frame::PictureType::CoverFront, description: String::new(), - data: encoded_image_bytes, + data: encoded_image_bytes.into_inner(), }); - tag.write_to_path(music_filename, id3::Version::Id3v23). - map_err(|e| anyhow!("Error writing image to music file {:?}: {}", music_filename, e))?; + tag.write_to_path(music_filename, id3::Version::Id3v23) + .map_err(|e| { + anyhow!( + "Error writing image to music file {:?}: {}", + music_filename, + e + ) + })?; Ok(()) } @@ -55,8 +68,8 @@ pub fn embed_image_from_memory(music_filename: &Path, image: &image::DynamicImag /// pub fn extract_first_image(music_filename: &Path, image_filename: &Path) -> anyhow::Result<()> { extract_first_image_as_img(music_filename)? - .save(&image_filename). - map_err(|e| anyhow!("Couldn't write image file {:?}: {}", image_filename, e)) + .save(&image_filename) + .map_err(|e| anyhow!("Couldn't write image file {:?}: {}", image_filename, e)) } /// Extract the first found embedded image from `music_filename` and return it as image object @@ -69,8 +82,7 @@ pub fn extract_first_image_as_img(music_filename: &Path) -> anyhow::Result anyhow::Result<()> { let mut tag = read_tag(music_filename)?; tag.remove("APIC"); - tag.write_to_path(music_filename, id3::Version::Id3v23). - map_err(|e| anyhow!("Error updating music file {:?}: {}", music_filename, e))?; + tag.write_to_path(music_filename, id3::Version::Id3v23) + .map_err(|e| anyhow!("Error updating music file {:?}: {}", music_filename, e))?; Ok(()) } fn read_tag(path: &Path) -> anyhow::Result { id3::Tag::read_from_path(&path).or_else(|e| { - eprintln!("Warning: file metadata is corrupted, trying to read partial tag: {}", path.display()); - e.partial_tag.clone().ok_or_else(|| anyhow!("Error reading music file {:?}: {}", path, e)) + eprintln!( + "Warning: file metadata is corrupted, trying to read partial tag: {}", + path.display() + ); + e.partial_tag + .clone() + .ok_or_else(|| anyhow!("Error reading music file {:?}: {}", path, e)) }) } diff --git a/tests/test_processing.rs b/tests/test_processing.rs index 8616161..65b9a59 100644 --- a/tests/test_processing.rs +++ b/tests/test_processing.rs @@ -24,7 +24,11 @@ impl Fixture { let mut path = PathBuf::from(&tempdir.path()); path.push(&fixture_filename); - Fixture { _tempdir: tempdir, source, path } + Fixture { + _tempdir: tempdir, + source, + path, + } } fn copy(fixture_filename: &str) -> Self { @@ -46,7 +50,6 @@ fn read_tag(path: &Path) -> id3::Tag { id3::Tag::read_from_path(path).unwrap() } - #[test] fn test_unsuccessful_image_embedding() { let song = Fixture::copy("attempt_1_no_image.mp3"); @@ -55,7 +58,11 @@ fn test_unsuccessful_image_embedding() { // Nonexistent files assert!(embed_image(&song, &PathBuf::from("nonexistent.jpg")).is_err()); assert!(embed_image(&PathBuf::from("nonexistent.mp3"), &image).is_err()); - assert!(embed_image(&PathBuf::from("nonexistent.mp3"), &PathBuf::from("nonexistent.jpg")).is_err()); + assert!(embed_image( + &PathBuf::from("nonexistent.mp3"), + &PathBuf::from("nonexistent.jpg") + ) + .is_err()); // Wrong kinds of files assert!(embed_image(&image, &song).is_err());