package com.yutou.qqbot.Controllers;

import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.BiliBili.BiliVideo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BiliBiliController {
    @RequestMapping("/bilibili/down.do")
    @ResponseBody
    public JSONObject downloadBili(String data) {
        new Thread(() -> {
            JSONObject json = JSONObject.parseObject(data);
            System.out.println("json = " + json);
            String url = json.getString("url");
            boolean downDanmu = json.containsKey("danmu") && "on".equals(json.getString("danmu"));
            boolean merge = json.containsKey("merge") && "on".equals(json.getString("merge"));
            BiliVideo video = new BiliVideo(QQBotManager.defQQ);
            video.downVideo(url, downDanmu, merge);
        }
        ).start();
        JSONObject json = new JSONObject();
        json.put("msg", "ok");
        json.put("code", 0);
        return json;
    }
}
