import requests
from urllib.parse import quote
import subprocess
import os
import sys

speaker_id="p230"

letter_year = sys.argv[1]
output_dir = f"./wavs/bpl-{letter_year}"

outputs = os.listdir(output_dir)
inputs = []

for output in outputs:
 padded_fn = f"output-{output.split('-')[1].split('.')[0].zfill(2)}.wav"
 if (padded_fn != output):
     subprocess.run(["mv", output_dir+"/"+output, output_dir+"/"+padded_fn])

outputs = [f"output-{x.split('-')[1].split('.')[0].zfill(2)}.wav" for x in outputs]
print(outputs)
outputs.sort()

with open(f"inputs-{letter_year}.txt", 'w') as f:
    for (i, output) in enumerate(outputs):
        f.write(f"file {output_dir}/{output}'\n")

    #inputs.extend(['-i', './outputs/'+ output])
    f.flush()

#ffmpeg_cmd = ['ffmpeg']
#ffmpeg_cmd.extend(inputs)
#ffmpeg_cmd.extend(["./outputs/output.mp3"])
# print(ffmpeg_cmd)
#subprocess.run(ffmpeg_cmd)

