Compare commits

..

3 commits

Author SHA1 Message Date
1dac8cc13a feat: group authors by first character
All checks were successful
Rust / build (map[name:stable]) (push) Successful in 1m48s
Rust / build (map[name:nightly]) (push) Successful in 3m46s
Release Please / Release-plz (push) Successful in 32s
2024-10-11 22:40:33 +01:00
84929351d9 docs: add usage instructions to readme
Some checks failed
Rust / build (map[name:nightly]) (push) Successful in 2m13s
Rust / build (map[name:stable]) (push) Successful in 3m42s
Release Please / Release-plz (push) Failing after 17s
2024-10-11 22:40:33 +01:00
ba0b72b4be chore: fix name of project refile-mp4 to refile-m4b
Some checks failed
Rust / build (map[name:nightly]) (push) Successful in 2m3s
Rust / build (map[name:stable]) (push) Successful in 3m48s
Release Please / Release-plz (push) Failing after 53s
2024-10-11 22:40:33 +01:00
5 changed files with 45 additions and 31 deletions

48
Cargo.lock generated
View file

@ -65,18 +65,6 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "auto-file-mp4"
version = "0.2.0"
dependencies = [
"anyhow",
"clap",
"pretty_assertions",
"regex",
"rstest",
"taglib",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -315,22 +303,34 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.66" version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.33" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "refile-m4b"
version = "0.3.0"
dependencies = [
"anyhow",
"clap",
"pretty_assertions",
"regex",
"rstest",
"taglib",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.6" version = "1.10.6"
@ -368,9 +368,9 @@ checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
[[package]] [[package]]
name = "rstest" name = "rstest"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b423f0e62bdd61734b67cd21ff50871dfaeb9cc74f869dcd6af974fbcb19936" checksum = "0a2c585be59b6b5dd66a9d2084aa1d8bd52fbdb806eafdeffb52791147862035"
dependencies = [ dependencies = [
"futures", "futures",
"futures-timer", "futures-timer",
@ -380,9 +380,9 @@ dependencies = [
[[package]] [[package]]
name = "rstest_macros" name = "rstest_macros"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5e1711e7d14f74b12a58411c542185ef7fb7f2e7f8ee6e2940a883628522b42" checksum = "825ea780781b15345a146be27eaefb05085e337e869bff01b4306a4fd4a9ad5a"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"glob", "glob",
@ -428,9 +428,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.29" version = "2.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -475,9 +475,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.11" version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]] [[package]]
name = "utf8parse" name = "utf8parse"

View file

@ -1,5 +1,5 @@
[package] [package]
name = "refile-mp4" name = "refile-m4b"
version = "0.3.0" version = "0.3.0"
edition = "2021" edition = "2021"
description = "Refile a directory of m4b files by artist, album (where specified) and title. Used to refile m4b versions of converted aax files for use by Smart Audiobook Player." description = "Refile a directory of m4b files by artist, album (where specified) and title. Used to refile m4b versions of converted aax files for use by Smart Audiobook Player."

View file

@ -1,3 +1,14 @@
# Refile M4B
## Usage
```bash
refile-m4b DIR
```
This will refile all the `*.m4b` files in `DIR` and it's subdirectories by author, series (if given) and title.
The information in each files metadata is used.
## dependencies ## dependencies
### debian ### debian
@ -5,3 +16,5 @@
```bash ```bash
sudo apt install libtag1-dev libtagc0-dev sudo apt install libtag1-dev libtagc0-dev
``` ```
> Due to a typo, this was previously known as refile-mp4.

View file

@ -78,12 +78,13 @@ fn rename_files(directory: &str, base: &str, args: &Arguments) -> Result<i32> {
let (Some(title), Some(artist)) = (tag.title(), tag.artist()) else { let (Some(title), Some(artist)) = (tag.title(), tag.artist()) else {
continue; continue;
}; };
let (bucket, _) = artist.split_at(1);
let album = parse_album(&title); let album = parse_album(&title);
count += 1; count += 1;
let new_name = if album.is_empty() { let new_name = if album.is_empty() {
format!("{artist}/{title}/{title}.m4b") format!("{bucket}/{artist}/{title}/{title}.m4b")
} else { } else {
build_series_name(&artist, &album, &title) build_series_name(bucket, &artist, &album, &title)
}; };
println!("=============================="); println!("==============================");
println!("- artist: {artist}"); println!("- artist: {artist}");
@ -107,10 +108,10 @@ fn rename_files(directory: &str, base: &str, args: &Arguments) -> Result<i32> {
Ok(count) Ok(count)
} }
fn build_series_name(artist: &str, album: &str, title: &str) -> String { fn build_series_name(bucket: &str, artist: &str, album: &str, title: &str) -> String {
let index = parse_index(title); let index = parse_index(title);
let title = parse_title(title); let title = parse_title(title);
format!("{artist}/{album}/{index}. {title}/{index}. {title}.m4b") format!("{bucket}/{artist}/{album}/{index}. {title}/{index}. {title}.m4b")
} }
fn parse_index(title: &str) -> String { fn parse_index(title: &str) -> String {

View file

@ -11,8 +11,8 @@ use pretty_assertions::assert_eq;
"3. A Conjuring of Light" "3. A Conjuring of Light"
)] )]
fn parse_series_details(#[case] album: &str, #[case] title: &str, #[case] expected: &str) { fn parse_series_details(#[case] album: &str, #[case] title: &str, #[case] expected: &str) {
let expected_result = format!("Bob/{album}/{expected}/{expected}.m4b"); let expected_result = format!("B/Bob/{album}/{expected}/{expected}.m4b");
let result = build_series_name("Bob", album, title); let result = build_series_name("B", "Bob", album, title);
assert_eq!(result, expected_result); assert_eq!(result, expected_result);
} }