|
|
#46 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 11226
Join Date: Mar 2022
Device: Kobo Sage, Libra 2, Aura H2O
|
[QUOTE=chaley;4524192]
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'
|
|
|
|
|
|
#47 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73
Karma: 11226
Join Date: Mar 2022
Device: Kobo Sage, Libra 2, Aura H2O
|
|
|
|
|
| Advert | |
|
|
|
|
#48 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,529
Karma: 8075744
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
For future reference, the next calibre release (8.7 or a preview) will contain a template function that can do what the python template does.
formats_path_segments(with_author, with_title, with_format, with_ext, sep) return parts of the path to a book format in the calibre library separated by ``sep``. The parameter ``sep`` should usually be a slash (``'/'``). One use is to be sure that paths generated in Save to disk and Send to device templates are shortened consistently. Another is to be sure the paths on the device match the paths in the calibre library. See the manual for full documentation. |
|
|
|
![]() |
|
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 03:05 PM |
| Calibre taking a long, long time to update metadata on sony prs650 | hydin | Calibre | 5 | 06-05-2012 01:21 AM |
| Is there anything in Calibre that can fix long file names automatically? | dmunson | Calibre | 4 | 02-05-2012 07:12 PM |
| File Names to long? | JTAL604622 | Calibre | 5 | 08-31-2011 04:21 AM |
| Files with long names? | cmhsieh54 | iRex | 0 | 08-05-2009 01:43 PM |