Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 04-18-2010, 04:13 PM   #1
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 550
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
Sorting a collection

Hello all, I hope you can help me with a problem I'm having.

I had tried Calibre some time ago for organizing my ebook collection, but finding it was not for me I uninstalled it. I recently discovered that it exists in a portable version, so I thought I should give it another chance and try to learn how to use it efficiently. I ran into a problem when I added a folder containing a large number of files.

The files are txt files titled in the following format:

Series - number - Title.txt

Authors were not in the title, as they weren't important for this collection. When I added the books, the series became the title, the titles became authors, and the "series" column in Calibre was blank.

I read the FAQ and went through several threads here, but all the mentions of command lines, regex, codes in curly brackets are making my head spin. I don't understand any of them, nor do I know anything about any level of programming. What I'm looking for is someone who would be so good to explain to me as they would to a small child, what do I need to do to have Calibre recognize the correct titles.

Thank you in advance.
citac is offline   Reply With Quote
Old 04-18-2010, 06:06 PM   #2
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by citac View Post
What I'm looking for is someone who would be so good to explain to me as they would to a small child, what do I need to do to have Calibre recognize the correct titles.
Click Preferences
Click Add/Save
Put this:
Code:
(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
into the box that says "Regular expression."
Then drag your books in to the main window.
Starson17 is offline   Reply With Quote
Advert
Old 04-18-2010, 07:41 PM   #3
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 550
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
Quote:
Originally Posted by Starson17 View Post
Click Preferences
Click Add/Save
Put this:
Code:
(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
into the box that says "Regular expression."
Then drag your books in to the main window.
Hi,

thank you for the suggestion, I tried that but it doesn't recognize the series now. When I opened the Preferences dialog, I found this:

(?P<title>.+) - (?P<author>[^_]+)

I replaced it with this:

(?P<series>.+) - (?P<title>[^_]+)

I'm using the portable version found on the PortableApps website, if that makes a difference.

How would I need to name a file for cases where I'd like to see the series index and author names, for book where I want that distinction? Also, is there a way to minimize the number of folders/subfolders I get in the "Saving books" dialog?

ETA I did some poking around, and discovered that

(?P<series>[^_]+) (?P<series_index>[0-9]+) - (?P<title>.+) - (?P<author>[^_]+)

seems to work but only if I choose to have Calibre use file names as it's source of metadata. What will happen if I import a book which has metadata in the file? Will it be ignored? Also, can I have a different scheme for files named in a different way? I have some files where author is listed first; will the file be read in the correct way?

Last edited by citac; 04-18-2010 at 11:27 PM.
citac is offline   Reply With Quote
Old 04-19-2010, 10:23 AM   #4
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by citac View Post
thank you for the suggestion, I tried that but it doesn't recognize the series now.
You said your books were formatted as:

Quote:
Series - number - Title.txt
If they are formatted that way, it will work. I just tested it on this:

Code:
Series - 5 - Book title.txt
and it worked correctly. Post a book that it doesn't work on and I'll explain why.

Quote:
When I opened the Preferences dialog, I found this:

(?P<title>.+) - (?P<author>[^_]+)
That's the default.

Quote:
I replaced it with this:

(?P<series>.+) - (?P<title>[^_]+)
Yours won't do the series number. Mine will (provided your books are named as you said they were.)

Quote:
I'm using the portable version found on the PortableApps website, if that makes a difference.
That's going to be an older version, but it should still work.

Quote:
How would I need to name a file for cases where I'd like to see the series index and author names, for book where I want that distinction?
See above. I gave you a very simple regular expression, as you seemed worried about complexity. Simple expressions are easy to understand, but aren't very flexible when it comes to variations in the filename. Search for "regular expression" or "regex" if you want a complex, but flexible expression.

Quote:
Also, is there a way to minimize the number of folders/subfolders I get in the "Saving books" dialog?
Yes, see the next tab on the page that has the regex we're talking about,.

Quote:
discovered that

(?P<series>[^_]+) (?P<series_index>[0-9]+) - (?P<title>.+) - (?P<author>[^_]+)

seems to work but only if I choose to have Calibre use file names as it's source of metadata.
That won't work with the way you said you named your files. There's no hyphen between the series and series number. You always have to have Calibre use file names as it's source of metadata for the regex to apply.

Quote:
What will happen if I import a book which has metadata in the file? Will it be ignored?
Yes
Quote:
Also, can I have a different scheme for files named in a different way? I have some files where author is listed first; will the file be read in the correct way?
It depends on your regex and how "different" the names are. You can make things optional (like your hyphen), but you can't make things optionally swap positions. I suggest you do some searching. There are lots of regexes available. If your files are named consistently, one of them will work.
Starson17 is offline   Reply With Quote
Old 04-19-2010, 10:29 AM   #5
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by citac View Post
How would I need to name a file for cases where I'd like to see the series index and author names, for book where I want that distinction?
I see that I didn't answer this correctly. It's easy to make the author optional. You simply put parentheses around the author and add a question mark after the closing parentheses. Post some book titles that you actually have, with and without author, and someone will show you how to do it.
Starson17 is offline   Reply With Quote
Advert
Old 04-19-2010, 09:48 PM   #6
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 550
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
Thank you, I will try these as soon as time allows, and make sure to include a hyphen between the series and series #. I found the Saving books tab, but I'm still getting too many folders for my taste, and will have to do some further research.

As for using file names as a source of metadata, I imagine it would be possible to use it as a first step during import, and later download metadata for files. I just don't have as much time as I want to research and familiarize myself with all the details so it will take me a while. Thanks again for all the suggestions.
citac is offline   Reply With Quote
Old 04-20-2010, 06:52 PM   #7
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 550
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
I tried adding parentheses around (?P<author>[^_]+) followed by a question mark, but that didn't seem to do the trick. You said I needed to add some titles for you, so here they are if you're willing to have a look.

These are all from the same author, so I want that to show up:
Beth Baker - FBI - 01 - The Games People Play
Beth Baker - FBI - 02 - The Devil’s Den
Beth Baker - FBI - 03 - Memories of the Dead

These are from various authors, about the same subject
Brothers - 01 - Reading of the Will
Brothers - 02 - Fortunate Sons
Brothers - 03 - A Matter Of Family

These two go well together:

(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
Brothers - 01 - Reading of the Will

If I change it to ((?P<author>[^_]+))? - (?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*) it doesn't work. Did I place the parentheses and question mark in the proper place? I googled various phrases containing calibre, regex, optional author but was unable to find what I needed - all possibilities seemed very complicated and didn't achieve what I was looking for when I tried them (most of my searches pointed to this forum so I went through most of them).
citac is offline   Reply With Quote
Old 04-21-2010, 09:22 AM   #8
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by citac View Post
I tried adding parentheses around (?P<author>[^_]+) followed by a question mark, but that didn't seem to do the trick.
That's no surprise....
Quote:
You said I needed to add some titles for you, so here they are if you're willing to have a look.
I did, but I have bad news.

Quote:
(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
Brothers - 01 - Reading of the Will
Yes, that works.
Quote:
If I change it to ((?P<author>[^_]+))? - (?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*) it doesn't work. Did I place the parentheses and question mark in the proper place?
Close, but not quite. That tells it that your match starts with a space-hyphen-space. When your book filenames don't have an author, you don't omit just the author, you also omit the subsequent space-hyphen-space.

Here is what you wanted .. or more accurately, what I thought would work:
Code:
((?P<author>[^_]+) - )?(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
Note I moved your close parenthesis and put it around the space-hyphen-space and the author.

Unfortunately, when I did that, it worked great for the titles that have an author, but Calibre threw an error when it did not have an author.

I then tried this ({0,1} says the preceding is there zero or one times):
Code:
((?P<author>[^_]+) - ){0,1}(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
but that threw the same error.
Code:
ERROR: ERROR: Unhandled exception: <b>AttributeError</b>:'NoneType' object has no attribute 'replace'

Traceback (most recent call last):
  File "site-packages\calibre\gui2\widgets.py", line 74, in do_test
  File "site-packages\calibre\ebooks\metadata\meta.py", line 147, in metadata_from_filename
  File "site-packages\calibre\ebooks\metadata\__init__.py", line 20, in string_to_authors
AttributeError: 'NoneType' object has no attribute 'replace'
I'd need to look at the code to find out why. You may want to post a bug report. I think those should have worked. Calibre will normally substitute "Unknown" for an author name if it's blank, but making the author optional in this way potentially bypasses that code in a way that throws this error.

Sorry, but I'm out of ideas. I've never actually needed an optional author regex, and I'm a bit short on time to test it further.

Last edited by Starson17; 04-21-2010 at 09:37 AM.
Starson17 is offline   Reply With Quote
Old 04-21-2010, 04:22 PM   #9
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 550
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
Quote:
Originally Posted by Starson17 View Post
....I have bad news.

Here is what you wanted .. or more accurately, what I thought would work:
Code:
((?P<author>[^_]+) - )?(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
Note I moved your close parenthesis and put it around the space-hyphen-space and the author.

Unfortunately, when I did that, it worked great for the titles that have an author, but Calibre threw an error when it did not have an author.

I then tried this ({0,1} says the preceding is there zero or one times):
Code:
((?P<author>[^_]+) - ){0,1}(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
but that threw the same error.
Code:
ERROR: ERROR: Unhandled exception: <b>AttributeError</b>:'NoneType' object has no attribute 'replace'

Traceback (most recent call last):
  File "site-packages\calibre\gui2\widgets.py", line 74, in do_test
  File "site-packages\calibre\ebooks\metadata\meta.py", line 147, in metadata_from_filename
  File "site-packages\calibre\ebooks\metadata\__init__.py", line 20, in string_to_authors
AttributeError: 'NoneType' object has no attribute 'replace'
I'd need to look at the code to find out why. You may want to post a bug report. I think those should have worked. Calibre will normally substitute "Unknown" for an author name if it's blank, but making the author optional in this way potentially bypasses that code in a way that throws this error.

Sorry, but I'm out of ideas. I've never actually needed an optional author regex, and I'm a bit short on time to test it further.
First of all, thank you very much for your patience in walking me through totally unfamiliar territory for me. I gave up on Calibre the first time due to several reasons, but this time I wanted to try and learn how to use it and customize it as possible to fit my needs.

I will look into posting a bug report for this. In the mean time, I went through the Calibre forum one more time with a fine tooth comb, and found a thread where the OP requested help with something similar. There were several regexes there, and I tried each. Finally, it turned out this worked:

^((?P<author>([^\-_0-9]+)(?=\s*-\s*)(?!\s*-\s*[0-9.]+)|\b))(\s*-\s*)?(\[?(?P<series>[^0-9\-]+) (- )?(?P<series_index>[0-9.]+)\]?\s*-\s*)?(?P<title>.+)

It doesn't add "Unknown" but leaves the author's name completely blank. Why, I have no idea, and I guess you would understand it better than I do. Thanks again.
citac is offline   Reply With Quote
Old 04-21-2010, 04:53 PM   #10
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by citac View Post
Finally, it turned out this worked:

^((?P<author>([^\-_0-9]+)(?=\s*-\s*)(?!\s*-\s*[0-9.]+)|\b))(\s*-\s*)?(\[?(?P<series>[^0-9\-]+) (- )?(?P<series_index>[0-9.]+)\]?\s*-\s*)?(?P<title>.+)
That looks like the one I use, and I think it's one I wrote - I recognize the optional square brackets

That's what I get for listening to you when you said:
Quote:
all the mentions of command lines, regex, codes in curly brackets are making my head spin.
I believed you when you said your files were in a particular format and I tried to make it simple, not flexible.

I'm really going to have to look at why my simpler expressions threw errors.

Quote:
It doesn't add "Unknown"
It will when you actually add a book to calibre with a blank author.
Starson17 is offline   Reply With Quote
Old 04-21-2010, 08:23 PM   #11
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 550
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
Quote:
Originally Posted by Starson17 View Post
That looks like the one I use, and I think it's one I wrote - I recognize the optional square brackets

That's what I get for listening to you when you said:


I believed you when you said your files were in a particular format and I tried to make it simple, not flexible.
Sorry! I thought simple would work. Simple is good, most of the time. And really, that's the way I name most of my files, which are a mix of free books, fanfic, academic pdfs and various fiction books. I place files in author folders, so it seems redundant to me to add an author name to the file. E.g. for fanfic, I've got Fandom > Authors > Files.

Quote:
I'm really going to have to look at why my simpler expressions threw errors.

Quote:
It will when you actually add a book to calibre with a blank author.
When I tested it, it just left the field blank, it didn't add "unknown". I will soon add some files without an author listed and see what happens.
citac is offline   Reply With Quote
Old 04-21-2010, 08:44 PM   #12
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by citac View Post
Sorry!
I was just giving you a hard time
Starson17 is offline   Reply With Quote
Reply

Tags
calibre sorting


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting by Author Ben Thornton Amazon Kindle 6 08-31-2010 10:03 PM
Title Sorting / Author Sorting ahi Sony Reader 0 09-14-2009 01:51 PM
"Sort By Author" not sorting correctly within author's collection Sonist Amazon Kindle 1 08-05-2009 07:52 PM
Sorting out my ebook collection using Calibre river Calibre 6 06-16-2009 03:16 AM
sorting strahlemann Sony Reader 0 11-19-2008 10:09 PM


All times are GMT -4. The time now is 07:03 AM.


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