Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 07-10-2018, 01:58 AM   #1
wjBLqf-_9
Member
wjBLqf-_9 began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Jul 2018
Device: None
Angry Help me Regex Gurus.... "you're my only hope"... I screwed up a lot of my books!

I started getting really good at regex (all in one day)

I should've quit while I was ahead

I cannot recall the steps I took to screw this up... but here goes:

Two problems:
Problem #1 = Some of my books have the TITLE pre-pended the list of tags
(i.e. "book-title-is-now-the-1st, in, this, list, of, existing, tags")

Problem #2 = Some of my books have the TITLE appended the list of tags
(i.e. "this, list, of, existing, tags, ends, with, book-title-is-now-the-1st")

Is there **any** way to search the tag field for the title and remove it from the tag field?

Then repeat for the remaining 8,000+ books?

Thanks!
wjBLqf-_9 is offline   Reply With Quote
Old 07-19-2018, 10:20 AM   #2
andrewferguson
Junior Member
andrewferguson began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jul 2018
Device: Android
Hello!

My knowledge of regex is extremely limited, but I do know Python, and I think I could probably cobble together a quick script that would fix your books for you. Do you have Python installed on your computer?
andrewferguson is offline   Reply With Quote
Advert
Old 07-19-2018, 10:29 AM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 33,396
Karma: 10205094
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
If he has calibre installed, he has python. You canrun any python script like this:

calibre-debug file.py
kovidgoyal is online now   Reply With Quote
Old 07-19-2018, 11:44 AM   #4
andrewferguson
Junior Member
andrewferguson began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jul 2018
Device: Android
So I've written a quick python script that should fix this for you.

Firstly, before you do ANYTHING, back up your Calibre books. I take no responsibility for any data loss that arises out of using the script. Although it worked fine on my library when I tested it a few minutes ago, you can never be too safe.

Then download the file fixcal.py (attached to this reply), open up a terminal or command-prompt, then run it either using python (e.g: python fixcal.py) or using calibre-debug (e.g: calibre-debug fixcal.py) if you don't have Python. This should not alter any of your books, but will instead print out a list of all books that contain the title of the book in the tags of the book. Check this output to ensure that the script isn't behaving funny, and if you're not sure if it is right, double-check before going any further.

Once you are happy that the script will be modifying the tags of the right books, run the script again, this time adding the "overwrite" option, eg: python fixcal.py overwrite / calibre-debug fixcal.py overwrite . This will actually modify the tags of the books to remove the title from the tag list.

Note: The script *doesn't* check just the first or last tag for the title, it checks them all. So if this isn't what you want (say, if you have the title in the tags of the book but it's the third tag in and you want to keep this tag) reply and I'll update the script for this.

Let me know how you get on..... and remember to backup your books first!
Attached Files
File Type: py fixcal.py (550 Bytes, 46 views)
andrewferguson is offline   Reply With Quote
Reply

Tags
regex, screwed up, tags, ufda

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
regex "?" with higher priority greedynes then the previous "?" ? user743 Editor 1 05-04-2014 03:57 AM
[Old Thread] Regex "FN LN" to "LN, FN" & reverse? unboggling Library Management 19 11-20-2013 06:44 AM
Problem with "Add Books" regex wygit Library Management 9 07-24-2011 12:24 PM
Is Fictionwise acting in good faith over a "screwed-up" book from a publisher? Dr. Drib News 2 03-02-2009 04:39 PM
"I'd like to sell a hell of a lot more than we're selling" says Sony Rep Fugubot News 13 10-21-2007 01:16 PM


All times are GMT -4. The time now is 01:33 PM.


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