Create output directory
This commit is contained in:
parent
efdb203e2c
commit
ca54ab5e01
@ -1,14 +1,16 @@
|
|||||||
import configparser
|
import configparser
|
||||||
from requests import get
|
from requests import get
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class AudibleBook(object):
|
class AudibleBook(object):
|
||||||
|
|
||||||
def __init__(self, filePath, activationBytes):
|
def __init__(self, filePath, activationBytes, targetDir):
|
||||||
self.filePath = filePath
|
self.filePath = filePath
|
||||||
self.activationBytes = activationBytes
|
self.activationBytes = activationBytes
|
||||||
|
self.targetDir = targetDir
|
||||||
self.metadata = json.loads(os.popen('ffprobe -i {} -show_format \
|
self.metadata = json.loads(os.popen('ffprobe -i {} -show_format \
|
||||||
-print_format json'.format(filePath)).read())['format']['tags']
|
-print_format json'.format(filePath)).read())['format']['tags']
|
||||||
self.chapters = json.loads(os.popen('ffprobe -i {} -print_format json \
|
self.chapters = json.loads(os.popen('ffprobe -i {} -print_format json \
|
||||||
@ -31,10 +33,15 @@ class AudibleBook(object):
|
|||||||
def getTitle(self):
|
def getTitle(self):
|
||||||
return self.getMetadata()['title']
|
return self.getMetadata()['title']
|
||||||
|
|
||||||
|
def setTargetDir(self, targetDir):
|
||||||
|
self.targetDir = targetDir
|
||||||
|
|
||||||
def removeDRM(self, fileName):
|
def removeDRM(self, fileName):
|
||||||
os.system('ffmpeg -activation_bytes {} -i {} -c copy "{}.m4b"'
|
filePath = '{}/{}.m4b'.format(self.targetDir, fileName)
|
||||||
.format(self.activationBytes, self.filePath, fileName))
|
if not os.path.exists(filePath):
|
||||||
print('test')
|
os.system('ffmpeg -activation_bytes {} -i {} -c copy "{}"'
|
||||||
|
.format(self.activationBytes, self.filePath, filePath))
|
||||||
|
self.convertedFilePath = filePath
|
||||||
|
|
||||||
# getHash() returns the hash of a given file.
|
# getHash() returns the hash of a given file.
|
||||||
def getHash(filePath):
|
def getHash(filePath):
|
||||||
@ -58,8 +65,13 @@ def createConfig(configFilePath, filePath):
|
|||||||
f.write('activationBytes={}'.format(activationBytes))
|
f.write('activationBytes={}'.format(activationBytes))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# osSafeName() convertes a string to an OS safe name.
|
||||||
|
def osSafeName(name):
|
||||||
|
return re.sub(r'[^a-zA-Z0-9 -]', '', name).lower().replace(' ', '-').replace('--', '-')
|
||||||
|
|
||||||
configFilePath='./settings.conf'
|
configFilePath='./settings.conf'
|
||||||
audibleBookPath=sys.argv[1]
|
audibleBookPath=sys.argv[1]
|
||||||
|
targetDir='.'
|
||||||
|
|
||||||
# Check if config file exists and creates one if needed.
|
# Check if config file exists and creates one if needed.
|
||||||
if not os.path.exists(configFilePath):
|
if not os.path.exists(configFilePath):
|
||||||
@ -71,7 +83,15 @@ configParser = configparser.RawConfigParser()
|
|||||||
configParser.read_string(configString)
|
configParser.read_string(configString)
|
||||||
activationBytes=configParser.get('Settings', 'activationBytes')
|
activationBytes=configParser.get('Settings', 'activationBytes')
|
||||||
|
|
||||||
book = AudibleBook(audibleBookPath, activationBytes)
|
book = AudibleBook(audibleBookPath, activationBytes, targetDir)
|
||||||
|
|
||||||
|
name = osSafeName(book.getTitle())
|
||||||
|
outputDir = '{}/{}'.format(targetDir, name)
|
||||||
|
if not os.path.exists(outputDir):
|
||||||
|
os.makedirs(outputDir)
|
||||||
|
book.setTargetDir(outputDir)
|
||||||
|
|
||||||
|
book.removeDRM(name)
|
||||||
|
|
||||||
for c in book.getChapters():
|
for c in book.getChapters():
|
||||||
start=c['start']
|
start=c['start']
|
||||||
@ -81,7 +101,7 @@ for c in book.getChapters():
|
|||||||
#os.system('ffmpeg -i {} -acodec copy -vcodec copy -ss {} -t {} OUTFILE-{}.m4a'.format(filePath, start, end, title))
|
#os.system('ffmpeg -i {} -acodec copy -vcodec copy -ss {} -t {} OUTFILE-{}.m4a'.format(filePath, start, end, title))
|
||||||
|
|
||||||
|
|
||||||
print(book.getTitle())
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user