Config generation

This commit is contained in:
Christian Colglazier 2021-08-14 10:52:16 -04:00
parent aa7c0fb106
commit 1aaa28d98d

View File

@ -1,4 +1,5 @@
import configparser
from requests import get
import os
import json
import sys
@ -33,10 +34,34 @@ def getHash(filePath):
f.close()
return data.hex()
configString = '[Settings]\n' + open('./settings.conf').read()
# 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)
book = AudibleBook(sys.argv[1])
book = AudibleBook(audibleBookPath)
for c in book.getChapters():
start=c['start']
@ -50,4 +75,4 @@ print(book.getTitle())
print(configParser.get('Settings', 'activationBytes'))
print(getHash(sys.argv[1]))