acsm to pdf is working, removed aax for now
This commit is contained in:
parent
98faaa4579
commit
8fd6244db8
7 changed files with 98 additions and 91 deletions
|
@ -48,4 +48,4 @@ def handle_aax(aax_path):
|
|||
'-loglevel', 'error'
|
||||
])
|
||||
|
||||
click.secho(f'DRM-free M4B file created:\n{aax_path.with_suffix(".m4b")}', fg='green')
|
||||
click.secho(f'DRM-free M4B file created:\n{m4b_path}', fg='green')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from xdg import xdg_config_home
|
||||
import click, sys, shutil, subprocess
|
||||
import click, sys, shutil, subprocess, magic
|
||||
from utils import run
|
||||
|
||||
def handle_acsm(acsm_path):
|
||||
|
@ -24,7 +24,7 @@ def handle_acsm(acsm_path):
|
|||
|
||||
run(
|
||||
[
|
||||
'adept-register',
|
||||
'adept_activate',
|
||||
'-u', email,
|
||||
'-O', str(adobe_dir)
|
||||
],
|
||||
|
@ -35,7 +35,7 @@ def handle_acsm(acsm_path):
|
|||
click.echo('Downloading the book from Adobe...')
|
||||
|
||||
run([
|
||||
'adept-download',
|
||||
'acsmdownloader',
|
||||
'-d', str(adobe_dir.joinpath('device.xml')),
|
||||
'-a', str(adobe_dir.joinpath('activation.xml')),
|
||||
'-k', str(adobe_dir.joinpath('devicesalt')),
|
||||
|
@ -45,11 +45,11 @@ def handle_acsm(acsm_path):
|
|||
|
||||
drm_path_type = magic.from_file(str(drm_path), mime=True)
|
||||
if drm_path_type == 'application/epub+zip':
|
||||
file_type = 'EPUB'
|
||||
file_type = 'epub'
|
||||
elif drm_path_type == 'application/pdf':
|
||||
file_type = 'PDF'
|
||||
file_type = 'pdf'
|
||||
else:
|
||||
click.echo(f'Error: Received file of media type {drm_path_type}.', err=True)
|
||||
click.echo(f'Error: Received file of media type {drm_path_type} from Adobe\' servers.', err=True)
|
||||
click.echo('Only the following ACSM conversions are currently supported:', err=True)
|
||||
click.echo(' * ACSM -> EPUB', err=True)
|
||||
click.echo(' * ACSM -> PDF', err=True)
|
||||
|
@ -57,20 +57,21 @@ def handle_acsm(acsm_path):
|
|||
click.echo(f' https://github.com/BentonEdmondson/knock/issues/new?title=Support%20{drm_path_type}%20Files&labels=enhancement', err=True)
|
||||
sys.exit(1)
|
||||
|
||||
output_file = acsm_path.with_suffix(file_type)
|
||||
if output_file.exists():
|
||||
click.echo(f"Error: {output_file} must be moved out of the way or deleted.", err=True)
|
||||
output_path = acsm_path.with_suffix('.' + file_type)
|
||||
if output_path.exists():
|
||||
drm_path.unlink()
|
||||
click.echo(f"Error: {output_path} must be moved out of the way or deleted.", err=True)
|
||||
sys.exit(1)
|
||||
|
||||
click.echo('Decrypting the file...')
|
||||
|
||||
run([
|
||||
'inept-' + file_type.lower(),
|
||||
'rmdrm-' + file_type,
|
||||
str(adobe_dir.joinpath('activation.xml')),
|
||||
str(drm_path),
|
||||
str(output_file)
|
||||
str(output_path)
|
||||
])
|
||||
|
||||
drm_path.unlink()
|
||||
|
||||
click.secho(f'DRM-free {file_type} file created:\n{output_file}', fg='green')
|
||||
click.secho(f'DRM-free {file_type.upper()} file created:\n{output_path}', fg='green')
|
|
@ -38,3 +38,8 @@ def close_fake_terminal(exit_code: int, cleanser = lambda: None):
|
|||
cleanser()
|
||||
click.echo(f'Error: Command returned error code {exit_code}.', err=True)
|
||||
sys.exit(1)
|
||||
|
||||
def verify_absence_of(file_path):
|
||||
if m4b_path.exists():
|
||||
click.echo(f"Error: {file_path} must be moved out of the way or deleted.", err=True)
|
||||
sys.exit(1)
|
Loading…
Add table
Add a link
Reference in a new issue