Started moving to a python script

This commit is contained in:
Christian Colglazier 2021-08-14 09:01:09 -04:00
parent 9f34fe4a8a
commit a35f9d05d4
2 changed files with 53 additions and 6 deletions

34
audible-converter.py Normal file
View File

@ -0,0 +1,34 @@
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())

View File

@ -31,11 +31,11 @@ function checkAudibleFile() {
}
function removeDRM() {
ffmpeg -activation_bytes ${2} -i ${1} -c copy "$(basename ${1} | cut -f 1 -d '.').m4b"
ffmpeg -activation_bytes ${2} -i ${1} -c copy "${3}.m4b"
}
function getChapterJSON() {
echo $(ffprobe -i ${1} -print_format json -show_chapters -loglevel error -sexagesimal)
echo $(ffprobe -i ${1} -print_format json -show_chapters -loglevel error -sexagesimal | jq '.chapters')
}
function getMetadataJSON() {
@ -46,6 +46,10 @@ function getTitle() {
echo $(echo ${1} | jq '.title' | cleanString)
}
function fileSafe() {
sed -e 's/[^A-Za-z0-9._-]/-/g' | tr '[:upper:]' '[:lower:]' | sed -e 's/--/-/g'
}
settingsFile='./settings.conf'
audibleFile=${1}
@ -61,9 +65,18 @@ fi
. $settingsFile
metadataJSON=$(getMetadataJSON $audibleFile)
json=$(getMetadataJSON $audibleFile)
getTitle "${json}"
chapterJSON=$(getChapterJSON $audibleFile)
name=$(getTitle "${metadataJSON}" | fileSafe)
if [ ! -f "$(basename ${audibleFile} | cut -f 1 -d '.').m4b" ]; then
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')