diff --git a/deportfolio.sh b/deportfolio.sh new file mode 100644 index 0000000..2e6385a --- /dev/null +++ b/deportfolio.sh @@ -0,0 +1,3 @@ +# Helper for unfucking Adobe's stupid Portfolios +# TODO: Currently only merges, can we automatically extract? +pdftk $(ls -1v) cat output $1 diff --git a/lecturemunger.py b/lecturemunger.py index 48b1ca3..6dd3dfd 100644 --- a/lecturemunger.py +++ b/lecturemunger.py @@ -115,53 +115,54 @@ def do(): print("Using destreamer.js at {}".format(path_to_destreamer)) call("node --max-http-header-size 32768 {} --skip -k -o {} -i {}".format(path_to_destreamer, downloaded, " ".join(urls)), shell=True) for entry in os.scandir(downloaded): - # Normalise names # Put file extension to one side for safekeeping split = entry.name.split('.') extension = split[1] - name = split[0].replace(',', '').split('#')[0] # Discard all commas, and unique id doodad - head, sep, tail = name.partition(' ') # Discard leading date - split2 = tail.split() - date = dparser.parse(split2[-1], fuzzy=True) # Parse the date - folder_path = split2[0] + split2[1] # TODO Fragile - title = re.search(r'\d+-\d+\s[\d\w\s]*', tail) - if re.match: - title = title.group(0).strip().replace(' ', '_') - # Add date back - if date is not None: - title += "_" + date.strftime('%Y-%m-%d') - # Rename file - source = entry.path - filename = "{}.{}".format(title, extension) - dest = os.path.abspath(renamed + "/" + filename) - print ("Source: " + source) - print ("Dest: " + dest) - shutil.copy(source, dest) - time.sleep(5) - # Extract audio, process it, add it back to the video - video_in = dest - processed_audio = os.path.join(processed_audio_dir, filename.split(".")[0] + ".wav") - final_output_name = os.path.join(final, filename.split(".")[0] + ".mp4") - do_command("New:") - do_command("Import2: Filename={}".format(video_in)) - time.sleep(5) - do_command("SelectAll:") - do_command('Amplify: Ratio=2') - time.sleep(1) - do_command("SelectAll:") - do_command('Popmute: thresh=10 floor=100') - time.sleep(1) - do_command("Export2: Filename={} NumChannels=2".format(processed_audio)) - time.sleep(5) - do_command("SelectAll:") - do_command("RemoveTracks:") - time.sleep(5) - # do_command('Close:') TODO THis causes audacity to wait for a input - # final_output_name = "output-" + - # TODO Folderisation of output by lecture - print("Combining video at {} with audio at {}".format(video_in, processed_audio)) - # https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg - call('ffmpeg -i {} -i {} -acodec copy -vcodec copy -map 0:v:0 -map 1:a:0 {}'.format(video_in, processed_audio, final_output_name), shell=True) - print("\033[92mDone! Result is at {}\e[0m".format(final_output_name)) + if str(extension) == "mkv": + # Normalise names + name = split[0].replace(',', '').split('#')[0] # Discard all commas, and unique id doodad + head, sep, tail = name.partition(' ') # Discard leading date + split2 = tail.split() + date = dparser.parse(split2[1], fuzzy=True) # Parse the date + folder_path = split2[0] + split2[1] # TODO Fragile + title = re.search(r'\d+-\d+\s[\d\w\s]*', tail) + if re.match: + title = title.group(0).strip().replace(' ', '_') + # Add date back + if date is not None: + title += "_" + date.strftime('%Y-%m-%d') + # Rename file + source = entry.path + filename = "{}.{}".format(title, extension) + dest = os.path.abspath(renamed + "/" + filename) + print ("Source: " + source) + print ("Dest: " + dest) + shutil.copy(source, dest) + time.sleep(5) + # Extract audio, process it, add it back to the video + video_in = dest + processed_audio = os.path.join(processed_audio_dir, filename.split(".")[0] + ".wav") + final_output_name = os.path.join(final, filename.split(".")[0] + ".mkv") + do_command("New:") + do_command("Import2: Filename={}".format(video_in)) + time.sleep(5) + do_command("SelectAll:") + do_command('Amplify: Ratio=2') + time.sleep(1) + do_command("SelectAll:") + do_command('Popmute: thresh=10 floor=100') + time.sleep(1) + do_command("Export2: Filename={} NumChannels=2".format(processed_audio)) + time.sleep(5) + do_command("SelectAll:") + do_command("RemoveTracks:") + time.sleep(5) + # do_command('Close:') TODO THis causes audacity to wait for a input + # final_output_name = "output-" + + # TODO Folderisation of output by lecture + print("Combining video at {} with audio at {}".format(video_in, processed_audio)) + # https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg + call('ffmpeg -i {} -i {} -acodec copy -vcodec copy -map 0:v:0 -map 1:a:0 {}'.format(video_in, processed_audio, final_output_name), shell=True) + print("\033[92mDone! Result is at {}\e[0m".format(final_output_name)) print("Munging complete!!!") do()