test pattern command

workspace
km0 3 years ago
parent 444490a3f3
commit 624012884e

@ -25,7 +25,7 @@ class Soup(Bureau):
Bureau.__init__(self)
@add_command("1sentence", "1 Sentence Game Ideas")
def print_fortune(self):
def print_game(self):
"""
Prints one entry from the one sentence game ideas.
"""
@ -37,63 +37,18 @@ class Soup(Bureau):
self.print_small(game)
@add_api("gif", "Moving Picture")
def print_gif(self, data):
@add_command("ptrn", 'Set Pattern')
def print_pattern(self, data):
"""
Prints out a series of image frames which can be viewed in lively
motion on any standard zoetrope. (Ø200mm)
Prints the pattern sent by the arduino
"""
# download the video file
d_url = data["url"]
filename, headers = urllib.request.urlretrieve(d_url)
print("fetching", d_url, filename)
# make sure we have a legit filename
ext = mimetypes.guess_extension(headers["Content-Type"])
if not filename.endswith(ext):
os.rename(filename, filename + ext)
filename = filename + ext
print("renamed to ", filename)
# if we have something that's a gif or webp (png?) then
# just print 12 frames
if filename.endswith(("gif", "webp")):
print("gif stuff")
img = Image.open(filename)
print(img.n_frames)
grab_frame = 0
out_frame = 0
in_len = float(img.n_frames)
# TODO: deal with frame counts lower than 12
# and maybe a different algo that includes endpoints
for frame in range(img.n_frames):
img.seek(frame)
if grab_frame == frame:
img_rotated = img.rotate(90, expand=True)
self.print_small_image(img_rotated)
out_frame += 1
grab_frame = math.ceil(out_frame * in_len / 12)
else:
# how many frames do we have?
cli = "ffprobe -i " + filename + \
" -show_format -v quiet | sed -n 's/duration=//p'"
vid_len = str(subprocess.check_output(cli), encoding="UTF-8")
print("video len: " + vid_len)
# TODO: if vid_len is not a number handle this error
# lengthen/shorten it to 12 frames
# dump frames to temp files
cli = "ffmpeg -i" + filename + " -vf fps=12/" + vid_len +\
" thumb%02d.png"
# print em out!
self.print_small("")
shortcode, _ = data.split(".")
self.print_small(_)
def main():
ha = Soup()
ha.run()
sb = Soup()
sb.run()
if __name__ == "__main__":

Loading…
Cancel
Save