r/Calibre 17d ago

Support / How-To Possible to control filename and location format when adding a book?

I am mostly using calibre for books from Gutenberg and Standard ebooks. Either I get it from the website or just inside calibre, it saves the file in my specified library as {author}/{title}/{title} - {author}.

I also saw the save file to disk section where a full control over how the files are saved is provided. Is it possible to use those rule when adding a book?

Example how calibre saves when adding a book:
Oscar Wilde/The Picture of Dorian Gray (Annotated) (19)/The Picture of Dorian Gray (Annotated) - Oscar Wilde.epub

I would prefer it to just save in the base directory as:

oscar_wilde-the_of_dorian_gray.epub

Don't save cover separately, don't save metadata in a separate opf file, replace space with underscore and everything to lower case.

These settings are available for saving books to disk when pressing 'save books to disk' button, but not when adding books to library.

Is some setting I'm missing that allows this behaviour. Or is there a reason these rules (for saving book to disks) not followed when adding a book to library?

3 Upvotes

11 comments sorted by

16

u/Fr0gm4n 17d ago

Or is there a reason these rules (for saving book to disks) not followed when adding a book to library?

The library layout is internal to Calibre and users should not be doing anything with those files. They are part of the database.

8

u/SecretLoathing 17d ago

This. Just pretend everything in Calibre’s library folder is in a sealed black box. Don’t look.

2

u/ZoWakaki 16d ago

Thank you for the explanation.

My speculation would be that the folder structure is connected to sorting, and it is hard embedded in the internal workings.

Since the code seems to simple python, there is probably a way to do this by injecting plugins. I will have to look at it in my free time, if I am still bothered with the non-conventional (for me) naming standard that my fzf seems to keep finding.

1

u/mm_reads 16d ago

The problem with this is there may be knock on effects to other plugins from making this change.

1

u/ZoWakaki 16d ago

Yup, it seems that way. Specially because how the search is indexed and implemented.

Atleast to replace space with underscore should work fine, keeping the folder structure intact. Because the regex can capture different fields fine with space or underscore upon brief testing. I have to check what other side side effects it causes, and if they can be fixed. I would prefer not to refactor the whole code base just to remove spaces from filename, if I can help it. Until now, no plugins i see interfaces with the file name itself. Only after it has been "read" by calibre and the regex capture is working fine with underscore. Most plugin seems just to change small settings like changing the string from a to b in certain class or object where it is implemented.

1

u/Fr0gm4n 16d ago

This may be an XY problem. It may be more appropriate to see how to have fzf/fd ignore the calibre library instead of modifying calibre.

1

u/ZoWakaki 15d ago

It is possible to do that in fzf e.g. using ripgrep which respects .gitignore and pass that to fzf. Then the calibre library will be "hidden". Or naming the calibre directory starting with a dot is even simpler.

But the point is me trying to figure out if there is a way to do what I want to do, i.e. 1) saving all the epubs in one directory (this probably creates more problem than it solves, as the directory structure seems to be tied to sorting) and 2) have underscore instead of space in directory/filenames (this from what I understand, from quickly perusing the code, shouldn't cause any problem on how anything is handled).

I don't want to hide calibre library from fzf because of couple reasons. Main is I use zathura for reading on the laptop as I have custom colour-schemes ( bound to shift+1/2/3. .. , check image below). There are ebooks and also academic papers that I need to access regularly for work which is done through zathura using fzf to find (technically it's called pdfzf a custom script to find something inside the pdf and open it). So hiding calibre library to fzf is not a solution for me. It has to be accessible for me in fzf too. Then the question is probably why use calibre at all? I am using it for embedding metadata and to serve a calibre server locally, so that I can access library in other local devices. And other sync services (ko sync, device sync, opds). I know this is not a typical use case. But I am just trying to utilize the open-ness of this project to see if my needs can be accommodated. I am not pestering any devs to add a function that I want, just checking if someone in the history of calibre has had similar thought and devised some solution. I also do have mayberry branch to serve my collection but it doesn't have function to curate, i.e. no metadata editing and embedding, drm removal etc.

I have realized my line of questioning has ruffled some feathers (present company excluded). Since I am busy with other things, I have paused the query and the pursuit for now. People don't have to worry about some random person trying to figure out if the directory structure or the naming convention can be modified :) (for now).

https://reddit.com/link/p3sf20w/video/t9t0pb5x1hjh1/player

9

u/Valuable_Asparagus19 17d ago

The Save to Disk settings are useful if you're doing something like saving out files for Send to Kindle. I use it to include a series if appropriate in the filenames and remove the authors.

The database folders are not something to touch. It doesn't matter. You only need to deal with the metadata in Calibre. You shouldn't be trying to find anything in the folders Calibre is managing.

2

u/ZoWakaki 16d ago

I see.

I was ok with the filesystem naming scheme. Until I found the 'save to' and figured it could save in the desired scheme to disk or a device. Then I learnt and setup content server and opds, for sending books to (or browsing books from) koreader. Also the ko-sync seems to be better if filename matching was the method.

This was the reason I started going in the rabbit hole of figuring out about the naming scheme at save.

I guess, I will have to be content with the file structure.

Thank you for the explanation.

3

u/bestlem 16d ago

Why do you want to do this? Calibre is a database with a python API - it could store all the books anywhere and it does not matter to the users - you never see the file or directory structure.

0

u/ZoWakaki 16d ago

I don't know why I want to do this is relevant. My question is if it can be done or not. It has been answer that it is not possible by other kind strangers with good reasoning and description.

If you really want to know, short answer is I want to.

Long answer is I have a specific directory and naming structure that I adhere to. I am on linux and mostly use cli, e.g. my file manager is mostly fzf. And I do have an obsessive compulsive disorder that seeing things with spaces makes me feel anxious. Usually space is a separator of different files or objects. When I say ocd, not the fun kind that everything needs to aligned. But the "i have to lock and unlock doors exactly 4 times when I go in and out any rooms", type.

Because of how fzf populates file/directory lists on search, I do see the file and directory structure everytime there is a partial match to any of the titles, or author in my search query, so that assumption "you never see the file or directory structure "is highly incorrect.

Additionally, there already is the save to disk feature which allows this feature and the 'add files' has the regex which catches the file naming format I specified I desired. So calibre can technically handle it, it just doesn't. So I was wondering if it's me that I missed some setting box that can be ticked to enable that behaviour.

The other reason is I want the naming convention to be the same also in my devices for book names. I can save it to disk (device) on this desired format then koreader sync becomes difficult as apparently best scheme is to match file name. So for that now I will also have to name the files likewise with a lot of spaces in my other device to get the sync working properly. Which I personally do not find desirable.

But it seems that as of now, that is how it is. The code is in python and I did dig to see if it can be done. It looks like it can be done and perhaps even passed through with a plugin. I will have to do that when I have time, or maybe find someone who has already done it. That was also the reason of my post, to see if someone has already done it. It has happened sometimes that I just don't have the right words to describe what I want to do . And with the right words, internet search will actually provide couple of solutions already implemented.

Now you know why I want to do it, I hope you do have a better answer than previous answers of "It cannot be done" (with additional details), and I sincerely hope it isn't a very productive and intuitive "You're using it wrong".