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

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 10-28-2018, 06:36 AM   #1
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 15,486
Karma: 25810738
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo,Aura H2O,Glo HD,Aura ONE,Clara HD,Forma;tolino epos
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
And override this in each metadata source plugin. For example, in the Kobo plugin, I have:
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
Which I just realised is in the latest version I released.

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?
Attached Files
File Type: py basic_widgets.py (67.6 KB, 9 views)
davidfor is offline   Reply With Quote
Old 10-28-2018, 07:49 AM   #2
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,615
Karma: 10209576
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
seems fine to me, I dont see a need for it to return multiple identifiers.
kovidgoyal is offline   Reply With Quote
Advert
Old 10-28-2018, 08:31 AM   #3
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 5,063
Karma: 5438918
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?
Terisa de morgan is offline   Reply With Quote
Old 10-28-2018, 08:59 AM   #4
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 15,486
Karma: 25810738
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo,Aura H2O,Glo HD,Aura ONE,Clara HD,Forma;tolino epos
Quote:
Originally Posted by Terisa de morgan View Post
@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?
That's close to the case. I rarely use bulk metadata download. So I use it for single books.
Quote:
Should it be possible to automate adding the goodreads id even if data come from amazon?
I don't know as I've never looked at that code. I don't think I'd trust it as if the Amazon and Goodreads data are not merged, then they might not be for the same book.
davidfor is offline   Reply With Quote
Old 10-28-2018, 09:04 AM   #5
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 15,486
Karma: 25810738
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo,Aura H2O,Glo HD,Aura ONE,Clara HD,Forma;tolino epos
Quote:
Originally Posted by kovidgoyal View Post
seems fine to me, I dont see a need for it to return multiple identifiers.
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.
davidfor is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with pasting content on Sigil davidchavez Sigil 21 07-24-2018 11:07 AM
Text pasting as HTML? ChipSuey Editor 8 02-28-2017 09:11 AM
Pasting from grid columns very slow MikeMJ Calibre 3 02-10-2015 11:59 PM
Content copying and pasting text beppe Amazon Kindle 12 07-24-2011 04:09 PM
Pasting creates DIVS but not Paragraphs? bitterbug Sigil 4 10-22-2010 01:42 AM


All times are GMT -4. The time now is 06:02 AM.


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