Initial version of lecturemunger working a treat

This commit is contained in:
2021-02-07 22:33:08 +00:00
parent 0f50272cdf
commit 8f1a5b23b2

View File

@@ -5,9 +5,15 @@
Depends on Destreamer and python-dateutil
Ensure you have a blank Audacity project open before use
Known issues:
- Audio and video slip ever so slightly out of sync
- Audio gets dickered into mono >.>
"""
import shutil
from subprocess import call
import os
import sys
@@ -81,15 +87,6 @@ def do_command(command):
return response
def export(filename):
"""Export the new track, and deleted both tracks."""
do_command("Select: Track=1 mode=Set")
do_command("SelTrackStartToEnd")
do_command("Export2: Filename={} NumChannels=1.0".format(filename))
do_command("SelectAll")
do_command("RemoveTracks")
def do_command(command):
"""Send one command, and return the response."""
send_command(command)
@@ -102,12 +99,14 @@ def mkdir_if_not_exists(directory):
os.makedirs(directory)
return os.path.abspath(directory)
# TODO Cleanup path handling cause...ew
def do():
mkdir_if_not_exists(working_dir)
if working_dir:
# Setup
#os.chdir(working_dir)
downloaded = mkdir_if_not_exists(working_dir + "/downloaded")
renamed = mkdir_if_not_exists(working_dir + "/renamed")
processed_audio_dir = mkdir_if_not_exists(working_dir + "/processed_audio")
final = mkdir_if_not_exists(working_dir + "/final")
# Download videos
@@ -132,25 +131,30 @@ def do():
# Rename file
source = entry.path
filename = "{}.{}".format(title, extension)
dest = downloaded.path.joinpath(filename)
dest = os.path.abspath(renamed + "/" + filename)
print ("Source: " + source)
print ("Dest: " + dest)
os.rename(source, dest)
shutil.copy(source, dest)
# Extract audio, process it, add it back to the video
video_in = os.path.abspath(filename)
processed_audio = processed_audio_dir.joinpath(filename + ".wav")
final_output_name = final.joinpath(filename)
video_in = dest
processed_audio = os.path.join(processed_audio_dir, filename.split(".")[0] + ".wav")
final_output_name = os.path.join(final, filename)
# do_command("Help: Command=Popmute")
do_command("Import2: Filename={}".format(video_in))
do_command("SelectAll:")
do_command('Popmute:')
do_command('Popmute: thresh=-0.5 floor=-100')
do_command("SelectAll:")
do_command('Amplify:')
export(processed_audio)
do_command('Close:')
# TODO Move to different script?
final_output_name = "output-" + video_in
print("Combining video with audio at {}", processed_audio)
call('ffmpeg -i {} -i {} -acodec copy -vcodec copy -f mkv {}'.format(video_in, processed_audio, final_output_name), shell=True)
do_command("SelectAll:")
do_command("Export2: Filename={}".format(processed_audio))
do_command("SelectAll")
do_command("RemoveTracks")
# do_command('Close:')
# final_output_name = "output-" +
# TODO Folderisation of output by lecture
print("Combining video with audio at {}".format(processed_audio))
call('ffmpeg -i {} -i {} -acodec copy -vcodec copy {}'.format(video_in, processed_audio, final_output_name), shell=True)
print("\033[92mDone! Result is at {}".format(final_output_name))
do()