mirror of
https://github.com/Leseratte10/acsm-calibre-plugin.git
synced 2024-12-23 01:34:36 +06:00
Actually fix loans without deviceID
This commit is contained in:
parent
2779334e4a
commit
dd104665bb
@ -38,7 +38,8 @@
|
|||||||
# fulfillment notifications, allow authorizing an eReader through USB (experimental),
|
# fulfillment notifications, allow authorizing an eReader through USB (experimental),
|
||||||
# drop dependencies python-cryptography, python-rsa and python-pyasn1.
|
# drop dependencies python-cryptography, python-rsa and python-pyasn1.
|
||||||
# add a ton of testing code, try to prevent AV false-positives,
|
# 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_NAME = "DeACSM"
|
||||||
PLUGIN_VERSION_TUPLE = (0, 0, 15)
|
PLUGIN_VERSION_TUPLE = (0, 0, 15)
|
||||||
|
@ -1427,11 +1427,15 @@ class RentedBooksDialog(QDialog):
|
|||||||
print("Deleting book entry %s (ID %s)" % (self.listy.currentItem().text(), userdata))
|
print("Deleting book entry %s (ID %s)" % (self.listy.currentItem().text(), userdata))
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
for book in self.parent.deacsmprefs["list_of_rented_books"]:
|
done = False
|
||||||
if book["loanID"] == userdata:
|
while not done:
|
||||||
self.parent.deacsmprefs["list_of_rented_books"].remove(book)
|
done = True
|
||||||
success = True
|
for book in self.parent.deacsmprefs["list_of_rented_books"]:
|
||||||
break
|
if book["loanID"] == userdata:
|
||||||
|
done = False
|
||||||
|
self.parent.deacsmprefs["list_of_rented_books"].remove(book)
|
||||||
|
success = True
|
||||||
|
break
|
||||||
|
|
||||||
self.populate_list()
|
self.populate_list()
|
||||||
|
|
||||||
|
@ -429,6 +429,10 @@ def fulfill(acsm_file, do_notify = False):
|
|||||||
if do_notify:
|
if do_notify:
|
||||||
print("Notifying server ...")
|
print("Notifying server ...")
|
||||||
success, response = performFulfillmentNotification(adobe_fulfill_response)
|
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:
|
else:
|
||||||
print("Not notifying any server since that was disabled.")
|
print("Not notifying any server since that was disabled.")
|
||||||
else:
|
else:
|
||||||
@ -474,25 +478,27 @@ def updateLoanReturnData(fulfillmentResultToken):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
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
|
operatorURL = loanToken.find("./%s" % (adNS("operatorURL"))).text
|
||||||
except:
|
except:
|
||||||
print("Loan ID error")
|
print("OperatorURL missing")
|
||||||
return False
|
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
|
book_name = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("metadata"), dcNS("title"))).text
|
||||||
|
|
||||||
userUUID = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("user"))).text
|
userUUID = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("user"))).text
|
||||||
try:
|
try:
|
||||||
deviceUUID = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("device"))).text
|
deviceUUID = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("device"))).text
|
||||||
except:
|
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")))
|
permissions = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("permissions")))
|
||||||
|
|
||||||
display = permissions.findall("./%s" % (adNS("display")))[0]
|
display = permissions.findall("./%s" % (adNS("display")))[0]
|
||||||
@ -530,7 +536,7 @@ def updateLoanReturnData(fulfillmentResultToken):
|
|||||||
"book_name": book_name,
|
"book_name": book_name,
|
||||||
"user": userUUID,
|
"user": userUUID,
|
||||||
"device": deviceUUID,
|
"device": deviceUUID,
|
||||||
"loanID": loanid,
|
"loanID": loanID,
|
||||||
"operatorURL": operatorURL,
|
"operatorURL": operatorURL,
|
||||||
"validUntil": dsp_until
|
"validUntil": dsp_until
|
||||||
})
|
})
|
||||||
@ -544,17 +550,12 @@ def tryReturnBook(bookData):
|
|||||||
try:
|
try:
|
||||||
user = bookData["user"]
|
user = bookData["user"]
|
||||||
loanID = bookData["loanID"]
|
loanID = bookData["loanID"]
|
||||||
|
device = bookData["device"]
|
||||||
operatorURL = bookData["operatorURL"]
|
operatorURL = bookData["operatorURL"]
|
||||||
device = None
|
|
||||||
except:
|
except:
|
||||||
print("Invalid book data!")
|
print("Invalid book data!")
|
||||||
return False, "Invalid book data"
|
return False, "Invalid book data"
|
||||||
|
|
||||||
try:
|
|
||||||
device = bookData["device"]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
req_data = "<?xml version=\"1.0\"?>"
|
req_data = "<?xml version=\"1.0\"?>"
|
||||||
req_data += "<adept:loanReturn xmlns:adept=\"http://ns.adobe.com/adept\">"
|
req_data += "<adept:loanReturn xmlns:adept=\"http://ns.adobe.com/adept\">"
|
||||||
@ -589,7 +590,10 @@ def tryReturnBook(bookData):
|
|||||||
return False, retval
|
return False, retval
|
||||||
elif "<envelope" in retval:
|
elif "<envelope" in retval:
|
||||||
print("Loan return successful")
|
print("Loan return successful")
|
||||||
return performFulfillmentNotification(etree.fromstring(retval), True, user=user, device=device)
|
bl, txt = performFulfillmentNotification(etree.fromstring(retval), True, user=user, device=device)
|
||||||
|
if not bl:
|
||||||
|
print("Error while notifying of book return. Book's probably still been returned properly.")
|
||||||
|
return True, retval
|
||||||
else:
|
else:
|
||||||
print("Invalid loan return response: %s" % (retval))
|
print("Invalid loan return response: %s" % (retval))
|
||||||
return False, retval
|
return False, retval
|
||||||
@ -661,15 +665,17 @@ def performFulfillmentNotification(fulfillmentResultToken, forceOptional = False
|
|||||||
device = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("device"))).text
|
device = fulfillmentResultToken.find("./%s/%s/%s/%s" % (adNS("fulfillmentResult"), adNS("resourceItemInfo"), adNS("licenseToken"), adNS("device"))).text
|
||||||
except:
|
except:
|
||||||
print("Missing deviceID for loan metadata ... why?")
|
print("Missing deviceID for loan metadata ... why?")
|
||||||
# I have no idea if this behaviour is correct, need to do more testing on loaned books without deviceID
|
print("Reading from device.xml instead.")
|
||||||
|
# Lets try to read this from the activation ...
|
||||||
|
activationxml = etree.parse(get_activation_xml_path())
|
||||||
|
device = activationxml.find("./%s/%s" % (adNS("activationToken"), adNS("device"))).text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
full_text = "<adept:notification xmlns:adept=\"http://ns.adobe.com/adept\">"
|
full_text = "<adept:notification xmlns:adept=\"http://ns.adobe.com/adept\">"
|
||||||
full_text += "<adept:user>%s</adept:user>" % user
|
full_text += "<adept:user>%s</adept:user>" % user
|
||||||
|
full_text += "<adept:device>%s</adept:device>" % device
|
||||||
if device is not None:
|
|
||||||
full_text += "<adept:device>%s</adept:device>" % device
|
|
||||||
|
|
||||||
|
|
||||||
# ADE 4.0 apparently changed the order of these two elements.
|
# ADE 4.0 apparently changed the order of these two elements.
|
||||||
|
Loading…
Reference in New Issue
Block a user