def patch( self, ranges: Union[Union[int, Tuple[int, int]], List[Union[int, Tuple[int, int]]]], clean_up: bool = True, external_file: Optional[Union[os.PathLike[str], str]] = None) -> None: """ :ranges: Frame ranges that require patching. Expects as a list of tuples or integers (can be mixed). Examples: [(0, 100), (400, 600)]; [50, (100, 200), 500] :param clean_up: Perform clean-up procedure after patching :external_file: File to patch into. This is intended for videos like NCs with only one or two changes so you don't need to encode the entire thing multiple times. It will copy the given file and rename it to ``FileInfo.name_file_final``. If None, performs regular patching. """ v_encoder = X265Encoder('settings/x265_settings') self.clip = dither_down(self.clip) if external_file: if os.path.exists(external_file): Status.info( f"Copying {external_file} to {self.file.name_file_final}") shutil.copy(external_file, self.file.name_file_final) else: Status.warn( f"{self.file.name_file_final} already exists; please ensure it's the correct file!" ) runner = Patch( clip=self.clip, ranges=ranges, # type:ignore[arg-type] encoder=v_encoder, file=self.file, ) runner.run() new = f"{self.file.name_file_final.to_str()[:-4]}_new.mkv" Status.info(f"Replacing {self.file.name_file_final} -> {new}") os.replace(new, self.file.name_file_final) if clean_up: runner.do_cleanup()
def pick_settings(f: FileInfo) -> str: ep = f.name[-2:] try: int(ep) except ValueError: ep = f.name[-3:] base = 'settings/x265_settings_BD' settings_file = f'{base}_{ep}' if not os.path.exists(settings_file): # Double-check, there's probably a nicer way to write out there but oh well ep = f.name[-7:] settings_file = f'{base}_{ep}' if not os.path.exists(settings_file): Status.warn(f"Couldn't find \"{settings_file}\"; falling back to default settings") settings_file = base else: Status.info(f"Succesfully found {settings_file}") return settings_file
def appendCRC(f: Union[str, VPath]) -> None: from vardautomation.status import Status Status.info("Calculating CRC...") basename = str(f) crc = calculateCRC(basename) Status.info(f"CRC: {crc}") filename = f'{os.path.splitext(basename)[0]} [{crc}]{os.path.splitext(basename)[1]}' Status.info(f'Renaming {basename} -> {filename}') os.rename(basename, filename)
def run(self, clean_up: bool = True, make_comp: bool = True) -> None: """ :param clean_up: Perform clean-up procedure after encoding :param make_comp: Create a slowpics-compatible comparison between src, flt, and enc """ assert self.file.a_src is_dvd = False if self.file.clip.width > 1280 else True if is_dvd: Status.info("DVD encode detected: Switching over to DVD settings") x265_settings = 'settings/x265_settings' if not is_dvd else 'settings/x265_settings_dvd' msg = 'HEVC BDRip by LightArrowsEXE@Kaleido' if not is_dvd else 'HEVC DVDrip by LightArrowsEXE@Kaleido' v_encoder = X265Encoder(x265_settings) self.clip = dither_down(self.clip) audio_files = video_source(self.file.path.to_str(), trim_list=resolve_trims( self.file.trims_or_dfs), trims_framerate=self.file.clip.fps, flac=False, aac=True, silent=False) if not is_dvd: audio_tracks: List[AudioStream] = [] for track in audio_files: audio_tracks += [ AudioStream(VPath(track), 'AAC 2.0', JAPANESE, XML_TAG) ] else: a_extracters = FfmpegAudioExtracter(self.file, track_in=0, track_out=0) a_cutters = EztrimCutter(self.file, track=1) audio_tracks = AudioStream(self.file.a_src_cut.set_track(1), 'AC-3 2.0', JAPANESE) if self.chapter_list: assert self.file.chapter assert self.file.trims_or_dfs if not isinstance(self.chapter_offset, int): self.chapter_offset = self.file.trims_or_dfs[ 0] * -1 # type: ignore chapxml = MatroskaXMLChapters(self.file.chapter) chapxml.create(self.chapter_list, self.file.clip.fps) chapxml.shift_times(self.chapter_offset, self.file.clip.fps) # type: ignore chapxml.set_names(self.chapter_names) chapters = ChapterStream(chapxml.chapter_file, JAPANESE) muxer = Mux(self.file, streams=(VideoStream(self.file.name_clip_output, msg, JAPANESE), audio_tracks, chapters if self.chapter_list else None)) if not is_dvd: config = RunnerConfig(v_encoder, None, None, None, None, muxer) else: config = RunnerConfig(v_encoder, None, a_extracters, a_cutters, None, muxer) runner = SelfRunner(self.clip, self.file, config) runner.run() try: if make_comp: generate_comparison(self.file, self.file.name_file_final.to_str(), self.clip) except ValueError as e: Status.fail(str(e)) if clean_up: runner.do_cleanup()