![]() |
#16 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
I figured something out.
![]() Save this code as a file, "calibre-add-format-blank-txt.py". But first, see the bit in red? Change that to 'C:\\Users\Josieb1\\Calibre Library\\' or wherever your library is located, and make sure there are two backslashes. ![]() Then run the following command in the command prompt: Code:
calibre-debug.exe C:\path\to\wherever\you\put\calibre-add-format-blank-txt.py Code:
def init_cache(library_path):
from calibre.db.backend import DB
from calibre.db.cache import Cache
backend = DB(library_path)
cache = Cache(backend)
cache.init()
return cache
import tempfile
temporary_txt_file = tempfile.NamedTemporaryFile(suffix='txt', delete=False)
cache = init_cache(library_path = 'C:\\Users\\<username>\\Calibre Library\\')
for id in cache.all_book_ids():
cache.add_format(id, 'TXT', temporary_txt_file)
![]() Does this look good? I decided it wasn't worth trying to deal with json on other peoples' machines ![]() Tested on a test library of mine, on a Win7 machine. Last edited by eschwartz; 11-26-2014 at 09:15 PM. |
![]() |
![]() |
![]() |
#17 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Some comments: - Why did you create the temp file for the txt format instead of simply using its path? EDIT: ahhh, I see. You created an empty txt file to avoid the necessity of passing one in as an argument or having one sitting around. - You should first get the IDs that don't have a TXT format and add it only to them. Use something like cache.search('not formats:=TXT'). This is where the user could also add some criteria, such as doing it only if a book has a certain tag. - You might want to put try/except around the add_format - Is it worth checking add_format's returned value and printing an error? Last edited by chaley; 11-27-2014 at 05:44 AM. |
|
![]() |
![]() |
![]() |
#18 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
Quote:
![]() I had a few problems getting the path right but eventually I got the message Welcome to the Interactive Calibre Shell. Does that mean its working? I have nearly 6000 books so I don't know how long to leave it before I check in Calibre. Last edited by Josieb1; 11-27-2014 at 05:05 AM. |
|
![]() |
![]() |
![]() |
#19 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
I just opened Calibre and I don't have any format for TXT so i guess i did something wrong. In the command prompt I input
calibre-debug.exe C:\Users\Jenny\Documents\Calibre Library\ And the code in the py is (it is inside a box is that an issue)? def init_cache(library_path): from calibre.db.backend import DB from calibre.db.cache import Cache backend = DB(library_path) cache = Cache(backend) cache.init() return cache import tempfile temporary_txt_file = tempfile.NamedTemporaryFile(suffix='txt', delete=False) cache = init_cache(library_path = 'C:\\Users\\Jenny\\Documents\\Calibre Library\\') for id in cache.all_book_ids(): cache.add_format(id, 'TXT', temporary_txt_file) Last edited by Josieb1; 11-27-2014 at 05:15 AM. |
![]() |
![]() |
![]() |
#20 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@Josieb1: two things.
1) You put the python code into a file. The file can be anywhere. It must end with ".py". Lets assume you put it in documents, at the same level as your library in the file add_txt.py. 2) Given the above assumption, the command line you use would be Code:
calibre-debug C:\Users\Jenny\Documents\add_txt.py |
![]() |
![]() |
![]() |
#21 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@Josieb1: And please please make a backup of your library before you run the script.
|
![]() |
![]() |
![]() |
#22 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
Quote:
calibre-debug.exe C:\Users\Jenny\Documents\Calibre Library\calibre-add-format-blank-txt.py I keep a full Calibre back up in Dropbox ![]() The file is in the Calibre Library and I changed the doc extension to be py once I was sure the code was correct (i hope) |
|
![]() |
![]() |
![]() |
#23 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
calibre-debug.exe "C:\Users\Jenny\Documents\Calibre Library\calibre-add-format-blank-txt.py" Last edited by chaley; 11-27-2014 at 06:10 AM. Reason: correction: "txt" should have been "py" in one instance |
|
![]() |
![]() |
![]() |
#24 | |
US Navy, Retired
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,897
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Kindle PaperWhite SE 11th Gen
|
Quote:
Here is the FAQ on how to direct which directory CC will place the books. And here is a link to CC main FAQ. Now back to your regular thread conversation. |
|
![]() |
![]() |
![]() |
#25 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
Quote:
Edited to say yes my file is gibberish ![]() Last edited by Josieb1; 11-27-2014 at 10:32 AM. |
|
![]() |
![]() |
![]() |
#26 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#27 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
I'm not sure exactly what i'm supposed to see.
I opened a new Notepad page (using Notepad + +) and copied the code into that. Then saved it with the correct name. Then I ran the command prompt screen and got the usual Welcome to the Interactive Calibre Shell. Nothing has happened in Calibre. I guess I was execting to see a new format of 'txt' And no books have a txt file showing. And when I went back into my Calibre Library (which is where the file was) and its gone. I'm out of options now. Can anyone guide me on what I'm doing wrong please ![]() Last edited by Josieb1; 11-27-2014 at 12:11 PM. |
![]() |
![]() |
![]() |
#28 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Here is an example of what starting the script should look like. The file names are not what you would use, but the form is correct. The first command (dir) checks that the file name of the test script is correct by printing some information about it. The second command, calibre-debug, actually runs the script. I added the -e option so that calibre-debug knows to expect a script. I suggest you do the same thing. If all goes well when you start the script, it won't say anything but will take a fair amount of time to run. Do not start calibre while it is running! If you get bored after a time, use CTRL-C to kill the script, at which point you can start calibre to see if any txt formats have appeared. Be sure that calibre is not running when you start the script. Code:
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. d:\CBH_Data\calibre.git>dir "D:\CBH_Data\calibre.git\tests\all_tags.py" Volume in drive D is CBH_DATA Volume Serial Number is C63D-6515 Directory of D:\CBH_Data\calibre.git\tests 03/03/2014 14:15 378 all_tags.py 1 File(s) 378 bytes 0 Dir(s) 688,465,313,792 bytes free d:\CBH_Data\calibre.git>calibre-debug -e "D:\CBH_Data\calibre.git\tests\all_tags.py" |
|
![]() |
![]() |
![]() |
#29 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
Thank you. This is the name of the actual notepad file. I did select py as the save extension. I never amended the txt file extension
calibre-add-format-blank-txt.py The file is now in the main Documents folder so the path is this C:\Users\Jenny\Documents\calibre-add-format-blank-txt.py so as far as I can tell my command prompt should be this calibre-debug.exe C:\Users\Jenny\Documents\calibre-add-format-blank-txt.py the Code within the Notepad file is as below:- Code:
def init_cache(library_path):
from calibre.db.backend import DB
from calibre.db.cache import Cache
backend = DB(library_path)
cache = Cache(backend)
cache.init()
return cache
import tempfile
temporary_txt_file = tempfile.NamedTemporaryFile(suffix='txt', delete=False)
cache = init_cache(library_path = 'C:\\Users\\Jenny\\Documents\\')
for id in cache.all_book_ids():
cache.add_format(id, 'TXT', temporary_txt_file)
Last edited by chaley; 11-27-2014 at 12:22 PM. Reason: Added code tags |
![]() |
![]() |
![]() |
#30 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,086
Karma: 18051062
Join Date: Nov 2009
Location: UK
Device: Kindle Scribe, Coloursoft, PW SE, Kindle 6, Kobo Libra 2
|
I've had another go now my file is in Documents and this time the prompt just returned
C:\Users\Jenny> Last edited by Josieb1; 11-27-2014 at 12:25 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Books I didn't buy on 2 new Kobo Wifi readers (not 100 free books) | tylermckellar | Kobo Reader | 12 | 07-26-2012 09:29 PM |
A Noobs Guide to Borrowing E-Library Books and Installing non Kobo Bookstore Books | bamelin | Kobo Reader | 17 | 01-07-2012 04:11 PM |
Free (Kindle/Nook)(some at Sony/iBooks) Six books from Writers Digest Books | arcadata | Deals and Resources (No Self-Promotion or Affiliate Links) | 12 | 11-13-2011 02:10 PM |
Free books (Kobo) - 20 Dorchester Publishing Books (Romance, Horror, Thriller etc.) | ATDrake | Deals and Resources (No Self-Promotion or Affiliate Links) | 15 | 09-24-2010 07:01 PM |
Two free books (kobo) from Francesca Lia Block [BOOKS DELETED BY AUTHOR] | koland | Deals and Resources (No Self-Promotion or Affiliate Links) | 11 | 04-08-2010 06:03 AM |