I'm writing an mp3 file condenser that turns multiple files into 1 large file. The idea is I point to a group of thousands of files such as Episode_001_00234523.mp3 and it condenses all the files that are episode 1 into a single mp3 and one that is episode 2 into another. I have tried every syntax I can think of in the command line and I feel like I'm following the instructions but I have just gotten error after error. What am I doing wrong? Or is there something in this script that is unlikely to work?
Thanks in advance for any help
Python Code:
import subprocess
from glob import glob
import os, sys
import re
media_path = "."
output_dir = sys.argv[1]
if (output_dir[0], output_dir[1]) == ('"','"'):
output_dir = output_dir[1:-2]
anime_re = re.compile("(.*)\.\d+\.\d+\.\d+-\d\.\d+\.\d+\.\d+.mp3")
os.chdir(media_path)
def condense(files):
files = sorted(files)
filename = '"' + os.path.join(output_dir,os.path.basename(files[0][1])) + '.mp3"'
files = ['"' + os.path.basename(x[0]) + '"' for x in files]
subprocess.call(f"./mp3cat -o {filename} {' '.join(files)}",shell=True)
safe_get = lambda x, y: "" if not x else x[y]
audios = glob(os.path.join(media_path,"*.mp3"))
names = [x for x in list(set([safe_get(re.findall(anime_re,x),0)for x in audios])) if x]
for i in names:
found = [(x,i) for x in audios if x.startswith(i)]
condense(found)
Sources used
https://old.reddit.com/r/ajatt/comments/em1yjs/make_condensed_audio_files_from_all_your_subs2srs/
https://gist.github.com/CrystalBear45/9cbc7d5def39a0d95c50f98965141a58
Instructions to reproduce on windows
Import all your desired subs2srs decks into a dummy Anki profile
Open a Windows command prompt and enter the following
python path/to/main.py path/to/collection.media output/folder
And then it asks you to put in the executable for mp3cat so you would type in something like:
path/to/mp3cat.exe
The files should output into your specified output folder
Link to the original zip:
https://mega.nz/folder/VKQkWAhI#dRmHR31_xsxhylCD4rN1uw
What I typed into the command line to try to make it work:
python "E:/Users/Bradley Aidan Johnson/Documents/Sentence Mining/Immersion Tracks/Bleach/Individual Episodes/001 - Copy/main.py" "E:/Users/Bradley Aidan Johnson/Documents/Sentence Mining/Immersion Tracks/Bleach/Individual Episodes/001 - Copy" "output/folder"
Error when I only told it to execute the py file:
main.py", line 8, in <module>
output_dir = sys.argv[1]
IndexError: list index out of range