From b712c60cbd4632607cdc7f588b337e0c8ed808da Mon Sep 17 00:00:00 2001 From: LightArrowsEXE Date: Tue, 16 Jul 2019 13:41:24 +0200 Subject: [PATCH] Update fansub-util repository --- auto-CRC.py | 4 +- encode_audio.py | 7 +-- generate_keyframes.py | 6 +- .../clean-dir.py | 12 ++-- old and dumb scripts/clean-enc-dir.py | 41 ++++++++++++++ remux.py | 55 +++++++++++++++++++ 6 files changed, 111 insertions(+), 14 deletions(-) rename clean-dir.py => old and dumb scripts/clean-dir.py (86%) create mode 100644 old and dumb scripts/clean-enc-dir.py create mode 100644 remux.py diff --git a/auto-CRC.py b/auto-CRC.py index ae131c0..7fc70cd 100644 --- a/auto-CRC.py +++ b/auto-CRC.py @@ -2,7 +2,7 @@ """ This script appends CRC-32s to the end of the files in a directory. This is intended for anime fansubbing releases. -You can change what it checks by modifying the 'ext' (extension) on L46. +You can change what it checks by modifying the 'ext' (extension) on L47. Can be run both from the command line, and imported. """ import argparse @@ -45,4 +45,4 @@ if __name__ == "__main__": parser.parse_args() args = parser.parse_args() ext = '*.mkv' - main(ext, args.recursive) + main(ext, args.recursive) \ No newline at end of file diff --git a/encode_audio.py b/encode_audio.py index 4e2241e..85c523e 100644 --- a/encode_audio.py +++ b/encode_audio.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python """ Encodes audio from m2ts sources @@ -28,8 +29,8 @@ else: for f in filelist: print(f) - if not re.search(r'\.(wav|m4a|flac)$', f): - subprocess.call(["ffmpeg", "-hide_banner", "-loglevel", "panic", f"-i", f,"-vn", f"{os.path.splitext(f)[0]}.wav"]) + if not re.search(r'\.(wav|m4a|flac|lwi)$', f): + subprocess.call(["ffmpeg", "-hide_banner", "-loglevel", "panic", "-i", f,"-vn", f"{os.path.splitext(f)[0]}.wav"]) if not os.path.exists(f'{f[0]}.m4a') or os.path.exists(f'{f[0]}.flac'): if args.flac: subprocess.call(["ffmpeg", "-hide_banner", "-i", f"{os.path.splitext(f)[0]}.wav", "-vn", "-c:a flac", "-sample_fmt s16","compression_level 12", f"{os.path.splitext(f)[0]}.flac"]) @@ -44,5 +45,3 @@ for f in filelist: os.remove(f"{os.path.splitext(f)[0]}.wav") except OSError: pass - - diff --git a/generate_keyframes.py b/generate_keyframes.py index 41ddafe..841fce5 100644 --- a/generate_keyframes.py +++ b/generate_keyframes.py @@ -17,8 +17,8 @@ def generate_keyframes(): else: files = glob.glob('*') - if args.ext: - ext_in = args.ext + if args.extension: + ext_in = args.extension else: ext_in = "mkv" @@ -48,6 +48,6 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-R", "--recursive", help="check recursively", action="store_true") - parser.add_argument("-E", "--ext", help="pick extension to generate keyframes for") + parser.add_argument("-E", "--extension", help="pick extension to generate keyframes for") args = parser.parse_args() generate_keyframes() diff --git a/clean-dir.py b/old and dumb scripts/clean-dir.py similarity index 86% rename from clean-dir.py rename to old and dumb scripts/clean-dir.py index 8549f31..8a24710 100644 --- a/clean-dir.py +++ b/old and dumb scripts/clean-dir.py @@ -11,7 +11,8 @@ import os import time parser = argparse.ArgumentParser() -parser.add_argument("-R", "--recursive", help="check recursively", action="store_true") +parser.add_argument("-R", "--recursive", + help="check recursively", action="store_true") parser.add_argument("-E", "--extension", help="change extension") args = parser.parse_args() @@ -37,7 +38,8 @@ for f in filelist: cleaned_directory = os.path.join(os.getcwd(), new_directory) if not os.path.exists(cleaned_directory): os.makedirs(new_directory) - print(f"Created a new directory. Moving cleaned files into {cleaned_directory}") + print( + f"Created a new directory. Moving cleaned files into {cleaned_directory}") shutil.copy(f, cleaned_directory) os.remove(f) except Exception: @@ -52,9 +54,9 @@ if args.recursive: filelist = glob.glob('**/*', recursive=True) else: filelist = glob.glob('*') - + for f in filelist: print(f"'{f}'") - -print('\n\nPlease ensure that all the relevant files are included') \ No newline at end of file + +print('\n\nPlease ensure that all the relevant files are included') diff --git a/old and dumb scripts/clean-enc-dir.py b/old and dumb scripts/clean-enc-dir.py new file mode 100644 index 0000000..2857029 --- /dev/null +++ b/old and dumb scripts/clean-enc-dir.py @@ -0,0 +1,41 @@ +""" + Cleaning encoding directory of everything but vpy's and py's. + + Please note that this does NOT remove empty directories and does not have ANY exceptions. It will only keep mkv's. +""" +import argparse +import glob +import shutil +import os +import time + +parser = argparse.ArgumentParser() +parser.add_argument("-R", "--recursive", + help="check recursively", action="store_true") +parser.parse_args() +args = parser.parse_args() + +if args.recursive: + filelist = glob.glob('**\*.*', recursive=True) +else: + filelist = glob.glob('*.*') + +for f in filelist: + if f.endswith('.py') or f.endswith('.vpy'): + if os.path.isfile(f): + try: + shutil.copy(f, os.getcwd()) + os.remove(f) + print(f"Moving '{f}' to current directory.") + except Exception: + pass + else: + os.remove(f) + print(f"Cleaned '{f}'") + +print('-------------------------------------------------\nPrinting remaining files in directory...') +time.sleep(3) +print('-------------------------------------------------\nRemaining files:\n\n') +for f in filelist: + print(f"'{f}'") +print('\n\nPlease ensure that all the relevant files are included.') diff --git a/remux.py b/remux.py new file mode 100644 index 0000000..01a2e25 --- /dev/null +++ b/remux.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +""" + Generic script for remuxing files from a certain filetype into another. + + Flags: + -R - Check recursively + -i - change input extension + -o - change output extension + + TO-DO: clean up +""" +import os +import glob +import argparse +import subprocess +import time + +parser = argparse.ArgumentParser() +parser.add_argument("-R", "--recursive", + help="check recursively", action="store_true") +parser.add_argument("-i", "--input_ext", + help="set input's extension (default: mkv)") +parser.add_argument("-o", "--output_ext", + help="set output's extension (default: mp4)") +args = parser.parse_args() + +if args.recursive: + filelist = glob.glob('**/*', recursive=True) +else: + filelist = glob.glob('*') + +if args.input_ext: + ext_in = args.input_ext + if ext_in.startswith("."): + ext_in = ext_in[1:] +else: + ext_in = "mkv" + +if args.output_ext: + ext_out = args.output_ext + if ext_out.startswith("."): + ext_out = ext_out[1:] +else: + ext_out = "mp4" + +print(f"Remuxing all {ext_in} to {ext_out}\n") +time.sleep(1) + +for f in filelist: + if f.endswith(ext_in): + subprocess.call(["ffmpeg", "-hide_banner", "-loglevel", "panic", "-i", f"{os.path.splitext(f)[0]}.{ext_in}", "-c", "copy", f"{os.path.splitext(f)[0]}.{ext_out}"]) + print(f"Remuxing:\n{f} ->\n{os.path.splitext(f)[0]}.{ext_out}\n") + else: + pass +