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 02-03-2017, 07:51 PM   #1
BeckyEbook
Member
BeckyEbook began at the beginning.
 
BeckyEbook's Avatar
 
Posts: 22
Karma: 10
Join Date: Jan 2017
Location: Poland
Device: Kindle (Key3, PW2, PW3), Nook (ST, GLP), Kobo Touch, Tolino Vision 2
Call fetch/download metadata from GUI plugin

During develop LubimyCzytac [Metadata Source Plugin] in config I allow to download number of pages and save to comment and/or as identifier "lcpages" (abbreviation from "LubimyCzytac pages").

Now I prepared auxiliary plugin named "LCpages" [GUI plugin].
Plugin move number of pages value from "lcpages" identifier to custom column (for example "#pages"). This option works as intended and rapidly.

Code:
Spoiler:

Code:
    def action_lcpages(self):
        if not self.is_library_selected:
            return error_dialog(self.gui, _('No selected book'),
                    _('No book selected for move LCpages to custom column'), show=True)
            return

        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0 :
            return error_dialog(self.gui, _('No selected book'),
                    _('No book selected for move LCpages to custom column'), show=True)
        book_ids = self.gui.library_view.get_selected_ids()

        any_valid, colforpages = self._get_column_validity(cfg.KEY_PAGES_CUSTOM_COLUMN)
        if not any_valid:
            if not question_dialog(self.gui, _('Configure plugin'), '<p>'+
                _('You must specify custom columns first. Do you want to configure this now?'),
                show_copy_button=False):
                return
            self.show_configuration()
            return

        col_pag = colforpages

        overwrite_pages = self._is_overwrite_pages(cfg.OVERWRITE_PAGES)

        self.dzialaj_lcpages(book_ids, col_pag, overwrite_pages)

    def dzialaj_lcpages(self, book_ids, col_pag, overwrite_pages):

        dbA = self.gui.current_db

        db = self.gui.current_db.new_api

        id_aux = {}

        for id in book_ids:

            identifiers = dbA.get_identifiers(id, index_is_id=True)
            id_aux[id] = identifiers.get('lcpages', None)

            mi = dbA.get_metadata(id, index_is_id=True, get_cover=False)
            pagesval = mi.get(col_pag)

            if id_aux[id]:
               if pagesval is not None:
                   if overwrite_pages:
                       db.set_field(col_pag, {id:id_aux[id]})
               else:
                   db.set_field(col_pag, {id:id_aux[id]})

               #Delete unnecessary identifier  lcpages
               deleteid = dbA.set_identifier(id,'lcpages', '')

               self.gui.iactions['Edit Metadata'].refresh_gui(book_ids, covers_changed=False)


I would like to start fetch/download metadata from LubimyCzytac source (by LubimyCzytac plugin of course),
and next run standard primary function (move value from identifier to custom column).

I can call "Edit Metadata" window:

Code:
    def edycjametadanych(self):
        from calibre.library import db
        from calibre.gui2.metadata.single import edit_metadata
        db = db()
        row_list = list(range(len(db.data)))
        edit_metadata(db, row_list, 0)
I can call "LubimyCzytac" config:
Code:
    def _configure_lubimyczytac(self):
        from calibre.customize.ui import initialized_plugins
        for plugin in initialized_plugins():
            if plugin.name == 'LubimyCzytac':

                if not plugin.is_customizable():
                    return info_dialog(self, _('Plugin not customizable'),
                        _('Plugin: %s does not need customization')%plugin.name, show=True)
                from calibre.customize import InterfaceActionBase
                if isinstance(plugin, InterfaceActionBase) and not getattr(plugin,
                        'actual_iaction_plugin_loaded', False):
                    return error_dialog(self, _('Must restart'),
                            _('You must restart calibre before you can'
                                ' configure the <b>%s</b> plugin')%plugin.name, show=True)
                plugin.do_user_config(self.parent())
Unfortunately, I can not call the fetch/download metadata by using LubimyCzytac plugin. I've read various threads about calling plugins from other plugins. I was trying for many hours - without success.

Is possible call fetch/download metadata from GUI plugin and next run other functions?
Code:
My plan:
1. Download metadata
2. Move value from ID to custom column
3. Delete ID
I would also like to check whether LubimyCzytac is enabled as a source of metadata.

Does my concept make sense?

PS. Count Pages plugin supporting LubimyCzytac (thx davidfor) is OK, but I want to test my own solution – only for speed fill custom column once downloaded value.
Attached Thumbnails
Click image for larger version

Name:	lcpages-customize.png
Views:	85
Size:	8.8 KB
ID:	154724   Click image for larger version

Name:	lcpages-principle-of-operation.png
Views:	76
Size:	291.7 KB
ID:	154725  
BeckyEbook is offline   Reply With Quote
Reply

Tags
call, lcpages, lubimyczytac, plugin, problem

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] Zotero Metadata Importer DaltonST Plugins 137 10-24-2017 07:12 PM
[GUI Plugin] Consolidate All Library Metadata (CALM) DaltonST Plugins 188 06-09-2017 12:20 PM
Regarding using metadata objects in identify method of metadata download plugin api aprekates Development 1 07-06-2014 04:35 AM
Getting custom metadata field in GUI plugin SauliusP. Development 7 02-11-2012 02:31 AM
[Metadata Download Plugin] Goodreads Metadata **Deprecated** kiwidude Plugins 30 04-23-2011 03:10 PM


All times are GMT -4. The time now is 05:57 PM.


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