10-28-2018, 05:36 AM | #1 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Pasting identifiers
Some time ago, Kovid changed the paste button for identifiers in the metadata editor to handle several prefixes. At the time, I was looking at a way to paste a URL and generate the identifier based on the metadata sources installed and identifier rules defined. I wanted this as I frequently had a URL that I wanted to add as a specific identifier type. This was especially the case for the URL covered by the identifier rules. But, because of the way the metadata download doesn't always merge results, I might want the identifier from a different result than the one I am choosing.
Doing this is easy for the rules as they are defined in a way that they can be parsed in either direction. But, this isn't possible for the metadata sources as none contain a property or method that can be used for this. To do this, I needed something added to each metadata source plugin. This could be a property that returned a pattern that could be used in the same way as the identifier rules. Or a method in the metadata source plugin that parsed the URL and returned the identifier. In the end, I decided the latter was probably the way to go. Doing it this way allows more flexibility in the parsing. Amazon with national URLs and identifiers probably need it done this way. My proposal is to add the following to ebooks/metadata/sources/base.py: Code:
def id_from_url(self, url): ''' Parse a URL and return a tuple of the form: (identifier_type, identifier_value). If the URL does not match the pattern for the metadata source, return None. ''' return None Code:
def id_from_url(self, url): match = re.match(self.BASE_URL + ".*" + self.BOOK_PATH + "(.*)?", url) if match: return ('kobo', match.groups(0)[0]) return None The attached version of gui2/metadata/basic_widgets.py has the code to handle this. It tries the identifier rules and then tries the metadata source plugins. It stops after the first identifier found. If none is found, it goes through the current rules. I have been using this for a while and it works well for me. The question is, does anyone have a problem with this approach? Or a suggestion of a better way to do this. And a better name of the method than "id_from_url"? Does this need to return multiple identifiers? |
10-28-2018, 06:49 AM | #2 |
creator of calibre
Posts: 43,839
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
seems fine to me, I dont see a need for it to return multiple identifiers.
|
10-28-2018, 07:31 AM | #3 |
Grand Sorcerer
Posts: 6,227
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
@davidfor, is this related to the case when, in bulk metadata download, if amazon and goodreads data are not merged, you get the amazon information but not the goodreads id, that you have to add later manually? Should it be possible to automate adding the goodreads id even if data come from amazon?
|
10-28-2018, 07:59 AM | #4 | ||
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Quote:
|
||
10-28-2018, 08:04 AM | #5 |
Grand Sorcerer
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
I tend to agree, but, needed to check. I'll probably check it in tomorrow night. I'm fiddling with the KoboTouch driver, which is what prompted me to check-in some other changes that have been hanging around.
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problems with pasting content on Sigil | davidchavez | Sigil | 21 | 07-24-2018 10:07 AM |
Text pasting as HTML? | ChipSuey | Editor | 8 | 02-28-2017 08:11 AM |
Pasting from grid columns very slow | MikeMJ | Calibre | 3 | 02-10-2015 10:59 PM |
Content copying and pasting text | beppe | Amazon Kindle | 12 | 07-24-2011 03:09 PM |
Pasting creates DIVS but not Paragraphs? | bitterbug | Sigil | 4 | 10-22-2010 12:42 AM |