Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 07-10-2025, 11:30 PM   #31
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
Quote:
Originally Posted by chaley View Post
That error is harmless, caused by the template dialog not having a real book to work with. It will work when it us run "for real" -- when sending to the device.

This version removes the error.
Code:
python:
def evaluate(book, context):
	import os
	from calibre.library import current_library_path

	fmt_metadata = book.get('format_metadata')
	if fmt_metadata:
		for v in fmt_metadata.values():
			# A calibre format name is roughly "author/title (id)/title - author.extension"
			# We want to return the last segment, stripping off the author and title 
			# directory names and the extension, leaving just the basename of the book file
			f = v['path']
			return f[f.rfind(os.sep)+1:f.rfind('.')] 
	else:
		return 'title - author'
This code is still not accepted by the template editor - please see the screenshot
Attached Thumbnails
Click image for larger version

Name:	template1error.png
Views:	29
Size:	42.9 KB
ID:	216844  
edojan is offline   Reply With Quote
Old 07-11-2025, 03:33 AM   #32
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by edojan View Post
This code is still not accepted by the template editor - please see the screenshot
It works fine for me, no errors. Furthermore, the code line number makes no sense.

What version of calibre are you running, and on what OS?

EDIT: There was a change in calibre 8.5.101 and later (e.g. 8.6) that might affect this.

Last edited by chaley; 07-11-2025 at 04:03 AM. Reason: Info about release
chaley is offline   Reply With Quote
Old 07-11-2025, 06:56 AM   #33
readx
Connoisseur
readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.
 
Posts: 94
Karma: 118402
Join Date: Jul 2009
Device: Cybook Gen3
Quote:
Originally Posted by edojan View Post
This was done earlier. Unfortunately, due to the file name differences the hashes are different even if when there is no change in the metadata

FileSystem LongPathsEnabled was/is set to 1 (true), but I don't know how to change the application's manifest.
I wish there was a setting "keep device file names the same as in Calibre library" This would be ideal

Sorry, I don't get what you're doing with the hash.
By design, hashes will stay the same if the file name changes.
A file's hash is the hash of its contents. Metadata, such as file names, timestamps, and permissions, has no influence on the hash. see stackoverflow or stackexchange
readx is offline   Reply With Quote
Old 07-11-2025, 07:45 AM   #34
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,725
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Calibre has the option to embed current metadata into the format files that it exports… which includes title. So, if I export a format file now (i.e. an EPUB) and then change the title and re-export the EPUB the hash will change because the EPUB's content changed.

BR
BetterRed is offline   Reply With Quote
Old 07-11-2025, 09:05 AM   #35
readx
Connoisseur
readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.readx 's ceiling is 100% spider-free.
 
Posts: 94
Karma: 118402
Join Date: Jul 2009
Device: Cybook Gen3
Quote:
Originally Posted by BetterRed View Post
Calibre has the option to embed current metadata into the format files that it exports… which includes title. So, if I export a format file now (i.e. an EPUB) and then change the title and re-export the EPUB the hash will change because the EPUB's content changed.

BR

I know, thanks.
Embedding involves changing the content of the EPUB file, which has nothing to do with the file name, contrary to what the OP seems to think. Even if the file name (not the embedded title) is changed to '123.epub', it would still have the same hash.
Therefore, 'Calibre truncates long names on Win10 with long paths enabled' is not related to the hash problem.
readx is offline   Reply With Quote
Old 07-11-2025, 02:31 PM   #36
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
Quote:
Originally Posted by readx View Post
Sorry, I don't get what you're doing with the hash.
By design, hashes will stay the same if the file name changes.
A file's hash is the hash of its contents. Metadata, such as file names, timestamps, and permissions, has no influence on the hash. see stackoverflow or stackexchange
I am using Koreader to read epubs on all my devices (including windows - under WSL). Koreader produces its own metadata file to keep the highlights, annotations, page numbers, etc. which is separate from the book's epub. The Koreader-generated metadata files for each book are then synchronized using another app. The sync app (Kohighlights) checks the respective epub hash numbers to determine if it is dealing with the same book or not. Apparently, when epub in my Calibre library is transferred to the devices (such as Kobo reader), it no longer has the same hash. Calibre setting prevents storing metadata inside the epub so this is not an issue. i.e. the internal metadata inside the epub files are not being altered. I tried a manual copy of epubs from Calibre library directory directly to a folder on my sage reader. In such a case the hash remains the same.
edojan is offline   Reply With Quote
Old 07-11-2025, 02:45 PM   #37
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
Quote:
Originally Posted by chaley View Post
It works fine for me, no errors. Furthermore, the code line number makes no sense.

