first
This commit is contained in:
parent
a09fa58251
commit
6fe5259048
12
README.md
12
README.md
|
@ -1,3 +1,9 @@
|
|||
# van
|
||||
|
||||
.van player and converter
|
||||
# .van player and converter
|
||||
|
||||
in this repo:
|
||||
`van.py` - plays .van files
|
||||
`van_convert.py` - converts folder of .txt (numbered like 1.txt, 2.txt, etc) to one .van file
|
||||
|
||||
.van stands for Mr**V an**imation btw
|
||||
|
||||
Made by MrV 2023
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os, time, argparse, platform
|
||||
|
||||
if platform.system() == "Windows":
|
||||
clr = "cls"
|
||||
else:
|
||||
clr = "clear"
|
||||
|
||||
parser = argparse.ArgumentParser(description="plays .van files", epilog="Made by MrV on IRC")
|
||||
parser.add_argument("file", help="path of file to play")
|
||||
parser.add_argument("-s", "--speed", help="time between frames in seconds (default: 0)", default=0)
|
||||
parser.add_argument("-e", "--encoding", help="text encoding (default: ascii)", default="ascii")
|
||||
args = parser.parse_args()
|
||||
file = args.file
|
||||
speed = float(args.speed)
|
||||
encoding = args.encoding
|
||||
|
||||
print("Reading...")
|
||||
with open(file, "rb") as f:
|
||||
raw = f.read()
|
||||
data = raw.split(b"\x1b<VAN>\x1b")
|
||||
|
||||
os.system(clr)
|
||||
for frame in data:
|
||||
print(frame.decode(encoding))
|
||||
time.sleep(speed)
|
||||
os.system(clr)
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import glob, os, time, re, argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="converts a folder of animation frames (.txt) to .van", epilog="Made by MrV on IRC")
|
||||
parser.add_argument("dirpath", help="path of folder to convert")
|
||||
parser.add_argument("-o", "--output", help="path of output file (.van)", required=True)
|
||||
args = parser.parse_args()
|
||||
dirpath = args.dirpath
|
||||
outpath = args.output
|
||||
|
||||
print("Preparing...")
|
||||
files = glob.glob(os.path.join(dirpath, "*.txt"))
|
||||
# https://stackoverflow.com/a/53694164 :)
|
||||
files = sorted(files, key=lambda x:float(re.findall("(\d+)",x)[0]))
|
||||
|
||||
print("Reading...")
|
||||
frames = []
|
||||
for file in files:
|
||||
with open(file, "rb") as f:
|
||||
raw = f.read()
|
||||
frames.append(raw)
|
||||
|
||||
print("Writing...")
|
||||
output = b"\x1b<VAN>\x1b".join(frames)
|
||||
with open(outpath, "wb") as h:
|
||||
h.write(output)
|
||||
print("Saved to " + outpath)
|
Loading…
Reference in New Issue