01-05-2022, 04:34 PM | #1 |
Bookmaker
Posts: 416
Karma: 2143650
Join Date: Sep 2010
Device: Cybook Opus
|
Transforming Filenames With Special Characters
Is there a way to use templates or plugboards to set Calibre up so that when I send a file to a device that has an illegal character in the metadata (specifically, a colon), it transforms that character into something other than _?
I'm trying to use Calibre to manage my collection of RPG PDFs, and RPGs love having titles with colons in them, like Vampire: the Masquerade and its ilk. I'd like to be able to set things up so that the transfer sends these files to device with the filename of, more or less "Vampire — the Masquerade" instead of "Vampire_ the Masquerade". That is, it turns a colon into space-emdash-space. Can Calibre do this automatically? I've looked at the documents but I'm not too great at regular expressions. |
01-05-2022, 05:25 PM | #2 |
Well trained by Cats
Posts: 29,801
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Colon is illegal in windows, there is a FAQ on WHY Calibre prefers simple ASCII names (it is only allowd as part of a device (A:, Com1:, Aux: LPT1: )
Other symbols have meaning to various OS. Calibre works across many OS, so K.I.S.S. is the rule. |
Advert | |
|
01-05-2022, 09:04 PM | #3 |
null operator (he/him)
Posts: 20,568
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
I think the OP knows why the '_' (underscore) character is substituted for disallowed characters (e.g. <>:"/\|?*) in file names.
What they want to do is to use another substitute character in Save to Disk, Send to Device templates and plugboards etc. Or even better a substitute string e.g. ' — '. Personally, I would get rid of the ':' in the Title when I added the book, either via use of a subtitle column or by changing the ':' to ' — '. But that wouldn't suit everyone. BR Last edited by BetterRed; 01-05-2022 at 09:29 PM. |
01-05-2022, 09:29 PM | #4 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
If you are fiddling with the metadata that will be inside the book, you can use the metadata plugboard to make the changes you want. But, these won't affect the file names.
For the file names, the save template is used. There is a default save template on the "Sending books to devices" page of the preferences. That will be used for any device you have not done any configuration to. As this is probably a devices specific thing, configure this in the driver used by your device. The simplest way to do that, is to connect the device, wait for the device jobs to run and then right-click the device button and select the option to configure the device. That will make sure you get the right driver. The default save template is: Code:
{author_sort}/{title} - {authors} Code:
{author_sort}/{title: re(: , - )} - {authors} Code:
program: strcat($author_sort, "/", re($title, ":" , " -"), " - ", $authors) In both cases, the "re" is a regex replacement, so the parameters are regex to match and the string to replace all the matches with. After this has been executed, calibre will still sanitise result. Which will make sure whatever is produced is valid on the filesystem and the device in question. |
01-05-2022, 09:42 PM | #5 | |
Bookmaker
Posts: 416
Karma: 2143650
Join Date: Sep 2010
Device: Cybook Opus
|
Quote:
What's the correct way to do the second format if what I was currently using was: Code:
{author_sort}/{#line}/{#subline}/{#edition} Code:
program: strcat($author_sort, "/", $#line, "/" $#subline, "/", $#edition, "/", re($title, ":" , " -"), " - ", $authors) |
|
Advert | |
|
01-05-2022, 10:13 PM | #6 | |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
But, I feel like there should be a better way to do that, but, I can't see a "format_as_path" or the equivalent of "os.join()". |
|
01-05-2022, 11:09 PM | #7 |
Bookmaker
Posts: 416
Karma: 2143650
Join Date: Sep 2010
Device: Cybook Opus
|
Thanks a bunch!
|
01-21-2022, 12:43 PM | #8 |
Bookmaker
Posts: 416
Karma: 2143650
Join Date: Sep 2010
Device: Cybook Opus
|
Hm, after testing this, it looks like doing this with an endash actually results in the filename being transformed as requested, but it outputs a hyphen instead. If I use an emdash, it outputs two hyphens.
Odd! I know the filesystems I use are okay with endash and emdash, but maybe some of them aren't and so Calibre won't use them? Or could it be a bug? |
01-21-2022, 12:55 PM | #9 | |
Bibliophagist
Posts: 35,401
Karma: 145435140
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Forma Can't read .cbz files with special characters in the .jpg filenames | JawadLeLogeur | Kobo Reader | 3 | 06-24-2021 09:53 AM |
Enhancement request: special characters, invisible characters and html entities. | PenguinCEO | Editor | 15 | 04-08-2020 05:26 PM |
Change characters in metadata title and filenames on disk | NickKnaque | Calibre | 16 | 10-24-2019 10:07 AM |
Special CHaracters | Rellwood | Calibre | 10 | 05-01-2019 10:43 PM |
Special Characters | abbotrichard | ePub | 4 | 07-01-2011 06:03 PM |