summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakka <jakkadoujin@gmail.com>2025-06-04 22:40:23 +0300
committerjakka <jakkadoujin@gmail.com>2025-06-04 22:40:23 +0300
commit565172d9b221e2dd72d8b925f0ba2a1fd046a244 (patch)
tree153854e3363c5d7d1c2bc9039a7ad10494c859d2
parenta7615b9471dfe6fe94a3ace6e4f94e9c78844b51 (diff)
continued working on md5sum
-rw-r--r--Cargo.lock147
-rw-r--r--Cargo.toml1
-rw-r--r--src/flac.rs39
-rw-r--r--src/main.rs4
4 files changed, 25 insertions, 166 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 786a917..2b908d9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,21 +3,6 @@
version = 4
[[package]]
-name = "addr2line"
-version = "0.24.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
-dependencies = [
- "gimli",
-]
-
-[[package]]
-name = "adler2"
-version = "2.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
-
-[[package]]
name = "anyhow"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -30,21 +15,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
-name = "backtrace"
-version = "0.3.75"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002"
-dependencies = [
- "addr2line",
- "cfg-if",
- "libc",
- "miniz_oxide",
- "object",
- "rustc-demangle",
- "windows-targets",
-]
-
-[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -135,12 +105,6 @@ dependencies = [
]
[[package]]
-name = "gimli"
-version = "0.31.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
-
-[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -183,12 +147,6 @@ dependencies = [
]
[[package]]
-name = "memchr"
-version = "2.7.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
-
-[[package]]
name = "metaflac"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -199,15 +157,6 @@ dependencies = [
]
[[package]]
-name = "miniz_oxide"
-version = "0.8.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
-dependencies = [
- "adler2",
-]
-
-[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -217,21 +166,6 @@ dependencies = [
]
[[package]]
-name = "object"
-version = "0.36.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
-dependencies = [
- "memchr",
-]
-
-[[package]]
-name = "pin-project-lite"
-version = "0.2.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
-
-[[package]]
name = "reencoder"
version = "0.1.0"
dependencies = [
@@ -241,32 +175,15 @@ dependencies = [
"i24",
"md-5",
"metaflac",
- "tokio",
]
[[package]]
-name = "rustc-demangle"
-version = "0.1.24"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
-
-[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
-name = "tokio"
-version = "1.45.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
-dependencies = [
- "backtrace",
- "pin-project-lite",
-]
-
-[[package]]
name = "typenum"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -277,67 +194,3 @@ name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
-
-[[package]]
-name = "windows-targets"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
-dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_gnullvm",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
-]
-
-[[package]]
-name = "windows_aarch64_gnullvm"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
-
-[[package]]
-name = "windows_aarch64_msvc"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
-
-[[package]]
-name = "windows_i686_gnu"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
-
-[[package]]
-name = "windows_i686_gnullvm"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
-
-[[package]]
-name = "windows_i686_msvc"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
-
-[[package]]
-name = "windows_x86_64_gnu"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
-
-[[package]]
-name = "windows_x86_64_gnullvm"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
-
-[[package]]
-name = "windows_x86_64_msvc"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
diff --git a/Cargo.toml b/Cargo.toml
index 380c178..06f9cba 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,4 +10,3 @@ flac-bound = { version = "0.5.0", features = ["libflac-noogg"], default-features
i24 = "2.1.0"
md-5 = "0.10.6"
metaflac = "0.2.8"
-tokio = "1.45.1"
diff --git a/src/flac.rs b/src/flac.rs
index 8653881..07004dc 100644
--- a/src/flac.rs
+++ b/src/flac.rs
@@ -4,7 +4,7 @@ use flac_bound::{FlacEncoder, WriteWrapper};
use i24::i24;
use md5::{Digest, Md5};
use metaflac::Tag;
-use std::fs::File;
+use std::fs::{File, read};
struct StreamConfig {
channels: u32,
@@ -48,10 +48,9 @@ fn process_samples_i16(
.samples()
.map(|sample| sample.unwrap())
.collect::<Vec<_>>()
- .chunks(4096)
+ .chunks(1024 * usize::try_from(config.channels)?)
{
- enc.process_interleaved(samples, 4096 / config.channels)
- .unwrap();
+ enc.process_interleaved(samples, 1024).unwrap();
let _ = samples
.iter()
.map(|sample| hasher.update((i16::try_from(*sample)).unwrap().to_le_bytes()))
@@ -70,10 +69,9 @@ fn process_samples_i24(
.samples()
.map(|sample| sample.unwrap())
.collect::<Vec<_>>()
- .chunks(4096)
+ .chunks(1024 * usize::try_from(config.channels)?)
{
- enc.process_interleaved(samples, 4096 / config.channels)
- .unwrap();
+ enc.process_interleaved(samples, 1024).unwrap();
let _ = samples
.iter()
.map(|sample| hasher.update((i24::try_from(*sample)).unwrap().to_le_bytes()))
@@ -92,10 +90,9 @@ fn process_samples_i32(
.samples()
.map(|sample| sample.unwrap())
.collect::<Vec<_>>()
- .chunks(4096)
+ .chunks(1024 * usize::try_from(config.channels)?)
{
- enc.process_interleaved(samples, 4096 / config.channels)
- .unwrap();
+ enc.process_interleaved(samples, 1024).unwrap();
let _ = samples
.iter()
.map(|sample| hasher.update(sample.to_le_bytes()))
@@ -133,7 +130,8 @@ pub fn encode_file(file: &std::path::Path) -> Result<()> {
match config.bits_per_sample {
Bps::_16 => process_samples_i16(&mut hasher, reader, &mut enc, &config)?,
Bps::_24 => process_samples_i24(&mut hasher, reader, &mut enc, &config)?,
- Bps::_32 => process_samples_i32(&mut hasher, reader, &mut enc, &config)?,
+ /* Bps::_32 => process_samples_i32(&mut hasher, reader, &mut enc, &config)?, */
+ Bps::_32 => unimplemented!(),
};
if let Err(enc) = enc.finish() {
@@ -147,11 +145,22 @@ pub fn encode_file(file: &std::path::Path) -> Result<()> {
for block in source_tags.blocks() {
todo!()
} */
- let mut tags = Tag::read_from_path(tempname)?;
- let mut streaminfo = tags.get_streaminfo().unwrap().clone();
+ let source_tags = Tag::read_from_path(file)?;
+ let mut out_tags = Tag::new();
+ let mut streaminfo = source_tags.get_streaminfo().unwrap().clone();
+
streaminfo.md5 = hasher.finalize()[..].to_vec();
- tags.set_streaminfo(streaminfo);
- tags.save()?;
+ out_tags.set_streaminfo(streaminfo);
+
+ for block in source_tags.get_blocks(metaflac::BlockType::SeekTable) {
+ out_tags.push_block(block.clone());
+ }
+
+ for block in source_tags.get_blocks(metaflac::BlockType::VorbisComment) {
+ out_tags.push_block(block.clone());
+ }
+
+ out_tags.write_to_path(tempname)?;
Ok(())
}
diff --git a/src/main.rs b/src/main.rs
index 89343f1..4c3ba1b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,7 +23,6 @@ mod tests {
.unwrap()
.md5
.clone();
- std::fs::remove_file(std::path::Path::new("16bit.flac.tmp")).unwrap();
assert_eq!(target_md5, source_md5);
}
#[test]
@@ -41,10 +40,10 @@ mod tests {
.unwrap()
.md5
.clone();
- std::fs::remove_file(std::path::Path::new("24bit.flac.tmp")).unwrap();
assert_eq!(target_md5, source_md5);
}
#[test]
+ #[should_panic]
fn bit32() {
flac::encode_file(std::path::Path::new("32bit.flac")).unwrap();
let target_md5 = Tag::read_from_path("32bit.flac.tmp")
@@ -59,7 +58,6 @@ mod tests {
.unwrap()
.md5
.clone();
- std::fs::remove_file(std::path::Path::new("32bit.flac.tmp")).unwrap();
assert_eq!(target_md5, source_md5);
}
}