the script is working correctly, still need to add logins

This commit is contained in:
benton 2021-07-18 19:29:12 -05:00
commit 7485a8e823
4 changed files with 169 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
result

97
flake.lock Normal file
View file

@ -0,0 +1,97 @@
{
"nodes": {
"inept-epub": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1626630204,
"narHash": "sha256-R56r2p7z1bNJS0ng+KeuV4zbWT4T46zc6YDqySB7jQc=",
"owner": "BentonEdmondson",
"repo": "inept-epub",
"rev": "45306cadf7fd7a04453a60b8c1e39bc06b0035ec",
"type": "github"
},
"original": {
"owner": "BentonEdmondson",
"repo": "inept-epub",
"type": "github"
}
},
"libgourou-utils": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1626630231,
"narHash": "sha256-nuhlaSwdTVZl3mHA3Pw8pdbr8bxBmRuNAEwNh/IU/NE=",
"owner": "BentonEdmondson",
"repo": "libgourou-utils",
"rev": "07637d6aab51fc1e188576fefcf9a7b6d77f6fc6",
"type": "github"
},
"original": {
"owner": "BentonEdmondson",
"repo": "libgourou-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1626464457,
"narHash": "sha256-u2PCh/+8vQSLwf0mPpKHKQ8hAPB3l4uNZR3r0TdK2Lg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c6c4a3d45ab200f17805d2d86a1ff1cc7ca2b186",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1626464457,
"narHash": "sha256-u2PCh/+8vQSLwf0mPpKHKQ8hAPB3l4uNZR3r0TdK2Lg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c6c4a3d45ab200f17805d2d86a1ff1cc7ca2b186",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1626464457,
"narHash": "sha256-u2PCh/+8vQSLwf0mPpKHKQ8hAPB3l4uNZR3r0TdK2Lg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c6c4a3d45ab200f17805d2d86a1ff1cc7ca2b186",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"inept-epub": "inept-epub",
"libgourou-utils": "libgourou-utils",
"nixpkgs": "nixpkgs_3"
}
}
},
"root": "root",
"version": 7
}

26
flake.nix Normal file
View file

@ -0,0 +1,26 @@
{
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
inputs.libgourou-utils.url = github:BentonEdmondson/libgourou-utils;
inputs.inept-epub.url = github:BentonEdmondson/inept-epub;
outputs = { self, ... }@flakes: let
nixpkgs = flakes.nixpkgs.legacyPackages.x86_64-linux;
libgourou-utils = flakes.libgourou-utils.defaultPackage.x86_64-linux;
inept-epub = flakes.inept-epub.defaultPackage.x86_64-linux;
in {
defaultPackage.x86_64-linux = nixpkgs.stdenv.mkDerivation {
pname = "knock";
version = "0.0.0";
src = self;
nativeBuildInputs = [ nixpkgs.makeWrapper ];
buildInputs = [ nixpkgs.python3 libgourou-utils inept-epub ];
installPhase = ''
mkdir -p $out/bin
chmod +x knock
cp knock $out/bin
wrapProgram $out/bin/knock --prefix PATH : ${nixpkgs.lib.makeBinPath [libgourou-utils inept-epub]}
'';
};
};
}

45
knock Normal file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env python3
import os
import argparse
from pathlib import Path
import subprocess
parser = argparse.ArgumentParser(description='Convert an ACSM file to a DRM-free ePub file')
parser.add_argument('acsm_file', metavar='file', type=str, help='the ACSM file to convert')
args = parser.parse_args()
# these are all Path objects: https://docs.python.org/3/library/pathlib.html
args.acsm_file = Path(args.acsm_file).expanduser()
args.drm_file = args.acsm_file.with_suffix('.drm.epub')
args.epub_file = args.acsm_file.with_suffix('.epub')
args.adobe_dir = Path('~/.config/knock').expanduser()
args.activation_file = args.adobe_dir.joinpath('activation.xml')
if not args.adobe_dir.exists():
raise Exception('This device is not registered')
print('Downloading the ACSM file from Adobe...')
subprocess.check_output([
'acsmdownloader',
'-d', str(args.adobe_dir.joinpath('device.xml')),
'-a', str(args.adobe_dir.joinpath('activation.xml')),
'-k', str(args.adobe_dir.joinpath('devicesalt')),
'-o', str(args.drm_file),
'-f', str(args.acsm_file)
])
print('Decrypting the file...')
subprocess.check_output([
'inept-epub',
str(args.activation_file),
str(args.drm_file),
str(args.epub_file)
])
args.drm_file.unlink()
print(f'\nThe DRM-free ePub file now exists at {str(args.epub_file)}!')
print(f'Once you make sure the ePub file is readable, you can delete {str(args.acsm_file)}.')