Config generation
This commit is contained in:
parent
aa7c0fb106
commit
1aaa28d98d
@ -1,4 +1,5 @@
|
|||||||
import configparser
|
import configparser
|
||||||
|
from requests import get
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
@ -33,10 +34,34 @@ def getHash(filePath):
|
|||||||
f.close()
|
f.close()
|
||||||
return data.hex()
|
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 = configparser.RawConfigParser()
|
||||||
configParser.read_string(configString)
|
configParser.read_string(configString)
|
||||||
book = AudibleBook(sys.argv[1])
|
|
||||||
|
|
||||||
|
book = AudibleBook(audibleBookPath)
|
||||||
|
|
||||||
for c in book.getChapters():
|
for c in book.getChapters():
|
||||||
start=c['start']
|
start=c['start']
|
||||||
@ -50,4 +75,4 @@ print(book.getTitle())
|
|||||||
print(configParser.get('Settings', 'activationBytes'))
|
print(configParser.get('Settings', 'activationBytes'))
|
||||||
|
|
||||||
|
|
||||||
print(getHash(sys.argv[1]))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user