65 lines
2.7 KiB
Java
65 lines
2.7 KiB
Java
package com.hlab.yanalyst.web;
|
|
|
|
import com.hlab.yanalyst.domain.channel.Channel;
|
|
import com.hlab.yanalyst.domain.channel.ChannelVideo;
|
|
import com.hlab.yanalyst.domain.channel.ChannelService;
|
|
import com.hlab.yanalyst.global.common.ApiResponse;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@Controller
|
|
@RequiredArgsConstructor
|
|
@Tag(name = "Channel Detail", description = "Channel Detail & Video Management")
|
|
public class ChannelDetailController {
|
|
|
|
private final ChannelService channelService;
|
|
|
|
@GetMapping("/channels/{id}")
|
|
public String channelDetail(@PathVariable("id") Long id, Model model) {
|
|
Channel channel = channelService.getChannel(id);
|
|
model.addAttribute("channel", channel);
|
|
model.addAttribute("videos", channelService.getChannelVideos(id));
|
|
return "channel_detail";
|
|
}
|
|
|
|
@GetMapping("/channels/videos")
|
|
public String channelsVideos(@RequestParam("ids") java.util.List<Long> ids, Model model) {
|
|
java.util.List<Channel> channels = channelService.getChannelsByIds(ids);
|
|
java.util.List<String> selectedYoutubeIds = channels.stream()
|
|
.map(Channel::getChannelId)
|
|
.toList();
|
|
|
|
model.addAttribute("channels", channels);
|
|
model.addAttribute("selectedYoutubeIds", selectedYoutubeIds);
|
|
return "multi_channel_videos";
|
|
}
|
|
|
|
@PostMapping("/api/channels/{id}/sync")
|
|
@ResponseBody
|
|
@Operation(summary = "Sync Channel Videos", description = "Fetch and sync all videos from the channel's upload playlist.")
|
|
public ApiResponse<String> syncChannelVideos(@PathVariable("id") Long id) {
|
|
channelService.collectChannelVideos(id);
|
|
return ApiResponse.ok("Synced successfully");
|
|
}
|
|
|
|
@PostMapping("/api/channels/videos/{videoId}/script")
|
|
@ResponseBody
|
|
@Operation(summary = "Extract Script", description = "Extract transcript for a specific video.")
|
|
public ApiResponse<Void> extractScript(@PathVariable("videoId") Long videoId) {
|
|
channelService.extractScript(videoId);
|
|
return ApiResponse.ok(null);
|
|
}
|
|
|
|
@PostMapping("/api/channels/{channelId}/scripts/all")
|
|
@ResponseBody
|
|
@Operation(summary = "Extract All Scripts", description = "Extract transcripts for all videos in the channel.")
|
|
public ApiResponse<String> extractAllScripts(@PathVariable("channelId") Long channelId) {
|
|
channelService.extractAllScripts(channelId);
|
|
return ApiResponse.ok("Bulk extraction completed");
|
|
}
|
|
}
|