What version of calibre are you running, and on what OS?

EDIT: There was a change in calibre 8.5.101 and later (e.g. 8.6) that might affect this.
I was on version 8.5. Upon updating to 8.6 the error is gone. However, the intended results are still not achieved. The file name remains truncated.
Code:
Istsielieniie dukhovnykh boliez - Zhan-Klod Larshie.epub
Moreover, before this change the program would create a directory named after author, and then a directory with the book name.
Now, the file (truncated same as before) is placed into the root directory of the device.
edojan is offline   Reply With Quote
Old 07-11-2025, 04:25 PM   #38
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by edojan View Post
I was on version 8.5. Upon updating to 8.6 the error is gone. However, the intended results are still not achieved. The file name remains truncated.
Code:
Istsielieniie dukhovnykh boliez - Zhan-Klod Larshie.epub
Moreover, before this change the program would create a directory named after author, and then a directory with the book name.
Now, the file (truncated same as before) is placed into the root directory of the device.
I was under the impression that you wanted the send to device template to produce the identical file name for a book format as it has in the calibre library, which the template I suppled does. Apparently I was wrong. I can't help further.
chaley is offline   Reply With Quote
Old 07-11-2025, 05:13 PM   #39
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
Quote:
Originally Posted by chaley View Post
I was under the impression that you wanted the send to device template to produce the identical file name for a book format as it has in the calibre library, which the template I suppled does. Apparently I was wrong. I can't help further.
I am sorry - I spaced out for a min You are correct. Of course, the intent was to produce the identical file name on the device equal to one in the Calibre library - which your code did. Is there a way to modify the code to place the file in the {Author} folder? This would really solve the issue for me .
edojan is offline   Reply With Quote
Old 07-11-2025, 06:12 PM   #40
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
Also, the above code produces double extension such as
Code:
Istsielieniie dukhovnykh boliez - Zhan-Klod Larshie.epub.epub
edojan is offline   Reply With Quote
Old 07-11-2025, 06:18 PM   #41
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
@kovidgoyal your help would be greatly appreciated. I have been hitting the wall for a very long time - but the issue remains. I wonder if it would be possible to implement a feature - e.g. via tweaks to keep the destination file names exactly the same as the source (i.e. Calibre)?
edojan is offline   Reply With Quote
Old 07-11-2025, 09:22 PM   #42
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,355
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You were given a template that does it by chaley, not sure what more you want. It should be a trivial change in the template to both add an author folder and remove the file extension, or whatever else floats your boat. Good luck.
kovidgoyal is offline   Reply With Quote
Old 07-11-2025, 10:08 PM   #43
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
Posts: 13,523
Karma: 78910202
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
I csn't help but think that you'd get more assistance from the koReader community; presumably others in that community also want to sync across multiple devices.
PeterT is offline   Reply With Quote
Old 07-12-2025, 06:39 AM   #44
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by edojan View Post
@kovidgoyal your help would be greatly appreciated. I have been hitting the wall for a very long time - but the issue remains. I wonder if it would be possible to implement a feature - e.g. via tweaks to keep the destination file names exactly the same as the source (i.e. Calibre)?
Quote:
Originally Posted by kovidgoyal View Post
You were given a template that does it by chaley, not sure what more you want. It should be a trivial change in the template to both add an author folder and remove the file extension, or whatever else floats your boat. Good luck.
In addition, it would most likely be me that would implement such a feature, which I'm not going to do. I'm thinking of making a template function to return the path segments rather than something so specific, which would permit the user to construct the path however the person wishes.

