From b29305d1174d7bda24bbd5c4e87c029591bd9fcf Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sun, 8 Oct 2023 14:37:42 -0400 Subject: [PATCH] rip and rename tools too --- chapters.py | 10 +++++----- rename.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ rip.py | 6 ++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 rename.py create mode 100644 rip.py diff --git a/chapters.py b/chapters.py index 6f8c990..8a7ffb9 100644 --- a/chapters.py +++ b/chapters.py @@ -6,13 +6,13 @@ from mutagen.mp3 import MP3 class Chapters: - def __init__(self, title, author): + def __init__(self, title, artist): self.title = title - self.author = author + self.artist = artist self.file_names = sorted(glob.glob("*.mp3")) self.FFMETADATAFILE = f""";FFMETADATA1 title={self.title} -author={self.author} +artist={self.artist} encoder=libfdk_aac """ @@ -56,8 +56,8 @@ title={title} def main(): title = input("Title: ") - author = input("Author: ") - ch = Chapters(title=title, author=author) + artist = input("Artist: ") + ch = Chapters(title=title, artist=artist) ch.generate_metadata() with open("FFMETADATAFILE.txt", "w") as f: print(ch.FFMETADATAFILE, file=f) diff --git a/rename.py b/rename.py new file mode 100644 index 0000000..b2aa65f --- /dev/null +++ b/rename.py @@ -0,0 +1,44 @@ +import glob +import json +import os +import subprocess +import sys + + +def run(): + if len(sys.argv) > 1: + files = sys.argv[1:] + else: + files = glob.glob("*.m4b") + + for f in files: + rename(f) + +def rename(f): + p = subprocess.Popen( ["exiftool","-json","-Artist","-Title",f], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + out, err = p.communicate() + meta = json.loads(out)[0] + artist = meta['Artist'] + title = meta['Title'].split(":")[0] + + try: + os.mkdir(f"{artist}") + except FileExistsError as e: + pass + + try: + os.mkdir(f"{artist}/{title}") + except FileExistsError as e: + pass + + + new_path = f"{artist}/{title}/Audiobook.m4b" + os.rename(f, new_path) + + +if __name__ == "__main__": + run() diff --git a/rip.py b/rip.py new file mode 100644 index 0000000..cd9d5e6 --- /dev/null +++ b/rip.py @@ -0,0 +1,6 @@ +# name=$(basename "$1" .aax) +# ffmpeg -y -activation_bytes $KEY -i "$name.aax" -map_metadata 0 -id3v2_version 3 -codec:a copy -vn "output/$name.m4b" +# mv "$name.aax" "converted/$name.aax" + +if __name__ == "__main__": + main()