From 98faaa4579563d686aadbb3c9b39f193c122c0ff Mon Sep 17 00:00:00 2001 From: benton Date: Sat, 6 Nov 2021 14:29:50 -0500 Subject: [PATCH] using ffmpeg directly instead of AAXtoMP3 --- flake.lock | 42 +++++++++--------------------------------- flake.nix | 21 ++++++++++++--------- lib/handle_aax.py | 30 ++++++------------------------ src/knock.py | 4 ++-- 4 files changed, 29 insertions(+), 68 deletions(-) diff --git a/flake.lock b/flake.lock index 757ebaf..c41a39e 100644 --- a/flake.lock +++ b/flake.lock @@ -7,17 +7,14 @@ ] }, "locked": { - "lastModified": 1631424389, - "narHash": "sha256-Nbs8FjqdJQwSBG8AjfOefqjbqVueO2o5HGz4/7YdQMM=", - "owner": "BentonEdmondson", - "repo": "benpkgs", - "rev": "d6cd8eab1c25cb1186de283f28c9afed97c49dd2", - "type": "github" + "lastModified": 1633315458, + "narHash": "sha256-CKlsbD3I+CduADnEbPZV+LD4ByQ0RiDy39F3z6DKOQc=", + "type": "git", + "url": "file:///home/benton/git/benpkgs" }, "original": { - "owner": "BentonEdmondson", - "repo": "benpkgs", - "type": "github" + "type": "git", + "url": "file:///home/benton/git/benpkgs" } }, "inept-epub": { @@ -40,33 +37,13 @@ "type": "github" } }, - "libgourou-utils": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1631412686, - "narHash": "sha256-u0v3qU+qckvZE/obCHjeyktcvH8Wyo4Zld9AxEI53bI=", - "owner": "BentonEdmondson", - "repo": "libgourou-utils", - "rev": "88d6dc2b549a28f886a15a7992890d60e576716d", - "type": "github" - }, - "original": { - "owner": "BentonEdmondson", - "repo": "libgourou-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1631381596, - "narHash": "sha256-Xk91RO0uMyul8fWo3RP7WqEP5bsKUVucJRgLZgascAo=", + "lastModified": 1633080050, + "narHash": "sha256-T9I2WnlUzAIL70dk9V1jqaYk3nypy/cMkWR19S47ZHc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f6e9e908ccbcabb365cb5434a4a38dd8c996fc72", + "rev": "82155ff501c7622cb2336646bb62f7624261f6d7", "type": "github" }, "original": { @@ -80,7 +57,6 @@ "inputs": { "benpkgs": "benpkgs", "inept-epub": "inept-epub", - "libgourou-utils": "libgourou-utils", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 1454830..32b316f 100644 --- a/flake.nix +++ b/flake.nix @@ -2,13 +2,10 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - libgourou-utils.url = "github:BentonEdmondson/libgourou-utils"; - libgourou-utils.inputs.nixpkgs.follows = "nixpkgs"; - inept-epub.url = "github:BentonEdmondson/inept-epub"; inept-epub.inputs.nixpkgs.follows = "nixpkgs"; - benpkgs.url = "github:BentonEdmondson/benpkgs"; + benpkgs.url = "git+file:///home/benton/git/benpkgs"; benpkgs.inputs.nixpkgs.follows = "nixpkgs"; }; @@ -18,19 +15,24 @@ inept-epub = flakes.inept-epub.defaultPackage.x86_64-linux; benpkgs = flakes.benpkgs.packages.x86_64-linux; in { - defaultPackage.x86_64-linux = nixpkgs.python3Packages.buildPythonApplication { + defaultPackage.x86_64-linux = nixpkgs.python3Packages.buildPythonApplication rec { pname = "knock"; version = "1.0.0-alpha"; - src = self; + src = ./.; + + nativeBuildInputs = [ nixpkgs.makeWrapper ]; + + buildInputs = [ + inept-epub + benpkgs.libgourou + nixpkgs.ffmpeg + ]; propagatedBuildInputs = [ nixpkgs.python3Packages.python_magic nixpkgs.python3Packages.xdg nixpkgs.python3Packages.click - libgourou-utils - inept-epub benpkgs.Audible - benpkgs.AAXtoMP3 ]; format = "other"; @@ -39,6 +41,7 @@ mkdir -p $out/bin $out/${nixpkgs.python3.sitePackages} cp lib/*.py $out/${nixpkgs.python3.sitePackages} cp src/knock.py $out/bin/knock + wrapProgram $out/bin/knock --prefix PATH : ${nixpkgs.lib.makeBinPath buildInputs} ''; meta = { diff --git a/lib/handle_aax.py b/lib/handle_aax.py index 3ea5a76..def7126 100644 --- a/lib/handle_aax.py +++ b/lib/handle_aax.py @@ -9,21 +9,11 @@ def handle_aax(aax_path): authcode_path.parent.mkdir(parents=True, exist_ok=True) m4b_path = aax_path.with_suffix('.m4b') - cover_path = aax_path.parent.joinpath('cover.jpg') - chapters_path = aax_path.with_suffix('.chapters.txt') if m4b_path.exists(): click.echo(f"Error: {m4b_path} must be moved out of the way or deleted.", err=True) sys.exit(1) - if cover_path.exists(): - click.echo(f"Error: {cover_path} must be moved out of the way or deleted.", err=True) - sys.exit(1) - - if chapters_path.exists(): - click.echo(f"Error: {chapters_path} must be moved out of the way or deleted.", err=True) - sys.exit(1) - if not authcode_path.exists(): click.echo('This device does not have an Audible decryption key.') @@ -50,20 +40,12 @@ def handle_aax(aax_path): authcode = authcode_path.read_text() - def cleanup(): - cover_path.unlink(missing_ok=True) - chapters_path.unlink(missing_ok=True) - run([ - 'AAXtoMP3', - '--authcode', authcode, - '-e:m4b', - '-t', str(aax_path.parent), - '-D', '.', - '-F', str(aax_path.stem), - str(aax_path) - ], cleanser=cleanup) - - cleanup() + 'ffmpeg', + '-activation_bytes', authcode, + '-i', str(aax_path), + '-c', 'copy', str(m4b_path), + '-loglevel', 'error' + ]) click.secho(f'DRM-free M4B file created:\n{aax_path.with_suffix(".m4b")}', fg='green') diff --git a/src/knock.py b/src/knock.py index 934b451..5f989d0 100755 --- a/src/knock.py +++ b/src/knock.py @@ -39,8 +39,8 @@ def main(path): else: click.echo(f'Error: Files of type {path_type} are not supported.\n', err=True) click.echo('Only the following file types are currently supported:', err=True) - click.echo(' * ACSM (Adobe)\n') - click.echo(' * AAX (Audible)\n') + click.echo(' * ACSM (Adobe)\n', err=True) + click.echo(' * AAX (Audible)\n', err=True) click.echo('Please open a feature request at:', err=True) click.echo(f' https://github.com/BentonEdmondson/knock/issues/new?title=Support%20{path_type}%20Files&labels=enhancement', err=True) sys.exit(1)