rip and rename tools too

This commit is contained in:
Tyrel Souza 2023-10-08 14:37:42 -04:00
parent 083971d9b0
commit b29305d117
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
3 changed files with 55 additions and 5 deletions

View File

@ -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)

44
rename.py Normal file
View File

@ -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()

6
rip.py Normal file
View File

@ -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()