Quote:
Originally Posted by edojan View Post
Also, the above code produces double extension such as
Code:
Istsielieniie dukhovnykh boliez - Zhan-Klod Larshie.epub.epub
It doesn't for me. I suspect that something got changed when you entered the template.
Quote:
Originally Posted by edojan View Post
I am sorry - I spaced out for a min You are correct. Of course, the intent was to produce the identical file name on the device equal to one in the Calibre library - which your code did. Is there a way to modify the code to place the file in the {Author} folder? This would really solve the issue for me .
This template adds the author used by calibre in the library, and is slightly more robust across operating systems.
Code:
python:
def evaluate(book, context):
	import os
	from calibre.library import current_library_path

	fmt_metadata = book.get('format_metadata')
	if fmt_metadata:
		for v in fmt_metadata.values():
			# A calibre format name is three section, author, title, format.extension
			# We want to return author/format without the extension
			p = v['path']
			r,f = os.path.split(p)
			format = os.path.splitext(f)[0]
			r,title = os.path.split(r)
			r,author  = os.path.split(r)
			return '/'.join((author, format))
	else:
		return 'title - author'
Using the above template, the book
Click image for larger version

Name:	Clipboard01.jpg
Views:	13
Size:	8.4 KB
ID:	216862
saved in the library at
Code:
"C:\CBH_Data\calibre.git\Library.test_small\A B\Unknown2 (foo) (1313)\Unknown2 (foo) - A B.epub"
generates the path
Code:
A B/Unknown2 (foo) - A B
On my Kobo Libra 2 the book is stored with no doubled extension at
Click image for larger version

Name:	Clipboard02.jpg
Views:	15
Size:	14.4 KB
ID:	216863
chaley is offline   Reply With Quote
Old 07-12-2025, 02:00 PM   #45
edojan
Connoisseur
edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.edojan can tame squirrels without the assistance of a chair or a whip.
 
Posts: 68
Karma: 11226
Join Date: Mar 2022
Device: Kobo Libra 2, Aura H2O
@chaley Thank you! I kept struggling with the double extension issue. While adding the author directory to the destination was not difficult, for whatever reason I had to try several things to address the double extension thing. In the end the only solution which worked was to remove the extension from the filename before returning it, letting Calibre add it back during the transfer process. Here is the code which finally worked for me:

Code:
Python:
def evaluate(book, context):
    import os
    fmt_metadata = book.get('format_metadata')
    # Get main author safely, fallback 'Unknown Author', and sanitize for filesystem
    author = book.get('authors', ['Unknown Author'])[0].replace('/', '_').replace('\\', '_')
    if fmt_metadata:
        for v in fmt_metadata.values():
            # Extract only the filename with extension
            f = v['path']
            filename = os.path.basename(f)
            
            # **FIX**: Remove the extension since Calibre will add it automatically
            filename_without_ext = os.path.splitext(filename)[0]
            
            # Compose path as: {Author}/{filename (WITHOUT extension)}
            return '/'.join([author, filename_without_ext])
    else:
        # For fallback, also remove extension since Calibre will add it
        return '/'.join([author, 'title - author'])

Last edited by edojan; 07-12-2025 at 02:13 PM.
edojan is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Calibre's folder structure and long names in Windows crixtiano Calibre 1 07-28-2017 02:05 PM
Calibre taking a long, long time to update metadata on sony prs650 hydin Calibre 5 06-05-2012 12:21 AM
Is there anything in Calibre that can fix long file names automatically? dmunson Calibre 4 02-05-2012 06:12 PM
File Names to long? JTAL604622 Calibre 5 08-31-2011 03:21 AM
Files with long names? cmhsieh54 iRex 0 08-05-2009 12:43 PM


All times are GMT -4. The time now is 12:55 PM.


MobileRead.com is a privately owned, operated and funded community.