Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-14-2024, 12:06 PM   #1
groob
Enthusiast
groob began at the beginning.
 
Posts: 37
Karma: 10
Join Date: Oct 2020
Device: Kindle Paperwhite (1)
How to get book paths from command linee file

Hello,
I'm trying to analyze my library space usage, I've identified some books take a very large amount of space on my disk.
I want to analyze this further and automate some tasks.

I went on a first selection of my books and

- Create catalog to export / CSV/XML Options

But in there there is no option to export each book file path.

I've looked into calibredb command and also there could find a way to obtain this information.

Have I missed something? I don't need to export the books, I just need to find the folder paths containing those books as I need to further analyze the disk usage.
groob is offline   Reply With Quote
Old 02-14-2024, 12:15 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Did you grab {id} in your CSV?

Calibre has a pretty consistent path name
Library_folder\{author}\{title} (id)
eg
Code:
xxx MainLib\Martha Carr\Goth Drow Unleashed Boxed Set Two_ (21560)
theducks is online now   Reply With Quote
Advert
Old 02-14-2024, 12:19 PM   #3
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
BTW You can show / sort on the {size} column in the GUI.
Illustrated PDF's are my big hogs, followed by lots of embedded fonts in EPUB
theducks is online now   Reply With Quote
Old 02-14-2024, 02:52 PM   #4
groob
Enthusiast
groob began at the beginning.
 
Posts: 37
Karma: 10
Join Date: Oct 2020
Device: Kindle Paperwhite (1)
Quote:
Originally Posted by theducks View Post
BTW You can show / sort on the {size} column in the GUI.
Illustrated PDF's are my big hogs, followed by lots of embedded fonts in EPUB
Thanks! I didn't notice the Size column!
Do you if this is just for the main version of the book? I might have several formats for the same book: audiobook as a zip file, pdf, epub and so on.

I've made a quick test, it's not completely reliable, it's directional (I mean I can see the books with bigger file sizes first).
Example, the GUI tells me a book is 522MB, then by opening the folder the total size of all formats is 558MB. Even the single biggest file (547MB) is already bigger than what shown on the GUI. 🤷*♂️
groob is offline   Reply With Quote
Old 02-14-2024, 04:11 PM   #5
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,464
Karma: 145525534
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
If you have, for example, a PDF, azw3, ePub and txt file, the size shown is the largest file.

If you have a 250MB file and and 247MB file, the file size will be shown as 250MB.

For the file size, when I look in calibre, there is a file shown as 367MB, when I open the folder the largest file shows as 375,772KB. Dividing 375,772 by 1024 gives me 366.96MB so round up to 367MB while Windows file properties will round down to 366MB.

In your example, the 547 is likely the first three characters of the file size in bytes. 547,000,000 bytes gives me 521.65MB (divided twice by 1024) while 547,999,999 gives me 522.61MB.

Last edited by DNSB; 02-14-2024 at 04:20 PM.
DNSB is offline   Reply With Quote
Advert
Old 02-14-2024, 05:15 PM   #6
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,091
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
This can be done by combination of Action Chains plugin and calibre template language from within the GUI. Attached below is a chain that calculates total size for selected books in human readable format. You can import the attached chain by: Action Chains > Add/modify chains > right click on the chains dialog > import > browse to the zip file.

Note: Also see what DNSB said in the post above about the difference between MB and MiB.
Attached Files
File Type: zip diskspace_selected_books.zip (594 Bytes, 35 views)
capink is offline   Reply With Quote
Old 02-14-2024, 05:26 PM   #7
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
This calibre python script might help. It produces a tab-separated CSV file for each book id provided on the command line. The CSV file contains 4 columns:
  • book id
  • extension
  • size in bytes
  • full path to file

To use it, save this script somewhere convenient:
Spoiler:
Code:
import json, os
from calibre.db.legacy import LibraryDatabase

'''
argument 1: path to the library

argument 2: list of book ids, e.g., 208,209. Quote the argument if there
            are spaces between the ids. calibredb search can be used to
            produce a list of ids. For example,
            calibredb search "size:>100000"
            finds all books with size > 100,000, printing the list of ids

output: a tab-separated csv list written to standard output
'''

