54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import configparser
|
|
import os
|
|
import json
|
|
import sys
|
|
|
|
class AudibleBook(object):
|
|
|
|
def __init__(self, filePath):
|
|
self.filePath = filePath
|
|
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']
|
|
|
|
# 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']
|
|
|
|
# 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()
|
|
|
|
configString = '[Settings]\n' + open('./settings.conf').read()
|
|
configParser = configparser.RawConfigParser()
|
|
configParser.read_string(configString)
|
|
book = AudibleBook(sys.argv[1])
|
|
|
|
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())
|
|
print(configParser.get('Settings', 'activationBytes'))
|
|
|
|
|
|
print(getHash(sys.argv[1]))
|