From 61544e9ba184496037028f950e1d650223075c93 Mon Sep 17 00:00:00 2001 From: louis Date: Mon, 19 Apr 2021 18:07:40 -0400 Subject: [PATCH] vivy: tv: update scripts --- Vivy/01/01.vpy | 28 ++++++++---- Vivy/02/02.vpy | 74 ++++++++++++++++++------------- Vivy/03/03.vpy | 40 ++++++++++------- Vivy/04/04.vpy | 15 ++++--- Vivy/vivy_common/__init__.py | 2 +- Vivy/vivy_common/config.py | 22 +++++++-- Vivy/vivy_common/final-settings | 2 +- yt_common/yt_common/__init__.py | 4 +- yt_common/yt_common/automation.py | 50 +++++++++------------ yt_common/yt_common/config.py | 1 - yt_common/yt_common/log.py | 23 ---------- yt_common/yt_common/logging.py | 25 +++++++++++ yt_common/yt_common/source.py | 26 +++++++++-- 13 files changed, 188 insertions(+), 124 deletions(-) delete mode 100644 yt_common/yt_common/log.py create mode 100644 yt_common/yt_common/logging.py diff --git a/Vivy/01/01.vpy b/Vivy/01/01.vpy index ec5986a..f01328a 100644 --- a/Vivy/01/01.vpy +++ b/Vivy/01/01.vpy @@ -1,7 +1,10 @@ import vapoursynth as vs +from yt_common.automation import SelfRunner +from yt_common.source import waka_replace + from lvsfunc.types import Range -from lvsfunc.dehardsub import HardsubSign, bounded_dehardsub +from lvsfunc.dehardsub import HardsubSign, HardsubMask, bounded_dehardsub from typing import List @@ -9,14 +12,21 @@ import os import sys sys.path.append("..") -from vivy_common import (SelfRunner, antialias, deband, denoise, # noqa: E402 - finalize, fsrcnnx_rescale, letterbox_edgefix, source) +from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402 + finalize, fsrcnnx_rescale, letterbox_edgefix) core = vs.core EPNUM: int = int(os.path.basename(os.path.splitext(__file__)[0])) -SIGNS_RU: List[HardsubSign] = [ +CONFIG: VivyConfig = VivyConfig(EPNUM) +SOURCE: VivySource = VivySource(CONFIG) + +WAKA_REPLACE: List[List[Range]] = [ + [], + [] +] +SIGNS_RU: List[HardsubMask] = [ HardsubSign((5283, 5403), ((226, 786), (1214, 102)), highpass=2000), HardsubSign((6778, 6888), ((588, 454), (434, 63)), highpass=2000), HardsubSign((9017, 9070), ((975, 301), (157, 24)), highpass=2000), @@ -42,9 +52,11 @@ LETTERBOX: List[Range] = [ def filter_basic() -> vs.VideoNode: - waka, ref = source(EPNUM) - waka = waka[:37301] + core.std.BlankClip(waka, length=6) + waka[37301:] - src = bounded_dehardsub(waka, ref, SIGNS_RU) + wakas, ref = SOURCE.source() + wakas = [waka[:37301] + core.std.BlankClip(waka, length=6) + waka[37301:] for waka in wakas] + waka = wakas[0] + waka, wakas = waka_replace(waka, wakas[1:], WAKA_REPLACE) + src = bounded_dehardsub(waka, ref, SIGNS_RU, wakas) return src @@ -61,6 +73,6 @@ def filter() -> vs.VideoNode: if __name__ == "__main__": - SelfRunner(EPNUM, filter, filter_basic) + SelfRunner(CONFIG, filter, filter_basic) else: filter() diff --git a/Vivy/02/02.vpy b/Vivy/02/02.vpy index df5abe6..74638c9 100644 --- a/Vivy/02/02.vpy +++ b/Vivy/02/02.vpy @@ -1,7 +1,10 @@ import vapoursynth as vs +from yt_common.automation import SelfRunner +from yt_common.source import waka_replace + from lvsfunc.types import Range -from lvsfunc.dehardsub import HardsubSign, bounded_dehardsub +from lvsfunc.dehardsub import HardsubMask, HardsubSign, bounded_dehardsub from typing import List @@ -9,37 +12,44 @@ import os import sys sys.path.append("..") -from vivy_common import (SelfRunner, antialias, deband, denoise, finalize, # noqa: E402 - fsrcnnx_rescale, source) +from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize, # noqa: E402 + fsrcnnx_rescale) core = vs.core EPNUM: int = int(os.path.basename(os.path.splitext(__file__)[0])) -SIGNS_RU: List[HardsubSign] = [ - HardsubSign((125, 245), ((220, 865), (992, 98)), refframe=143), - HardsubSign((865, 896), ((1173, 539), (232, 40)), highpass=2000), - HardsubSign((2274, 2318), ((431, 671), (1068, 142)), highpass=2000), - HardsubSign((2391, 2426), ((116, 62), (1471, 311)), highpass=2000), - HardsubSign((2427, 2452), ((317, 728), (1176, 80)), highpass=2000), - HardsubSign((3776, 3871), ((782, 286), (748, 76)), highpass=2000), - HardsubSign((3877, 3950), ((866, 524), (494, 53)), highpass=2000), - HardsubSign((6498, 6542), ((696, 296), (493, 31)), highpass=2000), - HardsubSign((7212, 7221), ((430, 666), (1066, 149)), highpass=2000), - HardsubSign((7222, 7233), ((317, 728), (1179, 84)), highpass=2000), - HardsubSign((7234, 7245), ((410, 303), (1169, 129)), highpass=2000), - HardsubSign((7246, 7254), ((514, 687), (807, 90)), highpass=2000), - HardsubSign((27488, 27630), ((778, 287), (758, 78)), highpass=2000), - HardsubSign((27636, 27779), ((756, 449), (792, 87)), highpass=2000), - HardsubSign((28907, 28934), ((758, 454), (787, 79)), highpass=2000), - HardsubSign((28945, 28954), ((773, 481), (758, 57)), highpass=2000), - HardsubSign((28986, 29019), ((621, 748), (657, 52)), highpass=2000), - HardsubSign((29053, 29061), ((621, 748), (657, 52)), highpass=2000), - HardsubSign((29062, 29077), ((649, 333), (742, 53)), highpass=2000), - HardsubSign((29615, 29674), ((336, 74), (1244, 76)), highpass=2000), - HardsubSign((29675, 29758), ((587, 68), (750, 85)), highpass=2000), - HardsubSign((30259, 30977), ((293, 843), (1321, 227)), highpass=2000), - HardsubSign((32608, 32703), ((281, 859), (890, 101)), highpass=2000), +CONFIG: VivyConfig = VivyConfig(EPNUM) +SOURCE: VivySource = VivySource(CONFIG) + +WAKA_REPLACE: List[List[Range]] = [ + [], + [], +] +SIGNS_RU: List[HardsubMask] = [ + HardsubSign((125, 245), ((220, 865), (992, 98)), refframe=143, blur=False), + HardsubSign((865, 896), ((1173, 539), (232, 40)), highpass=2000, blur=False), + HardsubSign((2274, 2318), ((431, 671), (1068, 142)), highpass=2000, blur=False), + HardsubSign((2391, 2426), ((116, 62), (1471, 311)), highpass=2000, blur=False), + HardsubSign((2427, 2452), ((317, 728), (1176, 80)), highpass=2000, blur=False), + HardsubSign((3776, 3871), ((782, 286), (748, 76)), highpass=2000, blur=False), + HardsubSign((3877, 3950), ((866, 524), (494, 53)), highpass=2000, blur=False), + HardsubSign((6498, 6542), ((696, 296), (493, 31)), highpass=2000, blur=False), + HardsubSign((7212, 7221), ((430, 666), (1066, 149)), highpass=2000, blur=False), + HardsubSign((7222, 7233), ((317, 728), (1179, 84)), highpass=2000, blur=False), + HardsubSign((7234, 7245), ((410, 303), (1169, 129)), highpass=2000, blur=False), + HardsubSign((7246, 7254), ((514, 687), (807, 90)), highpass=2000, blur=False), + HardsubSign((27488, 27630), ((778, 287), (758, 78)), highpass=2000, blur=False), + HardsubSign((27636, 27779), ((756, 449), (792, 87)), highpass=2000, blur=False), + HardsubSign((28907, 28934), ((758, 454), (787, 79)), highpass=2000, blur=False), + HardsubSign((28945, 28954), ((773, 481), (758, 57)), highpass=2000, blur=False), + HardsubSign((28986, 29019), ((621, 748), (657, 52)), highpass=2000, blur=False), + HardsubSign((29053, 29061), ((621, 748), (657, 52)), highpass=2000, blur=False), + HardsubSign((29062, 29077), ((649, 333), (742, 53)), highpass=2000, blur=False), + HardsubSign((29615, 29674), ((336, 74), (1244, 76)), highpass=2000, blur=False), + HardsubSign((29675, 29758), ((587, 68), (750, 85)), highpass=2000, blur=False), + HardsubSign((30259, 30977), ((293, 843), (1321, 227)), highpass=2000, blur=False), + HardsubSign((32608, 32703), ((281, 859), (890, 101)), highpass=2000, blur=False), ] CREDITS: List[Range] = [(30152, 32343)] PIXELSHIT: List[Range] = [ @@ -50,9 +60,11 @@ NOAA: List[Range] = PIXELSHIT def filter_basic() -> vs.VideoNode: - waka, ref = source(EPNUM) - waka = waka[:32344] + waka[32349:] - src = bounded_dehardsub(waka, ref, SIGNS_RU) + wakas, ref = SOURCE.source() + wakas = [waka[:32344] + waka[32349:] for waka in wakas] + waka = wakas[0] + waka, wakas = waka_replace(waka, wakas[1:], WAKA_REPLACE) + src = bounded_dehardsub(waka, ref, SIGNS_RU, wakas) return src @@ -68,6 +80,6 @@ def filter() -> vs.VideoNode: if __name__ == "__main__": - SelfRunner(EPNUM, filter, filter_basic) + SelfRunner(CONFIG, filter, filter_basic) else: filter() diff --git a/Vivy/03/03.vpy b/Vivy/03/03.vpy index 2b542ea..53199c4 100644 --- a/Vivy/03/03.vpy +++ b/Vivy/03/03.vpy @@ -1,7 +1,10 @@ import vapoursynth as vs +from yt_common.automation import SelfRunner +from yt_common.source import waka_replace + from lvsfunc.types import Range -from lvsfunc.dehardsub import HardsubSign, bounded_dehardsub +from lvsfunc.dehardsub import HardsubMask, HardsubLine, HardsubSign, bounded_dehardsub from typing import List @@ -9,26 +12,31 @@ import os import sys sys.path.append("..") -from vivy_common import (SelfRunner, antialias, deband, denoise, # noqa: E402 - finalize, fsrcnnx_rescale, letterbox_edgefix, source) +from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402 + finalize, fsrcnnx_rescale, letterbox_edgefix) core = vs.core EPNUM: int = int(os.path.basename(os.path.splitext(__file__)[0])) -SIGNS_RU: List[HardsubSign] = [ - HardsubSign((1371, 3157), ((293, 872), (1323, 162)), highpass=20000), - HardsubSign((3572, 3688), ((236, 860), (821, 103)), refframe=3671), +CONFIG: VivyConfig = VivyConfig(EPNUM) +SOURCE: VivySource = VivySource(CONFIG) + +WAKA_REPLACE: List[List[Range]] = [ + [(29968, 30792)], + [(31727, 31879)], +] +SIGNS_RU: List[HardsubMask] = [ + HardsubLine((1371, 3157), ((293, 872), (1323, 162))), + HardsubSign((3572, 3688), ((236, 860), (821, 103)), refframes=3671), HardsubSign((4040, 4105), ((937, 18), (811, 338))), HardsubSign((4040, 4105), ((132, 671), (384, 211))), HardsubSign((8135, 8259), ((583, 65), (744, 80))), - HardsubSign((9572, 9596), ((573, 74), (768, 79))), - HardsubSign((21874, 21942), ((532, 131), (445, 228)), highpass=2000), - HardsubSign((29968, 31084), ((293, 872), (1323, 162)), highpass=20000), - HardsubSign((30002, 30792), ((302, 73), (1328, 142)), highpass=2000, expand=10), - HardsubSign((31727, 31879), ((293, 872), (1323, 162)), highpass=20000), - HardsubSign((32540, 32651), ((293, 872), (1323, 162)), highpass=20000), - HardsubSign((33948, 34044), ((267, 857), (1067, 104)), refframe=34030), + HardsubSign((9571, 9596), ((573, 74), (768, 79))), + HardsubSign((21874, 21942), ((532, 131), (445, 228)), refframes=21942, highpass=2000), + HardsubLine((29968, 31084), ((293, 872), (1323, 182))), + HardsubLine((32540, 32651), ((293, 872), (1323, 162))), + HardsubSign((33948, 34044), ((267, 857), (1067, 104)), refframes=34030), ] NOSCALE: List[Range] = [] NOAA: List[Range] = [] @@ -36,7 +44,9 @@ LETTERBOX: List[Range] = [(0, 432)] def filter_basic() -> vs.VideoNode: - waka, ref = source(EPNUM) + wakas, ref = SOURCE.source() + waka = wakas[0] + waka, wakas = waka_replace(waka, wakas[1:], WAKA_REPLACE) src = bounded_dehardsub(waka, ref, SIGNS_RU) return src @@ -54,6 +64,6 @@ def filter() -> vs.VideoNode: if __name__ == "__main__": - SelfRunner(EPNUM, filter, filter_basic) + SelfRunner(CONFIG, filter, filter_basic) else: filter() diff --git a/Vivy/04/04.vpy b/Vivy/04/04.vpy index 3815911..ac5b559 100644 --- a/Vivy/04/04.vpy +++ b/Vivy/04/04.vpy @@ -1,8 +1,10 @@ import vapoursynth as vs +from yt_common.automation import SelfRunner +from yt_common.source import waka_replace + from lvsfunc.types import Range from lvsfunc.dehardsub import HardsubLine, HardsubSign, HardsubMask, bounded_dehardsub -from yt_common import SelfRunner from typing import List @@ -11,7 +13,7 @@ import sys sys.path.append("..") from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402 - finalize, fsrcnnx_rescale, letterbox_edgefix, waka_replace) + finalize, fsrcnnx_rescale, letterbox_edgefix) core = vs.core @@ -19,6 +21,11 @@ core = vs.core EPNUM: int = int(os.path.basename(os.path.splitext(__file__)[0])) CONFIG: VivyConfig = VivyConfig(EPNUM) SOURCE: VivySource = VivySource(CONFIG) + +WAKA_REPLACE: List[List[Range]] = [ + [(30119, 30969)], + [], +] SIGNS_RU: List[HardsubMask] = [ HardsubLine((1278, 3392), ((275, 918), (1356, 112))), HardsubSign((3452, 3572), ((232, 857), (1077, 114)), refframes=3500), @@ -30,10 +37,6 @@ SIGNS_RU: List[HardsubMask] = [ NOSCALE: List[Range] = [] NOAA: List[Range] = [] LETTERBOX: List[Range] = [(0, 1151)] -WAKA_REPLACE: List[List[Range]] = [ - [(30119, 30969)], - [], -] def filter_basic() -> vs.VideoNode: diff --git a/Vivy/vivy_common/__init__.py b/Vivy/vivy_common/__init__.py index 475408f..850131e 100644 --- a/Vivy/vivy_common/__init__.py +++ b/Vivy/vivy_common/__init__.py @@ -1,2 +1,2 @@ from .filter import antialias, deband, denoise, finalize, fsrcnnx_rescale, letterbox_edgefix # noqa: F401 -from .util import SelfRunner, glob_crc, source # noqa: F401 +from .config import VivyConfig, VivySource # noqa: F401 diff --git a/Vivy/vivy_common/config.py b/Vivy/vivy_common/config.py index a8ae075..fc4379d 100644 --- a/Vivy/vivy_common/config.py +++ b/Vivy/vivy_common/config.py @@ -1,4 +1,8 @@ -from yt_common import Config, FunimationSource +import vapoursynth as vs + +from yt_common import source +from yt_common.logging import log +from yt_common.config import Config import os @@ -7,7 +11,6 @@ from typing import List TITLE: str = "Vivy" TITLE_LONG: str = f"{TITLE} - Fluorite Eye's Song" RESOLUTION: int = 1080 -SUBGROUP: str = "YameteTomete" DATAPATH: str = os.path.dirname(__file__) WAKA_RU_FILENAME: str = f"{TITLE}_{{epnum:02d}}_RU_HD.mp4" @@ -15,6 +18,9 @@ WAKA_FR_FILENAME: str = f"{TITLE}_{{epnum:02d}}_FR_HD.mp4" WAKA_DE_FILENAME: str = f"{TITLE} - Fluorite Eyes Song E{{epnum:02d}} [1080p][AAC][JapDub][GerSub][Web-DL].mkv" +core = vs.core + + class VivyConfig(Config): def __init__(self, epnum: int) -> None: super().__init__( @@ -26,7 +32,17 @@ class VivyConfig(Config): ) -class VivySource(FunimationSource): +class VivySource(source.FunimationSource): + def get_amazon(self) -> vs.VideoNode: + # ep1-3 have good funi video, let's just use that + if self.config.epnum < 4: + raise FileNotFoundError() + if not os.path.isfile(self.config.format_filename(source.AMAZON_FILENAME)): + log.warn("Amazon not found, falling back to Funimation") + raise FileNotFoundError() + log.success("Found Amazon video") + return core.ffms2.Source(self.config.format_filename(source.AMAZON_FILENAME)) + def get_waka_filenames(self) -> List[str]: return [self.config.format_filename(f) for f in [ WAKA_RU_FILENAME, diff --git a/Vivy/vivy_common/final-settings b/Vivy/vivy_common/final-settings index 00c4ec4..80939b5 100644 --- a/Vivy/vivy_common/final-settings +++ b/Vivy/vivy_common/final-settings @@ -1 +1 @@ -x265 --input - --y4m --input-depth 10 --output-depth 10 --input-csp i420 --profile main10 --colormatrix bt709 --colorprim bt709 --transfer bt709 --preset slower --rc-lookahead 72 --keyint 360 --min-keyint 23 --subme 5 --qcomp 0.7 --crf 15 --aq-mode 3 --aq-strength 0.9 --bframes 16 --psy-rd 0.95 --psy-rdoq 1.8 --rdoq-level 1 --deblock -2:-2 --no-sao --frames {frames:d} --output {filename:s}.h265 +x265 --input - --y4m --input-depth 10 --output-depth 10 --input-csp i420 --profile main10 --colormatrix bt709 --colorprim bt709 --transfer bt709 --preset slower --rc-lookahead 72 --keyint 360 --min-keyint 23 --subme 5 --qcomp 0.7 --crf 15 --aq-mode 3 --aq-strength 0.9 --bframes 16 --psy-rd 0.95 --psy-rdoq 1.8 --rdoq-level 1 --deblock -2:-2 --no-sao --no-open-gop --frames {frames:d} --output {filename:s}.h265 diff --git a/yt_common/yt_common/__init__.py b/yt_common/yt_common/__init__.py index cd4253b..2ba26f8 100644 --- a/yt_common/yt_common/__init__.py +++ b/yt_common/yt_common/__init__.py @@ -1,3 +1 @@ -from .config import Config # noqa: F401 -from .automation import SelfRunner # noqa: F401 -from .source import DehardsubFileFinder, FunimationSource # noqa: F401 +from . import config, automation, logging, source # noqa: F401 diff --git a/yt_common/yt_common/automation.py b/yt_common/yt_common/automation.py index 501be62..1b8e1e8 100644 --- a/yt_common/yt_common/automation.py +++ b/yt_common/yt_common/automation.py @@ -9,7 +9,7 @@ import subprocess from typing import Any, BinaryIO, Callable, List, Optional, Sequence, Union, cast from .config import Config -from .log import status, warn, error, success +from .logging import log from .source import AMAZON_FILENAME, ER_FILENAME, SUBSPLS_FILENAME, FUNI_INTRO, glob_crc core = vs.core @@ -26,7 +26,7 @@ def bin_to_plat(binary: str) -> str: def forward_signal(signum: int, frame: Any, process: Any) -> None: - warn("Forwarding SIGINT") + log.warn("Forwarding SIGINT") process.send_signal(signum) @@ -55,12 +55,12 @@ class Encoder(): outfile = self.out_template.format(filename=filename) if os.path.isfile(outfile) and not self.force: - warn("Existing output detected, skipping encode!") + log.warn("Existing output detected, skipping encode!") return outfile params = [p.format(frames=end-start, filename=filename) for p in self.params] - status("--- RUNNING ENCODE ---") + log.status("--- RUNNING ENCODE ---") print("+ " + " ".join([self.binary] + list(params))) @@ -76,10 +76,10 @@ class Encoder(): # vapoursynth should handle this itself but just in case if process.returncode != 0: - error("--- ENCODE FAILED ---") + log.error("--- ENCODE FAILED ---") raise BrokenPipeError(f"Pipe to {self.binary} broken") - success("--- ENCODE FINISHED ---") + log.success("--- ENCODE FINISHED ---") self.cleanup.append(outfile) return outfile @@ -136,7 +136,7 @@ class AudioGetter(): if os.path.isfile(self.config.format_filename(AMAZON_FILENAME)): self.audio_file = self.config.format_filename(AMAZON_FILENAME) self.video_src = core.ffms2.Source(self.audio_file) - success("Found Amazon audio") + log.success("Found Amazon audio") return # as of Ep4 SubsPlease is using new funi 128kbps aac while erai has 256kbps still @@ -147,15 +147,15 @@ class AudioGetter(): elif os.path.isfile(glob_crc(self.config.format_filename(SUBSPLS_FILENAME))): self.audio_file = glob_crc(self.config.format_filename(SUBSPLS_FILENAME)) self.video_src = core.ffms2.Source(self.audio_file) - warn("Using SubsPlease, audio may be worse than Erai-Raws") + log.warn("Using SubsPlease, audio may be worse than Erai-Raws") else: raise FileNotFoundError() except FileNotFoundError: - error("Could not find audio") + log.error("Could not find audio") raise self.audio_start = FUNI_INTRO - warn("No Amazon audio, falling back to Funi") + log.warn("No Amazon audio, falling back to Funi") def trim_audio(self, src: vs.VideoNode, trims: Union[acsuite.Trim, List[acsuite.Trim], None] = None) -> str: @@ -213,11 +213,11 @@ class SelfRunner(): parser.add_argument("-s", "--start", nargs='?', type=int, help="Start encode at frame START") parser.add_argument("-e", "--end", nargs='?', type=int, help="Stop encode at frame END (inclusive)") parser.add_argument("-k", "--keep", help="Keep raw video", action="store_true") - parser.add_argument("-c", "--encoder", type=str, help="Override detected encoder binary") + parser.add_argument("-b", "--encoder", type=str, help="Override detected encoder binary") parser.add_argument("-f", "--force", help="Overwrite existing intermediaries", action="store_true") parser.add_argument("-a", "--audio", type=str, help="Force audio file") parser.add_argument("-x", "--suffix", type=str, help="Change the suffix of the mux") - parser.add_argument("-d", "--no-metadata", help="No extra metadata in premux", action="store_true") + parser.add_argument("-c", "--no-chapters", help="No chapters in premux", action="store_true") args = parser.parse_args() self.workraw = args.workraw if workraw_filter else False @@ -226,10 +226,10 @@ class SelfRunner(): self.clip = workraw_filter() if workraw_filter and self.workraw else final_filter() basename = "workraw-settings" if self.workraw else "final-settings" - settings_path = os.path.join(os.path.dirname(__file__), basename) + settings_path = os.path.join(self.config.datapath, basename) if not os.path.isfile(settings_path): - raise FileNotFoundError("Failed to find {basename}!") + raise FileNotFoundError(f"Failed to find {settings_path}!") start = args.start if args.start is not None else 0 if args.end is not None: @@ -254,33 +254,32 @@ class SelfRunner(): self.encoder = Encoder(self.config.epnum, settings_path, args.encoder, args.force) self.video_file = self.encoder.encode(self.clip, f"{self.config.epnum:02d}_{start}_{end}", start, end) - status("--- LOOKING FOR AUDIO ---") + log.status("--- LOOKING FOR AUDIO ---") self.audio = AudioGetter(self.config, args.audio) - status("--- TRIMMING AUDIO ---") + log.status("--- TRIMMING AUDIO ---") self.audio_file = self.audio.trim_audio(self.clip, (start, end)) try: - status("--- MUXING FILE ---") + log.status("--- MUXING FILE ---") if self._mux(f"{self.config.title.lower()}_{self.config.epnum:02d}_{self.suffix}.mkv", - not args.no_metadata, - not args.no_metadata and start == 0 and end == self.clip.num_frames) != 0: + not args.no_chapters and start == 0 and end == self.clip.num_frames) != 0: raise Exception("mkvmerge failed") except Exception: - error("--- MUXING FAILED ---") + log.error("--- MUXING FAILED ---") self.audio.do_cleanup() raise - success("--- MUXING SUCCESSFUL ---") + log.success("--- MUXING SUCCESSFUL ---") self.audio.do_cleanup() if not args.keep: self.encoder.do_cleanup() - success("--- ENCODE COMPLETE ---") + log.success("--- ENCODE COMPLETE ---") - def _mux(self, name: str, metadata: bool = True, chapters: bool = True) -> int: + def _mux(self, name: str, chapters: bool = True) -> int: mkvtoolnix_args = [ "mkvmerge", "--output", name, @@ -292,11 +291,6 @@ class SelfRunner(): "(", self.audio_file, ")", "--track-order", "0:0,0:1", ] - if metadata: - mkvtoolnix_args += [ - "--title", f"[{self.config.subgroup}] {self.config.title_long} - {self.config.epnum:02d}", - ] - if chapters: chap = [f for f in [f"{self.config.epnum:02d}.xml", "chapters.xml"] if os.path.isfile(f)] if len(chap) != 0: diff --git a/yt_common/yt_common/config.py b/yt_common/yt_common/config.py index 9d10bee..e9e9bb5 100644 --- a/yt_common/yt_common/config.py +++ b/yt_common/yt_common/config.py @@ -4,7 +4,6 @@ class Config(): title_long: str resolution: int datapath: str - subgroup: str def __init__(self, epnum: int, title: str, title_long: str, resolution: int, datapath: str) -> None: self.epnum = epnum diff --git a/yt_common/yt_common/log.py b/yt_common/yt_common/log.py deleted file mode 100644 index b50f201..0000000 --- a/yt_common/yt_common/log.py +++ /dev/null @@ -1,23 +0,0 @@ -# TODO: real logging shit not this jank-ass crap - -STATUS: str = '\033[94m' -WARNING: str = '\033[93m' -ERROR: str = '\033[91m' -SUCCESS: str = '\033[92m' -RESET: str = '\033[0m' - - -def status(s: str) -> None: - print(f"{STATUS}{s}{RESET}") - - -def warn(s: str) -> None: - print(f"{WARNING}{s}{RESET}") - - -def error(s: str) -> None: - print(f"{ERROR}{s}{RESET}") - - -def success(s: str) -> None: - print(f"{SUCCESS}{s}{RESET}") diff --git a/yt_common/yt_common/logging.py b/yt_common/yt_common/logging.py new file mode 100644 index 0000000..823ce15 --- /dev/null +++ b/yt_common/yt_common/logging.py @@ -0,0 +1,25 @@ +# TODO: real logging shit not this jank-ass crap + +STATUS: str = '\033[94m' +WARNING: str = '\033[93m' +ERROR: str = '\033[91m' +SUCCESS: str = '\033[92m' +RESET: str = '\033[0m' + + +class log(): + @staticmethod + def status(s: str) -> None: + print(f"{STATUS}{s}{RESET}") + + @staticmethod + def warn(s: str) -> None: + print(f"{WARNING}{s}{RESET}") + + @staticmethod + def error(s: str) -> None: + print(f"{ERROR}{s}{RESET}") + + @staticmethod + def success(s: str) -> None: + print(f"{SUCCESS}{s}{RESET}") diff --git a/yt_common/yt_common/source.py b/yt_common/yt_common/source.py index dcd7344..84115ab 100644 --- a/yt_common/yt_common/source.py +++ b/yt_common/yt_common/source.py @@ -2,6 +2,9 @@ import vapoursynth as vs import vsutil +from lvsfunc.types import Range +import lvsfunc as lvf + import glob import os @@ -9,7 +12,7 @@ from abc import ABC, abstractmethod from typing import List, Tuple from .config import Config -from .log import warn, error, success +from .logging import log core = vs.core @@ -19,6 +22,21 @@ FUNI_INTRO: int = 289 AMAZON_FILENAME: str = "{title_long} - {epnum:02d} (Amazon Prime CBR {resolution}p).mkv" +def waka_replace(src: vs.VideoNode, wakas: List[vs.VideoNode], ranges: List[List[Range]] + ) -> Tuple[vs.VideoNode, List[vs.VideoNode]]: + if len(wakas) == 0: + return src, wakas + if len(ranges) != len(wakas): + raise ValueError("waka_replace: 'Different number of range sets and wakas supplied'!") + new_wakas = [] + for waka, r in zip(wakas, ranges): + tmp = src + src = lvf.misc.replace_ranges(src, waka, r) + new_wakas.append(lvf.misc.replace_ranges(waka, tmp, r)) + + return src, new_wakas + + def glob_crc(pattern: str) -> str: res = glob.glob(glob.escape(pattern).replace("$CRC", "*")) if len(res) == 0: @@ -50,16 +68,16 @@ class DehardsubFileFinder(ABC): class FunimationSource(DehardsubFileFinder): def get_amazon(self) -> vs.VideoNode: if not os.path.isfile(self.config.format_filename(AMAZON_FILENAME)): - warn("Amazon not found, falling back to Funimation") + log.warn("Amazon not found, falling back to Funimation") raise FileNotFoundError() - success("Found Amazon video") + log.success("Found Amazon video") return core.ffms2.Source(self.config.format_filename(AMAZON_FILENAME)) def get_funi_filename(self) -> str: if os.path.isfile(self.config.format_filename(ER_FILENAME)): return self.config.format_filename(ER_FILENAME) - error("Erai-raws not found, falling back to SubsPlease") + log.error("Erai-raws not found, falling back to SubsPlease") return glob_crc(self.config.format_filename(SUBSPLS_FILENAME)) def get_funi(self) -> vs.VideoNode: