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:
|
class Chapters:
|
||||||
|
|
||||||
def __init__(self, title, author):
|
def __init__(self, title, artist):
|
||||||
self.title = title
|
self.title = title
|
||||||
self.author = author
|
self.artist = artist
|
||||||
self.file_names = sorted(glob.glob("*.mp3"))
|
self.file_names = sorted(glob.glob("*.mp3"))
|
||||||
self.FFMETADATAFILE = f""";FFMETADATA1
|
self.FFMETADATAFILE = f""";FFMETADATA1
|
||||||
title={self.title}
|
title={self.title}
|
||||||
author={self.author}
|
artist={self.artist}
|
||||||
encoder=libfdk_aac
|
encoder=libfdk_aac
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -56,8 +56,8 @@ title={title}
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
title = input("Title: ")
|
title = input("Title: ")
|
||||||
author = input("Author: ")
|
artist = input("Artist: ")
|
||||||
ch = Chapters(title=title, author=author)
|
ch = Chapters(title=title, artist=artist)
|
||||||
ch.generate_metadata()
|
ch.generate_metadata()
|
||||||
with open("FFMETADATAFILE.txt", "w") as f:
|
with open("FFMETADATAFILE.txt", "w") as f:
|
||||||
print(ch.FFMETADATAFILE, file=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