Jan-28-2019, 03:09 AM
Alright, I've tried a great many thing to try to get this to work. This iteration is the closest I've gotten to success. What I'm trying to do is write two lines, and only two lines, to a text file and then create a new file. The format is as such:
I'm using ffprobe to analyze an undetermined amount of audio tracks and essentially sort them by track length. I was at first trying to write the output ffprobe straight to the text file, but every out put was overwriting the first line and there would only be one file with one line, the last track in the directory. So then I tried to send the output of ffprobe to an array and print that to a text file. That works a little better, but either I only write 1 line to 1 file, or the entire array to only 1 file. Here's my code. I'm exhausted right now, I'll answer any questions and supply more code if you need. You'll see some bits commented out. I tend to leave those in there while I think about what I might change.
file1.txt
file 'C:\path\to\audiofile1.wav'
file 'C:\path\to\audiofile2.wav'
I'm using ffprobe to analyze an undetermined amount of audio tracks and essentially sort them by track length. I was at first trying to write the output ffprobe straight to the text file, but every out put was overwriting the first line and there would only be one file with one line, the last track in the directory. So then I tried to send the output of ffprobe to an array and print that to a text file. That works a little better, but either I only write 1 line to 1 file, or the entire array to only 1 file. Here's my code. I'm exhausted right now, I'll answer any questions and supply more code if you need. You'll see some bits commented out. I tend to leave those in there while I think about what I might change.
clipOrig = "D:\\path\\to\\audio\\files" os.chdir(clipOrig) current_files = glob.glob("sFile*.txt") file_count = 1 file = open(f"sFile{file_count}.txt", "w") while f"sFile{file_count}.txt" in current_files: file_count += 1 arr = [] def write_file(): global file_count, count count = sum(1 for line in open(f"sFile{file_count}.txt")) # count = 1 if(count == 2): file_count +=1 count = 1 else: for i in arr: print("file ", f"'{i}'", "\n", file=text_file) count += 1 for f in os.listdir(): ffprobe = subprocess.check_output(['ffprobe', '-v', 'quiet', '-show_entries', 'format=duration', '-of', 'csv=p=0', '-i', f], stderr=subprocess.PIPE, stdin=subprocess.PIPE).decode('utf-8').rstrip() with open(f"sFile{file_count}.txt", "w") as text_file: if float(ffprobe) < 35: ffilename = subprocess.check_output(['ffprobe', '-v', 'quiet', '-show_entries', 'format=filename', '-of', 'csv=p=0', '-i', f]).decode('utf-8').rstrip() arr.append(f"{clipOrig}\\{ffilename}") else: print("false") write_file()