rmcrackan / Libation

Libation: Liberate your Library
GNU General Public License v3.0
2.72k stars 149 forks source link

Add conditional logic to custom file naming #151

Closed shokinn closed 2 years ago

shokinn commented 2 years ago

Reference: #50

Hey @rmcrackan, I'm sorry to bother you again with this but I found 2 points which does not work out so well with new custom file and folder names.

  1. When I add a series to my filenames / folders it results in multiple blanks when the book is not part of a series
  2. It would be awesome if the series number would be also available with a leading 0 as it is available with the chapters.

1. Blanks in filnames / folders

grafik

Custom file naming:

How to format the folders in which the files will be saved:
<author>\<series> <series#> - <title short> [<id>]

How to format the saved pdf and audio files:
<author> - <series> <series#> - <title short> [<id>]

How to format the saved audio files when split by chapters:
<author> - <series> <series#> - <title short> [<id>] - <ch# 0> - <ch title>

Output for non series books:

E:\TMP\Libation\Books\Andreas Eschbach\  - Die Haarteppichknüpfer [B009R2XGK8]\Andreas Eschbach -   - Die Haarteppichknüpfer [B009R2XGK8].m4b

Output for books within a series:

E:\TMP\Libation\Books\Alexey Pehov\Chroniken der Seelenfänger 1 - Schwarzer Dolch [B075RG49M7]\Alexey Pehov - Chroniken der Seelenfänger 1 - Schwarzer Dolch [B075RG49M7].m4b

As you see for non series books it results in \ - <tiltle> [...] and \<author> - - <title> [...]. Is there any way to include a check if the book is part of a series or not? Something like:

<author> - <when series><series> <series#> - </when series><title short> [<id>]

Where everything between <when series> and </when series> would only be used when the book is part of a series.


2. Series number available with leading 0(s) / Userdefined amount of leading 0(s)

For example (the idea from before not yet applied):

How to format the folders in which the files will be saved:
<author>\<series> <series##> - <title short> [<id>]
Alexey Pehov\Chroniken der Seelenfänger 01 - Schwarzer Dolch [B075RG49M7]

How to format the saved pdf and audio files:
<author> - <series> <series##> - <title short> [<id>]
Alexey Pehov - Chroniken der Seelenfänger 01 - Schwarzer Dolch [B075RG49M7].m4b

How to format the saved audio files when split by chapters:
<author> - <series> <series##> - <title short> [<id>] - <ch###> - <ch title>
Alexey Pehov - Chroniken der Seelenfänger 01 - Schwarzer Dolch [B075RG49M7] - 001 - Chapter 1.m4b

Every # will be a placeholder for a number so that for the 1st book in a series it would be # = 1, ## = 01, ### = 001, ...


What do you think?

rmcrackan commented 2 years ago

tl;dr: 1 seems do-able, 2 doesn't

When I add a series to my filenames / folders it results in multiple blanks when the book is not part of a series

I thought about this. Without more and more templates I couldn't think of how to avoid it. I remove empty directories so it at least fixes this issue foo\<series>\bar => foo\\bar=> foo\bar

Your idea is clever. Checking to see if it's part of a series is trivial. The implementation of will not be trivial. The current implementation is mostly a simple whitelist find and replace.

It would be awesome if the series number would be also available with a leading 0 as it is available with the chapters.

I thought of this one too. From easiest to fix to hardest:

1) Series are different because they're often expanding. Today's 1 of 9 is tomorrow's 01 of 10. 2) Books don't carry in their metadata how many are in a series. That will require a new query to audible and brand new a cache store + retrieve so we aren't querying the same info again and again for each book in the series. 3) Position in a series is often WEIRD. These are all actual examples from my library:

For all of these oddities it's easy to print out the current value but not easy to parse into a regular number to determine leading zeros. I spent a long time going down this rabbit hole before deciding against it.

shokinn commented 2 years ago

1.

Sounds awesome :)

2.

WTF! Audible is sometimes soooooooo broken. But 1. was/is the important one for me 2. was more like a nice to have. So ¯\(ツ)

rmcrackan commented 2 years ago

Perfect, thank you for the review.

As per usual, now that the discussion part is satisfactory, I've added this into my queue and I'm closing this issue here. When it's complete, I'll update this again which will notify you. No ETA

Thanks again

rmcrackan commented 2 years ago

I'm experimenting with tracking enhancements and feature requests using github issues instead of a local file.

Enhancement: add conditional logic to custom file naming

Possible solutions: <if series></if series> or <when series></when series>

Example: <if series><series> <series#> - </if series>

Concerns: enabling user scripting is tricky, especially in terms of security or accidental cascades. Be careful. Use whitelisting.

rmcrackan commented 2 years ago

Added to v6.4.4

<if series->...<-if series>

I went with if series instead of when series for the incredibly technical reason that fewer characters means it fit in the UI with less twiddling :)

The arrow syntax actually is technical. There's a lot of validation code preventing slashes where you aren't allowed to define additional paths. Using html-style end tags would have meant a lot of code churn. By using filename-legal characters I was able to finish this feature much faster

shokinn commented 2 years ago

Hi @rmcrackan, works awesome 👍

Thanks!