rip and rename tools too
This commit is contained in:
parent
083971d9b0
commit
b29305d117
10
chapters.py
10
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)
|
||||
|
44
rename.py
Normal file
44
rename.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user