Compare commits
No commits in common. "efdb203e2c3eefeceaf9baa9b57502e7bf3a74d5" and "dce5236b1f23c048b10f8532cfaef2321f512789" have entirely different histories.
efdb203e2c
...
dce5236b1f
@ -1,87 +0,0 @@
|
|||||||
import configparser
|
|
||||||
from requests import get
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
|
|
||||||
class AudibleBook(object):
|
|
||||||
|
|
||||||
def __init__(self, filePath, activationBytes):
|
|
||||||
self.filePath = filePath
|
|
||||||
self.activationBytes = activationBytes
|
|
||||||
self.metadata = json.loads(os.popen('ffprobe -i {} -show_format \
|
|
||||||
-print_format json'.format(filePath)).read())['format']['tags']
|
|
||||||
self.chapters = json.loads(os.popen('ffprobe -i {} -print_format json \
|
|
||||||
-show_chapters -loglevel error -sexagesimal'.format(self.filePath))
|
|
||||||
.read())['chapters']
|
|
||||||
|
|
||||||
# getPath() returns path to origonal audible file.
|
|
||||||
def getPath(self):
|
|
||||||
return self.filePath
|
|
||||||
|
|
||||||
# getMetadata() returns audio metadata for a given filepath.
|
|
||||||
def getMetadata(self):
|
|
||||||
return self.metadata
|
|
||||||
|
|
||||||
# getChapters() returns chapter metadata for a given filepath.
|
|
||||||
def getChapters(self):
|
|
||||||
return self.chapters
|
|
||||||
|
|
||||||
# getTitle() returns audiobook title.
|
|
||||||
def getTitle(self):
|
|
||||||
return self.getMetadata()['title']
|
|
||||||
|
|
||||||
def removeDRM(self, fileName):
|
|
||||||
os.system('ffmpeg -activation_bytes {} -i {} -c copy "{}.m4b"'
|
|
||||||
.format(self.activationBytes, self.filePath, fileName))
|
|
||||||
print('test')
|
|
||||||
|
|
||||||
# getHash() returns the hash of a given file.
|
|
||||||
def getHash(filePath):
|
|
||||||
with open(filePath, 'rb') as f:
|
|
||||||
f.seek(653)
|
|
||||||
data = f.read(20)
|
|
||||||
f.close()
|
|
||||||
return data.hex()
|
|
||||||
|
|
||||||
# getActivationBytes returns the bytes needed to decrypt a given hash.
|
|
||||||
def getActivationBytes(filehash):
|
|
||||||
headers = {'User-Agent': 'audible-converter'}
|
|
||||||
response = get('https://aax.api.j-kit.me/api/v2/activation/{}'.format(filehash),
|
|
||||||
headers=headers)
|
|
||||||
return json.loads(response.text)['activationBytes']
|
|
||||||
|
|
||||||
# createConfig() creates a config file.
|
|
||||||
def createConfig(configFilePath, filePath):
|
|
||||||
activationBytes = getActivationBytes(getHash(filePath))
|
|
||||||
f = open(configFilePath, 'w')
|
|
||||||
f.write('activationBytes={}'.format(activationBytes))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
configFilePath='./settings.conf'
|
|
||||||
audibleBookPath=sys.argv[1]
|
|
||||||
|
|
||||||
# Check if config file exists and creates one if needed.
|
|
||||||
if not os.path.exists(configFilePath):
|
|
||||||
print('Creating config file')
|
|
||||||
createConfig(configFilePath, audibleBookPath)
|
|
||||||
|
|
||||||
configString = '[Settings]\n' + open(configFilePath).read()
|
|
||||||
configParser = configparser.RawConfigParser()
|
|
||||||
configParser.read_string(configString)
|
|
||||||
activationBytes=configParser.get('Settings', 'activationBytes')
|
|
||||||
|
|
||||||
book = AudibleBook(audibleBookPath, activationBytes)
|
|
||||||
|
|
||||||
for c in book.getChapters():
|
|
||||||
start=c['start']
|
|
||||||
end=c['end']
|
|
||||||
title=c['tags']['title']
|
|
||||||
print(start, end, title)
|
|
||||||
#os.system('ffmpeg -i {} -acodec copy -vcodec copy -ss {} -t {} OUTFILE-{}.m4a'.format(filePath, start, end, title))
|
|
||||||
|
|
||||||
|
|
||||||
print(book.getTitle())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cleanString() {
|
|
||||||
tr -d '"'
|
|
||||||
}
|
|
||||||
|
|
||||||
# getHash returns the hash of a given file.
|
# getHash returns the hash of a given file.
|
||||||
function getHash() {
|
function getHash() {
|
||||||
echo $(xxd -p -l20 -s 653 ${1})
|
echo $(xxd -p -l20 -s 653 ${1})
|
||||||
@ -12,7 +8,7 @@ function getHash() {
|
|||||||
# getActivationBytes returns the bytes needed to decrypt a given hash.
|
# getActivationBytes returns the bytes needed to decrypt a given hash.
|
||||||
function getActivationBytes() {
|
function getActivationBytes() {
|
||||||
json=$(curl -A 'audible-converter' https://aax.api.j-kit.me/api/v2/activation/${1})
|
json=$(curl -A 'audible-converter' https://aax.api.j-kit.me/api/v2/activation/${1})
|
||||||
echo $(echo $json | jq '.activationBytes' | cleanString)
|
echo $(echo $json | jq '.activationBytes' | tr -d '"')
|
||||||
}
|
}
|
||||||
|
|
||||||
# createConfig creates a config file.
|
# createConfig creates a config file.
|
||||||
@ -31,11 +27,11 @@ function checkAudibleFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeDRM() {
|
function removeDRM() {
|
||||||
ffmpeg -activation_bytes ${2} -i ${1} -c copy "${3}.m4b"
|
ffmpeg -activation_bytes ${2} -i ${1} -c copy "$(basename ${1} | cut -f 1 -d '.').m4b"
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChapterJSON() {
|
function getChapterJSON() {
|
||||||
echo $(ffprobe -i ${1} -print_format json -show_chapters -loglevel error -sexagesimal | jq '.chapters')
|
echo $(ffprobe -i ${1} -print_format json -show_chapters -loglevel error -sexagesimal)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMetadataJSON() {
|
function getMetadataJSON() {
|
||||||
@ -43,11 +39,7 @@ function getMetadataJSON() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTitle() {
|
function getTitle() {
|
||||||
echo $(echo ${1} | jq '.title' | cleanString)
|
echo $(echo ${1} | jq '.title')
|
||||||
}
|
|
||||||
|
|
||||||
function fileSafe() {
|
|
||||||
sed -e 's/[^A-Za-z0-9._-]/-/g' | tr '[:upper:]' '[:lower:]' | sed -e 's/--/-/g'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsFile='./settings.conf'
|
settingsFile='./settings.conf'
|
||||||
@ -65,18 +57,5 @@ fi
|
|||||||
. $settingsFile
|
. $settingsFile
|
||||||
|
|
||||||
metadataJSON=$(getMetadataJSON $audibleFile)
|
metadataJSON=$(getMetadataJSON $audibleFile)
|
||||||
chapterJSON=$(getChapterJSON $audibleFile)
|
json=$(getMetadataJSON $audibleFile)
|
||||||
name=$(getTitle "${metadataJSON}" | fileSafe)
|
removeDRM $audibleFile $activationBytes
|
||||||
|
|
||||||
if [ ! -f "${name}.m4b" ]; then
|
|
||||||
removeDRM $audibleFile $activationBytes $name
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p $name
|
|
||||||
|
|
||||||
data=$(echo "${chapterJSON}" | jq '.[] | "\(.start),\(.end),\(.tags.title)"')
|
|
||||||
echo $data
|
|
||||||
IFS=' ' read -r -a array <<< "$data"
|
|
||||||
|
|
||||||
|
|
||||||
echo $(echo "${chapterJSON}" | jq '.[] | .start,.end,.tags.title')
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user