# open the library database
db = LibraryDatabase(sys.argv[1]).new_api

# convert the book ids to a list of integers
book_ids = [int(bid.strip()) for bid in sys.argv[2].split(',')]

# get the library path from calibre. This removes symlinks and the like
library_path = db.backend.library_path

# print the header for the CSV output
print('\t'.join(('book_id', 'extension','size', 'path')))

# loop over the books generating the output for each format
for book_id in book_ids:
    # get the list of formats for the book
    formats = db.formats(book_id)

    # loop over the formats, generating the csv line
    for ext in formats:
        # get the metadata for the format: the extension, size, path, and modtime
        fmt_data = db.format_metadata(book_id, ext)
        # write the csv line for the format
        print('\t'.join((str(book_id), ext, str(fmt_data['size']), fmt_data['path'])))


Execute the script with
Code:
calibre-debug -e script_file_path library_path id1,id2,id3 > output.csv
Example using one of my test libraries:
  1. I saved the script as formats_sizes.py
  2. I used calibredb to get a list of ids, in this case books with 163 in the title
    Code:
    calibredb search "title:163"
    that produced the output
    Code:
    1337,1343,1361,1434
    You might want to use something like
    Code:
    calibredb search "size:>100000"
  3. I ran the script using
    Code:
    calibre-debug -e formats_sizes.py C:\CBH_Data\calibre.git\Library.test_small 1337,1343,1361,1434 > aaaaa.csv
The output is
Spoiler:
Code:
book_id	extension	size	path
1337	EPUB	790778	C:\CBH_Data\calibre.git\Library.test_small\Eric Flintt\16332 (1337)\16332 - Eric Flintt.epub
1337	ORIGINAL_EPUB	786992	C:\CBH_Data\calibre.git\Library.test_small\Eric Flintt\16332 (1337)\16332 - Eric Flintt.original_epub
1343	EPUB	736765	C:\CBH_Data\calibre.git\Library.test_small\Eric Flint\1632 (1343)\1632 - Eric Flint.epub
1343	MOBI	1029315	C:\CBH_Data\calibre.git\Library.test_small\Eric Flint\1632 (1343)\1632 - Eric Flint.mobi
1343	PRC	1093048	C:\CBH_Data\calibre.git\Library.test_small\Eric Flint\1632 (1343)\1632 - Eric Flint.prc
1361	EPUB	888796	C:\CBH_Data\calibre.git\Library.test_small\Weber, David\1633 (1361)\1633 - Weber, David.epub
1434	EPUB	990171	C:\CBH_Data\calibre.git\Library.test_small\A. B. C. Personn\1632 - Flint Eric (1434)\1632 - Flint Eric - A. B. C. Personn.epub


Libre office calc shows this file as
Click image for larger version

Name:	Clipboard01.jpg
Views:	31
Size:	112.8 KB
ID:	206401

Edit: it would be easy for the script to use a search expression instead of a list of ids. Let me know if you want an example script.

Last edited by chaley; 02-14-2024 at 05:42 PM. Reason: Discussed the possibility of using a search in the script
chaley is offline   Reply With Quote
Old 02-14-2024, 10:08 PM   #8
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: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibredb list --fields=formats
kovidgoyal is offline   Reply With Quote
Reply

Tags
calibredb, export, location, meta data, path


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping annotations/bookmarks in file -- save upon command/close instead of at once? graatch Calibre 3 07-04-2021 01:36 AM
How can I show document paths for each book? MarjaE Library Management 2 04-02-2021 01:39 AM
File paths not case sensitive in preview window? shadowmanwkp Sigil 4 04-25-2020 11:25 AM
Bug in renaming file in BookBrowser should show full paths mode. The_book Sigil 8 03-25-2020 02:20 PM
[Old Thread] Calibre Command line and .bat file stratman Calibre 15 01-10-2012 05:38 PM


All times are GMT -4. The time now is 01:57 PM.


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