MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Calibre (https://www.mobileread.com/forums/forumdisplay.php?f=166)
-   -   Need Help With "Regular Expression Syntax" (https://www.mobileread.com/forums/showthread.php?t=101005)

dkritso109 10-02-2010 03:27 PM

Need Help With "Regular Expression Syntax"
 
Hey all,
I am seriously confused with Regular Expression Syntax. All of my file names are like this:
----------------------------------------------------------------------------------------
Single Books:

Armstrong, Kelley - Jaurķa

Book Series:

Armstrong, Kelley - Otherworld 1 - Bitten
----------------------------------------------------------------------------------------
Calibre does not pick up any information at all from these filenames, the title nor the author. Can someone please forward me a syntax that works for this type of file name system?

Manichean 10-02-2010 04:33 PM

There's a tutorial available in Calibre's user manual.

kacir 10-02-2010 05:00 PM

Quote:

Originally Posted by Manichean (Post 1142212)
There's a tutorial available in Calibre's user manual.

I am aware that there is tutorial available ;-), but I haven't been able to figure out how to parse
Armstrong, Kelley - Otherworld 1 - Bitten
so I get author name Kelley Armstrong

I can extract author, title, series, even make series optional(*), yet I haven't found a way of how to parse (LastName, FirstName|Firstname Lastname) to the {authors} field.


(*) I *think*, because I found one unpleasant limitation in python RE engine used to parse names in calibre

dkritso109 10-02-2010 05:12 PM

see my dilemma??? can anyone give me an expression that most closely extracts the relevant data i need into the metadata card?

Manichean 10-02-2010 05:15 PM

You could always extract the lastname, firstname into {authors} and fix it up with search & replace later. Other than that, off the top of my head, I can't think of any solution.

dkritso109 10-02-2010 05:20 PM

i have literaly thousands of books in that format, we are talking like a month's work of copy and pasting. i have gone over the tutorial with no avail.

Manichean 10-02-2010 05:25 PM

Quote:

Originally Posted by dkritso109 (Post 1142278)
i have literaly thousands of books in that format, we are talking like a month's work of copy and pasting. i have gone over the tutorial with no avail.

I'm not talking about copying and pasting, I'm talking about the search & replace in bulk metadata editing. If you import your books with lastname, firstname in {authors} and then do a bulk metadata search & replace on {authors}, searching for
Code:

(.*?),\s(.*?)
and replacing it with
Code:

\2 \1
you should be fine. (Caution: I haven't tested that expression, but it should do the trick if the fields are the way I assumed in this post.)

kacir 10-02-2010 05:28 PM

Quote:

Originally Posted by dkritso109 (Post 1142262)
see my dilemma??? can anyone give me an expression that most closely extracts the relevant data i need into the metadata card?

At this very moment I do it this way:
- When I need to process a few books, I do it manually, with Drag & Drop of the book, then I press E and use icons next to title, name, author to swap some words.
- when I have many books to import, especially when they are just files with name of book in a directory that has author name, I make listing of all files (on Linux) it is like
Code:

cd ~/BooksToProcess
find . -type f > copybooks.sh

on Windows you would use something like dir /R/B > copybooks.bat

Then I open copybooks.sh in Gvim text editor and I massage it with Regular-Expresion-Fu until I get something like
Code:

cp '~/BooksToProcess/Armstrong, Kelley/Otherworld/ 1 - Bitten' '~/ImportTempDir/Kelley Armstrong - Otherworld 1 - Bitten'
then I import books into Calibre in bulk.

Another solution with the newest Calibre would be to import the books as they are, and then process Authors field using Regular Expressions with backreferences.
So:
Select books
Right click, select Bulk Edit Metadata
go to Search and Replace
select Search mode Regular Expressions
Search for ([^,]*), (.*)
Replace expression \2 \1
and, of course select Search Field and Destination Field "authors"

DO NOT FORGET TO MAKE BACKUP OF THE LIBRARY BEFORE ATTEMPTING SOMETHING LIKE THIS

Manichean 10-02-2010 05:32 PM

Quote:

Originally Posted by kacir (Post 1142295)
Another solution with the newest Calibre would be to import the books as they are, and then process Authors field using Regular Expressions with backreferences.
So:
Select books
Right click, select Bulk Edit Metadata
go to Search and Replace
select Search mode Regular Expressions
Search for ([^,]*), (.*)
Replace expression \2 \1
and, of course select Search Field and Destination Field "authors"

Your search expression is better than mine, I think... Although I used non-greedy quantifiers, it should be safer to exclude the comma.

dkritso109 10-02-2010 05:37 PM

wow, i think i'm gonna take a perl programming class at the local community college just so i can figure out a regular expression that works! or just pay a teenager minimum wage to go file by file and input them the way i want. don't know which way would be cheaper yet.

Manichean 10-02-2010 05:40 PM

Quote:

Originally Posted by dkritso109 (Post 1142311)
wow, i think i'm gonna take a perl programming class at the local community college just so i can figure out a regular expression that works! or just pay a teenager minimum wage to go file by file and input them the way i want. don't know which way would be cheaper yet.

If you have to take a class, take a Python class, since Calibre is written in that language. Alternatively, go over the tutorial once again from the very beginning to the very end, and if that doesn't help, post where you're stuck, so we can try to help.

dkritso109 10-02-2010 05:47 PM

yeah you guys are awesome thanks, i been going over it for hours and hours now. i could've read a few books by now. will continue to try and i'll post back with an update. thanks again, also if anyone does figure it out hit me up.

Manichean 10-02-2010 05:51 PM

Quote:

Originally Posted by dkritso109 (Post 1142337)
yeah you guys are awesome thanks, i been going over it for hours and hours now. i could've read a few books by now. will continue to try and i'll post back with an update. thanks again, also if anyone does figure it out hit me up.

Wait, "if anyone does figure it out"? Both kacir and myself posted solutions to this. I don't think there's anything left to figure out.

dkritso109 10-02-2010 06:01 PM

i still can't get the author to load from FN,LN to LN,FN. from what i have gathered i have to go back and redo them with search and replace correct? that is where i am still lost.

chaley 10-02-2010 06:04 PM

Quote:

Originally Posted by Manichean (Post 1142346)
Wait, "if anyone does figure it out"? Both kacir and myself posted solutions to this. I don't think there's anything left to figure out.

Maybe you should volunteer to be his teenager. :)


All times are GMT -4. The time now is 06:07 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.