diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index 400fdc3..c4e7818 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -38,7 +38,8 @@ # fulfillment notifications, allow authorizing an eReader through USB (experimental), # drop dependencies python-cryptography, python-rsa and python-pyasn1. # add a ton of testing code, try to prevent AV false-positives, -# experimental support for Python2 / Calibre < 5. +# experimental support for Python2 / Calibre < 5, +# fix broken URLs with missing protocol, fix loan data for loans without device ID. PLUGIN_NAME = "DeACSM" PLUGIN_VERSION_TUPLE = (0, 0, 15) diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index afaed60..45a87a6 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -1427,11 +1427,15 @@ class RentedBooksDialog(QDialog): print("Deleting book entry %s (ID %s)" % (self.listy.currentItem().text(), userdata)) success = False - for book in self.parent.deacsmprefs["list_of_rented_books"]: - if book["loanID"] == userdata: - self.parent.deacsmprefs["list_of_rented_books"].remove(book) - success = True - break + done = False + while not done: + done = True + for book in self.parent.deacsmprefs["list_of_rented_books"]: + if book["loanID"] == userdata: + done = False + self.parent.deacsmprefs["list_of_rented_books"].remove(book) + success = True + break self.populate_list() diff --git a/calibre-plugin/libadobeFulfill.py b/calibre-plugin/libadobeFulfill.py index 448f6a6..0ff2c0b 100644 --- a/calibre-plugin/libadobeFulfill.py +++ b/calibre-plugin/libadobeFulfill.py @@ -429,6 +429,10 @@ def fulfill(acsm_file, do_notify = False): if do_notify: print("Notifying server ...") success, response = performFulfillmentNotification(adobe_fulfill_response) + if not success: + print("Some errors occurred during notify: ") + print(response) + print("The book was probably still downloaded correctly.") else: print("Not notifying any server since that was disabled.") else: @@ -474,15 +478,16 @@ def updateLoanReturnData(fulfillmentResultToken): return False try: - loanID = loanToken.findall("./%s" % (adNS("loan")))[0].text - if (loanID is None): - print("Loan ID not found") - return False - operatorURL = loanToken.find("./%s" % (adNS("operatorURL"))).text except: - print("Loan ID error") + print("OperatorURL missing") return False + + try: + loanID = None + loanID = loanToken.findall("./%s" % (adNS("loan")))[0].text + except: + pass book_name = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("metadata"), dcNS("title"))).text @@ -490,9 +495,10 @@ def updateLoanReturnData(fulfillmentResultToken): try: deviceUUID = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("device"))).text except: - deviceUUID = None + activationxml = etree.parse(get_activation_xml_path()) + deviceUUID = activationxml.find("./%s/%s" % (adNS("activationToken"), adNS("device"))).text + - loanid = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("fulfillment"))).text permissions = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("permissions"))) display = permissions.findall("./%s" % (adNS("display")))[0] @@ -530,7 +536,7 @@ def updateLoanReturnData(fulfillmentResultToken): "book_name": book_name, "user": userUUID, "device": deviceUUID, - "loanID": loanid, + "loanID": loanID, "operatorURL": operatorURL, "validUntil": dsp_until }) @@ -544,17 +550,12 @@ def tryReturnBook(bookData): try: user = bookData["user"] loanID = bookData["loanID"] + device = bookData["device"] operatorURL = bookData["operatorURL"] - device = None except: print("Invalid book data!") return False, "Invalid book data" - try: - device = bookData["device"] - except: - pass - req_data = "" req_data += "" @@ -589,7 +590,10 @@ def tryReturnBook(bookData): return False, retval elif "" full_text += "%s" % user - - if device is not None: - full_text += "%s" % device + full_text += "%s" % device # ADE 4.0 apparently changed the order of these two elements.