Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre Companion

Notices

Reply
 
Thread Tools Search this Thread
Old 11-27-2014, 12:24 PM   #31
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,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Josieb1 View Post
I've had another go now my file is in Documents and this time the prompt just returned

C:\Users\Jenny>
Did it add any txt formats?

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')
When you run the script you should see some output from the three print() statements.

Last edited by chaley; 11-27-2014 at 12:29 PM.
chaley is offline   Reply With Quote
Old 11-27-2014, 12:34 PM   #32
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
Quote:
Originally Posted by chaley View Post
Did it add any txt formats?

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')
When you run the script you should see some output from the three print() statements.
ohh I see what you mean , let me have another go. If this ever works i'll write up some notes!
Josieb1 is offline   Reply With Quote
Advert
Old 11-27-2014, 12:42 PM   #33
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
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
Josieb1 is offline   Reply With Quote
Old 11-27-2014, 01:17 PM   #34
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
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
Josieb1 is offline   Reply With Quote
Old 11-27-2014, 04:12 PM   #35
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by chaley View Post
Looks mostly good.

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.
Yep. I wanted to limit the number of named paths to be user-edited.

Quote:
- 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.
Good idea.

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)
We could do a search instead, or in addition (because I am still wary of overwriting another TXT) if I thought this script was going to get a lot of use. Heck, let's do it anyway.

Quote:
- You might want to put try/except around the add_format
- Is it worth checking add_format's returned value and printing an error?
Hmm, I don't know. Checking the source for add_format, it returns true unless early on it sees there is already a copy of that format AND replace=False.I guess it assumes the function will never error out, possibly because it shouldn't ever do so.
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.
Attached Files
File Type: txt calibre-add-format-blank-txt.txt (839 Bytes, 140 views)
File Type: txt v2-calibre-add-format-blank-txt.txt (1,003 Bytes, 117 views)

Last edited by eschwartz; 08-18-2015 at 12:21 PM.
eschwartz is offline   Reply With Quote
Advert
Old 11-27-2014, 04:29 PM   #36
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: 20,550
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by eschwartz View Post
It would help if Windows wasn't so eager to rid the world of file extensions.
Because people think by changing them the fairies will sprinkle stardust to change their MP3s into FLACs and their TIFFS into JPEGS

Uncheck Control Panel->Folder Options->View->Advanced Settings->Hide extensions for known file types.

BR
BetterRed is offline   Reply With Quote
Old 11-27-2014, 04:42 PM   #37
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by BetterRed View Post
Because people think by changing them the fairies will sprinkle stardust to change their MP3s into FLACs and their TIFFS into JPEGS

Uncheck Control Panel->Folder Options->View->Advanced Settings->Hide extensions for known file types.

BR
Oh, I do.

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.
eschwartz is offline   Reply With Quote
Old 11-27-2014, 04:57 PM   #38
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
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.
Josieb1 is offline   Reply With Quote
Old 11-27-2014, 05:07 PM   #39
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by Josieb1 View Post
I think ages ago I set my pc up to show files types so at least I had a bit of a clue there.
Sorry. That ^^ was just my general rant at a cruel uncaring world. I guess my day/week just isn't complete (based on track my record here ) if I cannot complain about Windows making something more difficult than it should be, somehow, somewhere.

Quote:
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.
You're welcome.
eschwartz is offline   Reply With Quote
Old 11-27-2014, 05:15 PM   #40
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: 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.
BetterRed is offline   Reply With Quote
Old 11-27-2014, 05:35 PM   #41
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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.
eschwartz is offline   Reply With Quote
Old 11-27-2014, 05:39 PM   #42
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by BetterRed View Post
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
But... but... but... data is the important stuff!
eschwartz is offline   Reply With Quote
Old 11-27-2014, 05:40 PM   #43
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
Quote:
Originally Posted by eschwartz View Post
@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.
@eschwartz, thank you. So I just update the py with the new code from post 35?
Josieb1 is offline   Reply With Quote
Old 11-27-2014, 05:43 PM   #44
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by Josieb1 View Post
@eschwartz, thank you. So I just update the py with the new code from post 35?
Or download and rename the attachment.
eschwartz is offline   Reply With Quote
Old 11-27-2014, 05:45 PM   #45
Josieb1
Grand Sorcerer
Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.Josieb1 ought to be getting tired of karma fortunes by now.
 
Posts: 5,009
Karma: 18018738
Join Date: Nov 2009
Location: UK
Device: Kobo Forma, Libra2, Clara 2e, Kindle PW SE & Kindle 2022
Quote:
Originally Posted by eschwartz View Post
Or download and rename the attachment.
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
Josieb1 is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 11:28 PM.


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