v0.0.7: PDF bugfixes, more PDF logging, MacOS locale bugfix

This commit is contained in:
Florian Bach 2021-10-01 14:32:46 +02:00
parent ac655fdd9d
commit e395d373a5
5 changed files with 25 additions and 12 deletions

View file

@ -1,4 +1,4 @@
# Calibre ACSM plugin
# Calibre ACSM Input plugin
This is a Calibre plugin that allows you to turn ACSM files into EPUB or PDF files without the need for ADE.
It is a full Python reimplementation of libgourou by Grégory Soutadé (http://indefero.soutade.fr/p/libgourou/).
@ -18,7 +18,7 @@ IMPORTANT:
- I would suggest creating a new dummy AdobeID to use for Calibre so just in case Adobe detects this and bans you, you don't lose your main AdobeID.
- Combined with that I suggest importing the DER file into the DeDRM plugin to make sure that losing your AdobeID doesn't also mean you'll lose access to all your eBooks.
- Support for PDFs might be unreliable. You will need to apply pull request #1689 (including my additional bugfix in the comments of that PR) to the DeDRM plugin in order to remove the DRM from PDF files. If you still encounter an issue with a PDF file created by this tool even with these bugfixes, please report a bug and attach the corrupted PDF (in this repository, not in the DeDRM one).
- Support for PDFs might be unreliable. You will need to apply pull request #1689 (including my additional bugfix in the comments of that PR) to the DeDRM plugin in order to remove the DRM from PDF files. If you still encounter an issue with a PDF file created by this tool even with these bugfixes, please report a bug (in this repository, not in the DeDRM one) and attach the corrupted PDF.
- This software is not approved by Adobe. I am not responsible if Adobe detects that you're using nonstandard software and bans your account. Do not complain to me if Adobe bans your main ADE account - you have been warned.

View file

@ -11,10 +11,11 @@
# v0.0.4: Manually execute DeDRM (if installed) after converting ACSM to EPUB.
# v0.0.5: Bugfix: DeDRM plugin was also executed if it's installed but disabled.
# v0.0.6: First PDF support, allow importing previously exported activation data.
# v0.0.7: More PDF logging, PDF reading in latin-1, MacOS locale bugfix
from calibre.customize import FileTypePlugin # type: ignore
__version__ = '0.0.6'
__version__ = '0.0.7'
PLUGIN_NAME = "DeACSM"
PLUGIN_VERSION_TUPLE = tuple([int(x) for x in __version__.split(".")])
@ -29,7 +30,7 @@ from lxml import etree
class DeACSM(FileTypePlugin):
name = PLUGIN_NAME
description = "Takes an Adobe ACSM file and converts that into a useable EPUB file. Python reimplementation of libgourou by Grégory Soutadé"
description = "ACSM Input Plugin - Takes an Adobe ACSM file and converts that into a useable EPUB or PDF file. Python reimplementation of libgourou by Grégory Soutadé"
supported_platforms = ['linux', 'osx', 'windows']
author = "Leseratte10"
version = PLUGIN_VERSION_TUPLE
@ -202,6 +203,7 @@ class DeACSM(FileTypePlugin):
return None
# Download eBook:
print("{0} v{1}: Loading book from {2}".format(PLUGIN_NAME, PLUGIN_VERSION, download_url))
book_content = sendHTTPRequest(download_url)
filetype = ".bin"
@ -244,7 +246,7 @@ class DeACSM(FileTypePlugin):
elif filetype == ".pdf":
print("{0} v{1}: Downloaded PDF, adding encryption config ...".format(PLUGIN_NAME, PLUGIN_VERSION))
pdf_tmp_file = self.temporary_file(filetype).name
patch_drm_into_pdf(filename, prepare_string_from_xml(rights_xml_str, author, title), pdf_tmp_file)
patch_drm_into_pdf(filename, prepare_string_from_xml(rights_xml_str, title, author), pdf_tmp_file)
print("{0} v{1}: File successfully fulfilled ...".format(PLUGIN_NAME, PLUGIN_VERSION))
return pdf_tmp_file
else:

View file

@ -180,7 +180,7 @@ class ConfigWidget(QWidget):
output_salt.close()
except:
err = traceback.print_exc()
err = traceback.format_exc()
return error_dialog(None, "Import failed", "Can't write file", show=True, det_msg=err, show_copy_button=False)
# update display

View file

@ -46,7 +46,13 @@ def createDeviceFile(hobbes: str, randomSerial: bool):
atr_ver3 = etree.SubElement(root, etree.QName(NSMAP["adept"], "version"))
atr_ver3.set("name", "clientLocale")
atr_ver3.set("value", locale.getdefaultlocale()[0])
language = locale.getdefaultlocale()[0]
if language is None or language == "":
# Can sometimes happen on MacOS with default English language
language = "en_US"
atr_ver3.set("value", language)
etree.SubElement(root, etree.QName(NSMAP["adept"], "fingerprint")).text = fingerprint

View file

@ -22,7 +22,7 @@ def read_reverse_order(file_name):
# If the read byte is new line character then it means one line is read
if new_byte == b'\n':
# Fetch the line from buffer and yield it
yield buffer.decode()[::-1]
yield buffer.decode("latin-1")[::-1]
# Reinitialize the byte array to save next line
buffer = bytearray()
else:
@ -31,7 +31,7 @@ def read_reverse_order(file_name):
# As file is read completely, if there is still data in buffer, then its the first line.
if len(buffer) > 0:
# Yield the first line too
yield buffer.decode()[::-1]
yield buffer.decode("latin-1")[::-1]
def deflate_and_base64_encode( string_val ):
zlibbed_str = zlib.compress( string_val )
@ -53,15 +53,18 @@ def patch_drm_into_pdf(filename_in, drm_string, filename_out):
ORIG_FILE = filename_in
trailer = ""
trailer_idx = 0
print("DRM data is %s" % (drm_string))
for line in read_reverse_order(ORIG_FILE):
trailer_idx += 1
trailer = line + "\n" + trailer
print("DEBUG: pdfdata[%d] = %s" % (trailer_idx, line))
if (trailer_idx == 20):
print("trailer_idx is very large (%d). Usually it's 10 or less. File might be corrupted." % trailer_idx)
if (line == "trailer"):
if (trailer_idx > 20):
print("trailer_idx is very large (%d). Usually it's 10 or less. File might be corrupted." % trailer_idx)
print("Found trailer at idx %d" % (trailer_idx))
break
r_encrypt_offs1 = 0
@ -137,6 +140,8 @@ def patch_drm_into_pdf(filename_in, drm_string, filename_out):
additional_data += "\r" + "startxref\r" + str(ptr) + "\r" + "%%EOF"
print("Appending DRM data: %s" % (additional_data))
inp = open(ORIG_FILE, "rb")