using ffmpeg directly instead of AAXtoMP3

This commit is contained in:
benton 2021-11-06 14:29:50 -05:00
parent c5c8750587
commit 98faaa4579
4 changed files with 29 additions and 68 deletions

View file

@ -7,17 +7,14 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1631424389, "lastModified": 1633315458,
"narHash": "sha256-Nbs8FjqdJQwSBG8AjfOefqjbqVueO2o5HGz4/7YdQMM=", "narHash": "sha256-CKlsbD3I+CduADnEbPZV+LD4ByQ0RiDy39F3z6DKOQc=",
"owner": "BentonEdmondson", "type": "git",
"repo": "benpkgs", "url": "file:///home/benton/git/benpkgs"
"rev": "d6cd8eab1c25cb1186de283f28c9afed97c49dd2",
"type": "github"
}, },
"original": { "original": {
"owner": "BentonEdmondson", "type": "git",
"repo": "benpkgs", "url": "file:///home/benton/git/benpkgs"
"type": "github"
} }
}, },
"inept-epub": { "inept-epub": {
@ -40,33 +37,13 @@
"type": "github" "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1631381596, "lastModified": 1633080050,
"narHash": "sha256-Xk91RO0uMyul8fWo3RP7WqEP5bsKUVucJRgLZgascAo=", "narHash": "sha256-T9I2WnlUzAIL70dk9V1jqaYk3nypy/cMkWR19S47ZHc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f6e9e908ccbcabb365cb5434a4a38dd8c996fc72", "rev": "82155ff501c7622cb2336646bb62f7624261f6d7",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -80,7 +57,6 @@
"inputs": { "inputs": {
"benpkgs": "benpkgs", "benpkgs": "benpkgs",
"inept-epub": "inept-epub", "inept-epub": "inept-epub",
"libgourou-utils": "libgourou-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View file

@ -2,13 +2,10 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; 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.url = "github:BentonEdmondson/inept-epub";
inept-epub.inputs.nixpkgs.follows = "nixpkgs"; inept-epub.inputs.nixpkgs.follows = "nixpkgs";
benpkgs.url = "github:BentonEdmondson/benpkgs"; benpkgs.url = "git+file:///home/benton/git/benpkgs";
benpkgs.inputs.nixpkgs.follows = "nixpkgs"; benpkgs.inputs.nixpkgs.follows = "nixpkgs";
}; };
@ -18,19 +15,24 @@
inept-epub = flakes.inept-epub.defaultPackage.x86_64-linux; inept-epub = flakes.inept-epub.defaultPackage.x86_64-linux;
benpkgs = flakes.benpkgs.packages.x86_64-linux; benpkgs = flakes.benpkgs.packages.x86_64-linux;
in { in {
defaultPackage.x86_64-linux = nixpkgs.python3Packages.buildPythonApplication { defaultPackage.x86_64-linux = nixpkgs.python3Packages.buildPythonApplication rec {
pname = "knock"; pname = "knock";
version = "1.0.0-alpha"; version = "1.0.0-alpha";
src = self; src = ./.;
nativeBuildInputs = [ nixpkgs.makeWrapper ];
buildInputs = [
inept-epub
benpkgs.libgourou
nixpkgs.ffmpeg
];
propagatedBuildInputs = [ propagatedBuildInputs = [
nixpkgs.python3Packages.python_magic nixpkgs.python3Packages.python_magic
nixpkgs.python3Packages.xdg nixpkgs.python3Packages.xdg
nixpkgs.python3Packages.click nixpkgs.python3Packages.click
libgourou-utils
inept-epub
benpkgs.Audible benpkgs.Audible
benpkgs.AAXtoMP3
]; ];
format = "other"; format = "other";
@ -39,6 +41,7 @@
mkdir -p $out/bin $out/${nixpkgs.python3.sitePackages} mkdir -p $out/bin $out/${nixpkgs.python3.sitePackages}
cp lib/*.py $out/${nixpkgs.python3.sitePackages} cp lib/*.py $out/${nixpkgs.python3.sitePackages}
cp src/knock.py $out/bin/knock cp src/knock.py $out/bin/knock
wrapProgram $out/bin/knock --prefix PATH : ${nixpkgs.lib.makeBinPath buildInputs}
''; '';
meta = { meta = {

View file

@ -9,21 +9,11 @@ def handle_aax(aax_path):
authcode_path.parent.mkdir(parents=True, exist_ok=True) authcode_path.parent.mkdir(parents=True, exist_ok=True)
m4b_path = aax_path.with_suffix('.m4b') 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(): if m4b_path.exists():
click.echo(f"Error: {m4b_path} must be moved out of the way or deleted.", err=True) click.echo(f"Error: {m4b_path} must be moved out of the way or deleted.", err=True)
sys.exit(1) 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(): if not authcode_path.exists():
click.echo('This device does not have an Audible decryption key.') 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() authcode = authcode_path.read_text()
def cleanup():
cover_path.unlink(missing_ok=True)
chapters_path.unlink(missing_ok=True)
run([ run([
'AAXtoMP3', 'ffmpeg',
'--authcode', authcode, '-activation_bytes', authcode,
'-e:m4b', '-i', str(aax_path),
'-t', str(aax_path.parent), '-c', 'copy', str(m4b_path),
'-D', '.', '-loglevel', 'error'
'-F', str(aax_path.stem), ])
str(aax_path)
], cleanser=cleanup)
cleanup()
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{aax_path.with_suffix(".m4b")}', fg='green')

View file

@ -39,8 +39,8 @@ def main(path):
else: else:
click.echo(f'Error: Files of type {path_type} are not supported.\n', err=True) 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('Only the following file types are currently supported:', err=True)
click.echo(' * ACSM (Adobe)\n') click.echo(' * ACSM (Adobe)\n', err=True)
click.echo(' * AAX (Audible)\n') click.echo(' * AAX (Audible)\n', err=True)
click.echo('Please open a feature request at:', 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) click.echo(f' https://github.com/BentonEdmondson/knock/issues/new?title=Support%20{path_type}%20Files&labels=enhancement', err=True)
sys.exit(1) sys.exit(1)