This repository has been archived on 2024-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
MiraiNikkiBot/tools/convert.py

66 lines
2.2 KiB
Python
Raw Permalink Normal View History

#! /usr/bin/env python3
import sys
import importlib
import os
import argparse
def get_modded_range(ranges, endseconds, fps, endframe):
d = []
multiply_factor = endframe / (fps * endseconds)
for i in ranges:
begin = int(i[0] * multiply_factor)
end = int(i[1] * multiply_factor)
d.append((begin, end))
return d
def is_in_range(ranges, frame):
for i in ranges:
if frame in range(i[0], i[1] + 1):
return True
return False
def main():
DEFAULT_CFG="cfg"
DEFAULT_FPS=24
# Parser
parser = argparse.ArgumentParser(
description="CLI tool to help convert time to frames. MiraiNikkiFrameBot is being depricated in favor of pre-rendered frames posted using YandereLewdBot",
epilog="See YandereLewdBot for examples on how to post frames.",
add_help=True)
parser.add_argument("-c", "--config", help="Set custom config file (Default: {})".format(DEFAULT_CFG))
parser.add_argument("-f", "--fps", help="Set fps manually (Default: {})".format(str(DEFAULT_FPS)), type=int, default=DEFAULT_FPS)
parser.add_argument("-r", "--ranges", help="Show time ranges of skip and nsfw converted into frames and exit", action="store_true")
parser.add_argument("profile", help="The index of settings_post to operate on", type=int)
parser.add_argument("endframe", help="The final frame count of the new pre-rendered frames", type=int)
arguments = parser.parse_args()
cfg = importlib.import_module(arguments.config)
settings_post = cfg.settings_post[arguments.profile]
setting_skip = get_modded_range(settings_post["skip"], settings_post["frames"], arguments.fps, arguments.endframe)
setting_nsfw = get_modded_range(settings_post["nsfw"], settings_post["frames"], arguments.fps, arguments.endframe)
if arguments.ranges:
print("Settings Skip:")
print(setting_skip)
print("Settings NSFW:")
print(setting_nsfw)
return 0
print(settings_post["profile_name"])
for i in range(1, arguments.endframe + 1):
status = "safe"
frame_name = os.path.basename(settings_post["output_name"].replace("${frame}", str(i).zfill(5)))
if is_in_range(setting_skip, i):
status = "skip"
elif is_in_range(setting_nsfw, i):
status = "nsfw"
print("mv -nv '{}' '{}'".format(str(frame_name), "{}/".format(status)))
return 0
if __name__ == "__main__":
sys.exit(main())