35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
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
|
|
|
|
filePath=''
|
|
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.getMetadata())
|