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 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 from subprocess import call
import os import os
import sys import sys
@@ -81,15 +87,6 @@ def do_command(command):
return response 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): def do_command(command):
"""Send one command, and return the response.""" """Send one command, and return the response."""
send_command(command) send_command(command)
@@ -102,12 +99,14 @@ def mkdir_if_not_exists(directory):
os.makedirs(directory) os.makedirs(directory)
return os.path.abspath(directory) return os.path.abspath(directory)
# TODO Cleanup path handling cause...ew
def do(): def do():
mkdir_if_not_exists(working_dir) mkdir_if_not_exists(working_dir)
if working_dir: if working_dir:
# Setup # Setup
#os.chdir(working_dir) #os.chdir(working_dir)
downloaded = mkdir_if_not_exists(working_dir + "/downloaded") 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") processed_audio_dir = mkdir_if_not_exists(working_dir + "/processed_audio")
final = mkdir_if_not_exists(working_dir + "/final") final = mkdir_if_not_exists(working_dir + "/final")
# Download videos # Download videos
@@ -132,25 +131,30 @@ def do():
# Rename file # Rename file
source = entry.path source = entry.path
filename = "{}.{}".format(title, extension) filename = "{}.{}".format(title, extension)
dest = downloaded.path.joinpath(filename) dest = os.path.abspath(renamed + "/" + filename)
print ("Source: " + source) print ("Source: " + source)
print ("Dest: " + dest) print ("Dest: " + dest)
os.rename(source, dest) shutil.copy(source, dest)
# Extract audio, process it, add it back to the video # Extract audio, process it, add it back to the video
video_in = os.path.abspath(filename) video_in = dest
processed_audio = processed_audio_dir.joinpath(filename + ".wav") processed_audio = os.path.join(processed_audio_dir, filename.split(".")[0] + ".wav")
final_output_name = final.joinpath(filename) final_output_name = os.path.join(final, filename)
# do_command("Help: Command=Popmute")
do_command("Import2: Filename={}".format(video_in)) do_command("Import2: Filename={}".format(video_in))
do_command("SelectAll:") do_command("SelectAll:")
do_command('Popmute:') do_command('Popmute: thresh=-0.5 floor=-100')
do_command("SelectAll:") do_command("SelectAll:")
do_command('Amplify:') do_command('Amplify:')
export(processed_audio) do_command("SelectAll:")
do_command('Close:') do_command("Export2: Filename={}".format(processed_audio))
# TODO Move to different script? do_command("SelectAll")
final_output_name = "output-" + video_in do_command("RemoveTracks")
print("Combining video with audio at {}", processed_audio) # do_command('Close:')
call('ffmpeg -i {} -i {} -acodec copy -vcodec copy -f mkv {}'.format(video_in, processed_audio, final_output_name), shell=True) # 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() do()