sandreas / m4b-tool

m4b-tool is a command line utility to merge, split and chapterize audiobook files such as mp3, ogg, flac, m4a or m4b
MIT License
1.15k stars 77 forks source link

Merge does not produce expected output file structure #202

Closed 2600box closed 1 year ago

2600box commented 1 year ago

Hello,

Is there no longer an option to set a twig template for filename output?

I get this error "--filename-template" option does not exist.

Thanks

sandreas commented 1 year ago

Unfortunately there is no context, so I don't know which command you are using but I assume that you are still trying to merge something...

merge does not support a template, but if you specify an output directory, it will keep the original base structure of the source.

Maybe you can try:

m4b-tool merge --help
m4b-tool split --help
m4b-tool chapters --help

to find out more about how m4b-tool works.

2600box commented 1 year ago

Sorry, yes, still trying to merge.

My source files look like this: chapter_0.m4a chapter_1.m4a chapter_2.m4a chapter_3.m4a chapter_4.m4a.

So the output defaults to title only. Is there another way?

I would like to have artist -- title.m4b

sandreas commented 1 year ago

Create a directory artist - title/ and put your files in this directory... e.g.:

- J.K. Rowling - Harry Potter 1/
  - chapter_0.m4a
  - chapter_1.m4a
  - ...

Then use --batch-pattern to convert them. Please read Best Practises carefully.

2600box commented 1 year ago

Hmmm, I thought I was following best practices. As the files appear in en/genre/artist/name/

m4b-tool merge -v --no-conversion --jobs=2 --output-file="output/" --equate=name,album --batch-pattern="en/%g/%a/%n/" en

Following your suggestion here I tried a directory like en/genre/artist -- title/ and then this command: m4b-tool merge -v --no-conversion --jobs=2 --output-file="output/" --batch-pattern="en/%g/%a -- %n/" en ?

Though the metadata inside the file is correct with genre, artist and title so it is being read by this alternative batch-pattern

But the result is still title.m4b is there something I am missing?

sandreas commented 1 year ago

But the result is still title.m4b is there something I am missing?

The result should be:

output/genre/artist -- title.m4b

If you use --batch-pattern="en/%g/%a/%n/", the output should be:

output/genre/artist/title.m4b

Seems that this may also be an edge case that needs to be investigated.

2600box commented 1 year ago

Ok, to be clear here are all the details with verbose log and debug here: http://bashupload.com/pDHjp/debug.tgz

Notably this is from the log:

NOTICE          9ms 1 match for pattern en/%g/%a -- %n/
NOTICE         10ms ================================
NOTICE         10ms merge en/psychology/Paul Bloom -- The Sweet Spot/
NOTICE         10ms   =>  output/psychology/Paul Bloom -- The Sweet Spot/The Sweet Spot.m4b
NOTICE         10ms - name: The Sweet Spot
NOTICE         10ms - artist: Paul Bloom
NOTICE         10ms - genre: psychology

Current structure:

- en/
  - Genre/
    - Artist - Title/
      - chapter_0.m4a
      - chapter_1.m4a
      - ...

Command: m4b-tool merge -v --no-conversion --jobs=2 --output-file="output/" --batch-pattern="en/%g/%a -- %n/" en produces:

Result: output/genre/artist -- title/title.m4b

sandreas commented 1 year ago

Ok, to be clear here are all the details with verbose log and debug here: http://bashupload.com/pDHjp/debug.tgz

Link does not work

Hmmm, I thought I was following best practices. As the files appear in en/genre/artist/name/

So I tried to reproduce this with no luck (I assume that the -- you used was a mistake and it should be a single -:

m4b-tool merge -v --no-conversion --jobs=2 --output-file="output/" --equate=name,album --batch-pattern="en/%g/%a/%n/" en

Result file structure:

tree
.
├── en
│   └── Fantasy
│       └── Jennifer Estep
│           └── Spiders Bite
│               ├── 001.mp3
│               ├── 002.mp3
│               └── cover.jpg
└── output
    └── Fantasy
        └── Jennifer Estep
            └── Spiders Bite
                └── Spiders Bite.m4b
m4b-tool merge -v --no-conversion --jobs=2 --output-file="output/" --equate=name,album --batch-pattern="en/%g/%a - %n/" en

Result file structure:

.
├── en
│   └── Fantasy
│       └── Jennifer Estep - Spiders Bite
│           ├── 001.mp3
│           ├── 002.mp3
│           └── cover.jpg
└── output
    └── Fantasy
        └── Jennifer Estep - Spiders Bite
            └── Spiders Bite.m4b

So it works for me. Could you show me the file structure of your failing example?

2600box commented 1 year ago

-- was not a typo, but I tried with a single -

m4b-tool merge -vvv --debug --tag-debug-path=./debug/ --no-conversion --jobs=2 --output-file="output/" --batch-pattern="en/%g/%a - %n/" en --equate=name,album

Debug:

http://bashupload.com/z0zaO/debug.tgz mirror: https://we.tl/t-eCGrDSCPC5

|-- en
|   `-- psychology
|       `-- Paul\ Bloom\ -\ The\ Sweet\ Spot
|           |-- book.md
|           |-- book.yaml
|           |-- chapter_0.m4a
|           |-- chapter_1.m4a
|           |-- chapter_2.m4a
|           |-- chapter_3.m4a
|           |-- chapter_4.m4a
|           `-- cover.jpg
`-- output
    `-- psychology
        `-- Paul\ Bloom\ -\ The\ Sweet\ Spot
            `-- The\ Sweet\ Spot.m4b
sandreas commented 1 year ago

Mmh, I would say that output/psychology/Paul Bloom - The Sweet Spot/The Sweet Spot.m4b is the expected result... what would you expect?

2600box commented 1 year ago

I need the artist and title in the file name. Like this :

output/psychology/Paul Bloom - The Sweet Spot/Paul Bloom - The Sweet Spot.m4b

Is that possible?

sandreas commented 1 year ago

Is that possible?

Unfortunately, no, not at the moment. The output file naming is partly hardcoded here

It should be not too hard to implement an --filename-template, I'll treat this as feature request. Is that ok? Pretty likely this will be released in the next weeks.

I investigated further. The batch processing tool does not know the tags of the resulting files, therefore it may be difficult to use a --filename-template... You could only use the parts from the --batch-pattern, so if --batch-pattern does not contain the author, you could not build a folder with it. I take a look on the necessary changes for using the whole output tag for a template, but this may be hard to do.

You could use another tool to rename the file after the encoding has finished. A shell script would do, but if it does not work, you might use exiftool to recursively rename your files.

sandreas commented 1 year ago

After further investigation I found a way to implement this. Was kind of fun to do.

As soon as the next pre-release is out, you should now be able to use

--filename-template="{{outputPath}}{{artist}} - {{title}}"

in merge command.

Additionally with the next pre-release an issue in the --equate option is fixed.