import imageio
import numpy as np
import os


class DoubleGif(object):
    def __init__(self, storage):
        self.storage = storage

    def get(self, raw: []) -> []:
        self.storage.download_file(raw[0], 'temp.gif')
        reader = imageio.get_reader('temp.gif')
        out1 = np.array([frame for frame in reader])
        reader.close()
        os.remove('temp.gif')
        self.storage.download_file(raw[1], 'temp.gif')
        reader = imageio.get_reader('temp.gif')
        out2 = np.array([frame for frame in reader])
        reader.close()
        os.remove('temp.gif')
        return out1, out2

    def put(self, val: []) -> []:
        imageio.mimsave('temp.gif', val[0], fps=60)
        key1 = self.storage.upload_file('temp.gif')
        os.remove('temp.gif')
        imageio.mimsave('temp.gif', val[1], fps=60)
        key2 = self.storage.upload_file('temp.gif')
        os.remove('temp.gif')
        return [key1, key2]
