From 5acf9a8d0bf344fc18c512f2a7f7dd861e645224 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Sat, 8 Jun 2013 23:11:55 -0500 Subject: [PATCH] Add 'Download as New Book?' dialog after 'Change Story URL?', fix author URLs when new author. --- calibre-plugin/ffdl_plugin.py | 43 +++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index 40806d29..d77207ac 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -862,11 +862,25 @@ class FanFictionDownLoaderPlugin(InterfaceAction): "

Click 'Yes' to %se book with new URL.

"%updat+ "

Click 'No' to skip %sing this book.

"%updat, show_copy_button=False): - book['comment'] = "Update declined by user due to differing story URL(%s)"%liburl - book['good']=False - book['icon']='rotate-right.png' - book['status'] = 'Different URL' - return + if question_dialog(self.gui, 'Download as New Book?', + '

Download as New Book?

'+ + '

%s by %s is already in your library with a different source URL.

'% + (mi.title,', '.join(mi.author))+ + '

You chose not to update the existing book. Do you want to add a new book for this URL?

'+ + '

New URL: %(newurl)s

'% + {'newurl':book['url']}+ + "

Click 'Yes' to a new book with new URL.

"+ + "

Click 'No' to skip URL.

", + show_copy_button=False): + book_id = None + mi = None + book['calibre_id'] = None + else: + book['comment'] = "Update declined by user due to differing story URL(%s)"%liburl + book['good']=False + book['icon']='rotate-right.png' + book['status'] = 'Different URL' + return if book_id != None and collision != ADDNEW: if collision in (CALIBREONLY): @@ -1309,15 +1323,6 @@ class FanFictionDownLoaderPlugin(InterfaceAction): except: print("Failed to set_cover, skipping") - # set author link if found. All current adapters have authorUrl, except anonymous on AO3. - if 'authorUrl' in book['all_metadata']: - authurls = book['all_metadata']['authorUrl'].split(", ") - for i, auth in enumerate(book['author']): - #print("===Update author url for %s to %s"%(auth,authurls[i])) - autid=db.get_author_id(auth) - db.set_link_field_for_author(autid, unicode(authurls[i]), - commit=False, notify=False) - # implement 'newonly' flags here by setting to the current # value again. if not book['added']: @@ -1420,6 +1425,16 @@ class FanFictionDownLoaderPlugin(InterfaceAction): db.set_custom(book_id, ", ".join(vallist), label=label, commit=False) + # set author link if found. All current adapters have authorUrl, except anonymous on AO3. + # Moved down so author's already in the DB. + if 'authorUrl' in book['all_metadata']: + authurls = book['all_metadata']['authorUrl'].split(", ") + for i, auth in enumerate(book['author']): + #print("===Update author url for %s to %s"%(auth,authurls[i])) + autid=db.get_author_id(auth) + db.set_link_field_for_author(autid, unicode(authurls[i]), + commit=False, notify=False) + db.commit() if 'Generate Cover' in self.gui.iactions and (book['added'] or not prefs['gcnewonly']):