package com.chuanxia.mcp.controller;

import com.chuanxia.mcp.bean.model.VideoM3u8;
import com.chuanxia.mcp.bean.vo.Result;
import com.chuanxia.mcp.sched.M3U8Utils;
import com.chuanxia.mcp.service.VideoM3u8Service;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api("m3u8")
@RequestMapping("cdnM3U8")
@RequiredArgsConstructor
public class CdnM3u8Controller {
    private final M3U8Utils m3U8Utils;
    private final VideoM3u8Service m3u8Service;

    @GetMapping("test")
    public Result test(@RequestParam("baseUrl") String url,
                       @RequestParam("videoId") String videoId) {
        List<VideoM3u8> videoM3u8s = m3U8Utils.downloadM3U8(url, videoId);
        m3u8Service.saveBatch(videoM3u8s);
        return Result.success("操作成功");
    }
}
