Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 01-06-2013, 09:59 AM   #1
snipe2004
Junior Member
snipe2004 began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2013
Device: Pc - Linux - Calibre
Desperately Looking for a Regex

Hi guys,

I'm desperately looking for a regex which would automatically search in my eBooks' titles the string "2012" (for example) and put it in my pubdate field. And, once this is done, I would also like it to replace some other fields like this, but the pubdate is the hardest for me.

Let me show you an example :

The pdf file is : TitleOfTheSerie Volume1 Number1 (out of 3) (2012)
I would like to use the Search&Replace function of Calibre to extract those informations and put them in the correct place.
So : 2012 -> pubdate (I'll use january everytime)
TitleOftheSerie -> Serie
Number -> Serie[X]

Quote:
Originally Posted by HarryT View Post
Try using a search string of:

<p>([0-9]*)</p>

and a replace string of:

<h3>\1</h3>

ie, with parentheses around the "search string" for the numbers.
So this seems very useful to me! I already adapted it to this :

Search in : title
For : ([0-2][0-9][0-9][0-9])
And replace it by : janv. \1
In : pubdate

But I get an error :

Code:
unknown string format

calibre, version 0.9.11
ERREUR : Echec: unknown string format

Traceback (most recent call last):
  File "/usr/lib/calibre/calibre/gui2/dialogs/metadata_bulk.py", line 125, in do_one_safe
    self.do_one(id)
  File "/usr/lib/calibre/calibre/gui2/dialogs/metadata_bulk.py", line 290, in do_one
    self.s_r_func(id)
  File "/usr/lib/calibre/calibre/gui2/dialogs/metadata_bulk.py", line 851, in do_search_replace
    setter(id, val, notify=False, commit=False)
  File "/usr/lib/calibre/calibre/library/database2.py", line 2613, in set_pubdate
    dt = parse_only_date(dt)
  File "/usr/lib/calibre/calibre/utils/date.py", line 94, in parse_only_date
    ans = parse_date(raw, default=default, assume_utc=assume_utc)
  File "/usr/lib/calibre/calibre/utils/date.py", line 80, in parse_date
    dt = parse(date_string, default=default, dayfirst=parse_date_day_first)
  File "/usr/lib/python2.7/dist-packages/dateutil/parser.py", line 697, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/usr/lib/python2.7/dist-packages/dateutil/parser.py", line 303, in parse
    raise ValueError, "unknown string format"
ValueError: unknown string format
I also tried many combinations such as :
1-1-\1
01/01/\1
01 janv. \1
but none of them had worked
Could you help me?
Thanks in advance,
Snipe
snipe2004 is offline   Reply With Quote
Old 01-06-2013, 10:39 AM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,791
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Dates are tricky. I think that this is because of Locale rules coming into play.

Next: Mon Year (in any order) is not a valid date . You need all 3 of DD MM YYYY: 01 Jan 2012


Next is where you use the pattern:
Preferences:Adding Books
or
The Metadata Editor (Bulk mode) I only have luck/skill here


TitleOfTheSerie Volume1 Number1 (out of 3) (2012)

(.+) (\(.+\))\s*\(([\d]{4})\)

Notes: (*not tested)
Group 1 is everything up to the space before the first (
Group 2 is the (out of ... ) pay attention to the escaped ( and )
Group 3 is the 4 digit only Year with the ( ) discarded , again pay attention to the escaped ( )

You are on you own constructing the replacement (used on the Published destination field) pattern (date in your Locale's format). 01 Jan \3 might do it
theducks is offline   Reply With Quote
Advert
Old 01-07-2013, 06:03 AM   #3
DoctorOhh
US Navy, Retired
DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.
 
DoctorOhh's Avatar
 
Posts: 9,864
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Nexus 7
Moderator Notice
Moved posts to their own thread. @snipe2004 Please avoid hijacking threads with off topic info requests. When in doubt start a new thread.
DoctorOhh is offline   Reply With Quote
Old 01-09-2013, 10:22 AM   #4
snipe2004
Junior Member
snipe2004 began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Jan 2013
Device: Pc - Linux - Calibre
Theducks, you're the King *_*

Thank you sooo much! It works like a charm!!

(and, sorry Dr!!)

[EDIT]
If needed : Theducks solution works out-of-the-box to extract the pubdate frome title.
To extract series frome title :
Search : (\w) (V[0-9]*) (\#)([0-9]*) (\(.+\))\s*\(([\d]{4})\) in Title
Replace : \1 [\4] in Series

Last edited by snipe2004; 01-09-2013 at 01:03 PM.
snipe2004 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Legal advice desperately needed Fluribus Lounge 3 11-27-2012 08:25 AM
Desperately seeking expert (hired) help illustrata Writers' Corner 7 06-06-2011 05:15 AM
iLiad Desperately need Advise/Help ... Iliad charging issue.... aabeg100 iRex 15 07-09-2010 12:16 PM
Desperately Seeking Software for Digitizing Books. harryE123 Reading and Management 8 12-17-2008 08:33 PM
iTouch -- info desperately needed Berni Apple Devices 36 10-05-2008 12:21 AM


All times are GMT -4. The time now is 04:16 AM.


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