package com.cab.controller;

import com.cab.service.CabLiveContentServiceImpl;
import com.cab.service.ContentServiceImpl;
import com.cku.upyun.ImageFtp;
import com.cku.upyun.VideoInfoService;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.IOException;

/**
 * Created by user on 2016/6/28.
 */
public class UploadFileToYun implements Runnable{
    private static final Logger logger = Logger.getLogger(UploadVideoToYun.class);
    private String newFileName;
    private String videoFile;
    private Long conentId;
    private CabLiveContentServiceImpl cabLiveContentService;


    public UploadFileToYun(Long conentId, CabLiveContentServiceImpl cabLiveContentService, String videoFile, String newFileName) {
        this.newFileName = newFileName;
        this.videoFile = videoFile;
        this.conentId = conentId;
        this.cabLiveContentService = cabLiveContentService;
    }

    public void run() {
        try {
            logger.info("========================uploadstart:"+conentId+"============================"+System.currentTimeMillis());
            String result = ImageFtp.uploadFile(ImageFtp.VIDEO_PATH_TEST, newFileName, videoFile + File.separator + newFileName);
            String time = VideoInfoService.getVideoTime(result);
            cabLiveContentService.updateTime(conentId,time);
            logger.info("========================uploadend:"+conentId+"============================"+System.currentTimeMillis());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
