11-27-2014, 12:24 PM | #31 | |
Grand Sorcerer
Posts: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
EDIT: you didn't specify your library correctly. Change the program to the following, being sure that the path to the library is correct. 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 print('Starting adding txt formats') import tempfile temporary_txt_file = tempfile.NamedTemporaryFile(suffix='txt', delete=False) cache = init_cache(library_path = 'C:\\Users\\Jenny\\Documents\\Calibre Library') print('Starting loop') for id in cache.all_book_ids(): cache.add_format(id, 'TXT', temporary_txt_file) print('Finished') Last edited by chaley; 11-27-2014 at 12:29 PM. |
|
11-27-2014, 12:34 PM | #32 | |
Grand Sorcerer
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
|
Quote:
|
|
Advert | |
|
11-27-2014, 12:42 PM | #33 |
Grand Sorcerer
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
|
Charley your fabulous!
I know have the words Starting adding txt formats Starting loop So i will just leave my pc tonight and see what happens later And thank you eschwartz for the original code And I apologise for being such a numpty |
11-27-2014, 01:17 PM | #34 |
Grand Sorcerer
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
|
IT WORKED!
5539 txt files of 0KB created Charley and eschwartz I'll make notes so if anyone else wants to do it they can |
11-27-2014, 04:12 PM | #35 | |||
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
Quote:
Um... add_format does have a "replace=True" default, so I guess we could just use: Code:
for id in cache.all_book_ids(): cache.add_format(id, 'TXT', temporary_txt_file, replace=False) Quote:
But if we are to limit to a search of not formats:"=TXT" then we will never get it. Using your print modifications as well. 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 print('Creating temporary TXT file') import tempfile temporary_txt_file = tempfile.NamedTemporaryFile(suffix='txt', delete=False) from calibre.utils.config import prefs library_path = prefs['library_path'] print('Initializing database') cache = init_cache(library_path) print('Begin looping through books') failed_books = 0 ids = 0 for id in cache.search('not formats:"=TXT"'): ids += 1 try: cache.add_format(id, 'TXT', temporary_txt_file, replace=False) except: failed_books+=1 print('Failed to add TXT format for book with id', id) print('Finished adding TXT format to', ids, 'books') if failed_books > 0: print(failed_books, 'books did not have a TXT format added') Anyway, good to hear it worked, thanks chaley for helping out while I was offline. Do not worry about being unable to get it at first. It isn't in your skillset, and you are hardly unusual in that regard. I probably should've mentioned in the first place that you will need Notepad. It would help if Windows wasn't so eager to rid the world of file extensions. Attached is the actual file, redundant though it may now be -- rename to .py (we really should be able to attach any file we want). EDIT: Updated to use calibre's internal preferences to choose the library. No need to edit anything. Last edited by eschwartz; 08-18-2015 at 12:21 PM. |
|||
Advert | |
|
11-27-2014, 04:29 PM | #36 | |
null operator (he/him)
Posts: 20,550
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
Uncheck Control Panel->Folder Options->View->Advanced Settings->Hide extensions for known file types. BR |
|
11-27-2014, 04:42 PM | #37 | |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
I just think it is deplorable that they have basically ensured (through several means) that several generations have no idea what a filetype is. Last edited by eschwartz; 11-27-2014 at 05:14 PM. |
|
11-27-2014, 04:57 PM | #38 |
Grand Sorcerer
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
|
I think ages ago I set my pc up to show files types so at least I had a bit of a clue there.
Thanks again for the original code eschwartz and for sorting me out on the other thread. I've made some notes now so I should be okay going forward. |
11-27-2014, 05:07 PM | #39 | ||
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
Quote:
|
||
11-27-2014, 05:15 PM | #40 |
null operator (he/him)
Posts: 20,550
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
I guess you never worked on a help desk supporting tens of thousands of users spread westwards from Fiji to Honolulu - the request would have come from MS's multinational corporate clients.
Most people get along fine without knowing about extensions because they do what they need to do by clicking pretty icons on their desktops to start programs and then opening the data they want. The files types presented in the programs are often limited to the ones the program is designed to handle not unlike Add files to selected books presents only ebook file types. The start at a program paradigm pre-dates Windows by at least a decade. If people wanted to drive their systems from their data they would all be installing 3rd party multi-pane tabbed file managers, but they don't, they install glitz and glamour laden gadgets like StarDock and or have apoplexy when their Start button disappears BR Last edited by BetterRed; 11-27-2014 at 05:23 PM. |
11-27-2014, 05:35 PM | #41 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
@Josieb1, in answer to your question:
yes, if you rerun the program it should again add a blank TXT file as a new format to each book. I updated it so it won't destroy TXT formats you already have, it will only add them to books without a TXT format. (See post #35.) The format must be added via calibre's backend, in order for calibre to track it in the database -- so make sure you do it through the calibre interface or else through my .py file. |
11-27-2014, 05:39 PM | #42 | |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
|
|
11-27-2014, 05:40 PM | #43 | |
Grand Sorcerer
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
|
Quote:
|
|
11-27-2014, 05:43 PM | #44 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
|
11-27-2014, 05:45 PM | #45 |
Grand Sorcerer
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
|
Sorry I spotted the attachment after I posted. I'm on my iPad now so I'll be sure to save that in the morning. I'll give it a go over the weekend (work tomorrow) and report back how I get on.
If I write up some notes maybe this information could be made a sticky as I'm sure there are others would would love to have just the metadata in Calibre Companion. Thanks again |
|
Similar Threads | ||||
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 |