diff --git a/audible-converter.py b/audible-converter.py index 2880da0..3d8a147 100644 --- a/audible-converter.py +++ b/audible-converter.py @@ -17,6 +17,7 @@ class AudibleBook(object): self.filePath = filePath self.activationBytes = activationBytes self.targetDir = targetDir + self.convertedFilePath='' 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 \ @@ -67,6 +68,10 @@ class AudibleBook(object): if not os.path.exists(outFilePath): os.system('ffmpeg -i {} -an -vcodec copy {}'. format(self.convertedFilePath, outFilePath)) + + def deleteConverted(self): + if self.convertedFilePath is not '' and os.path.exists(self.configFilePath): + os.remove(self.convertedFilePath) # getHash() returns the hash of a given file. @@ -94,7 +99,7 @@ def createConfig(configFilePath, filePath): configFilePath='./settings.conf' audibleBookPath=sys.argv[1] serverURL=sys.argv[2] -targetDir='.' +targetDir='./audiobooks' # Check if config file exists and creates one if needed. if not os.path.exists(configFilePath): @@ -114,9 +119,12 @@ if not os.path.exists(outputDir): os.makedirs(outputDir) book.setTargetDir(outputDir) -book.removeDRM(name) -book.splitChapters() -book.getCover() +rssFilePath='{}/rss.xml'.format(outputDir) + +if not os.path.exists(rssFilePath): + book.removeDRM(name) + book.splitChapters() + book.getCover() fg = FeedGenerator() fg.id(name) @@ -139,6 +147,5 @@ for c in book.getChapters(): count += 1 rssfeed = fg.rss_str(pretty=True) -fg.rss_file('{}/rss.xml'.format(outputDir)) - -print() +fg.rss_file(rssFilePath) +book.deleteConverted()