from django.views import View

from CeleryTask.TimeAlbumTask import generate_video
from Object.ResponseObject import ResponseObject


class TimeAlbum(View):
    def get(self, request, *args, **kwargs):
        request.encoding = 'utf-8'
        operation = kwargs.get('operation')
        request_dict = request.GET
        return self.validation(request, request_dict, operation)

    def post(self, request, *args, **kwargs):
        request.encoding = 'utf-8'
        operation = kwargs.get('operation')
        request_dict = request.POST
        return self.validation(request, request_dict, operation)

    def validation(self, request, request_dict, operation):
        language = request_dict.get('language', 'en')
        response = ResponseObject(language)
        if operation == 'createTimeAlbum':
            return self.create_time_album(response)
        else:
            return response.json(414)

    @staticmethod
    def create_time_album(response):
        # 从AWS桶获取图片链接

        # 下载图片保存地址

        # 收集图片文件路径
        image_files = ['static/temp/image1.jpg', 'static/temp/image2.jpg',
                       'static/temp/image3.jpg', 'static/temp/image4.jpg',
                       'static/temp/image5.jpg']

        output_path = 'static/temp'

        # 调用 Celery 任务
        generate_video.delay(image_files, output_path)
        return response.json(0)
