diff --git a/backend-java/src/main/java/com/tasteby/service/YouTubeService.java b/backend-java/src/main/java/com/tasteby/service/YouTubeService.java index fcf8e44..34f29dc 100644 --- a/backend-java/src/main/java/com/tasteby/service/YouTubeService.java +++ b/backend-java/src/main/java/com/tasteby/service/YouTubeService.java @@ -59,6 +59,7 @@ public class YouTubeService { String uploadsPlaylistId = "UU" + channelId.substring(2); List> allVideos = new ArrayList<>(); String nextPage = null; + boolean stopPaging = false; try { do { @@ -88,7 +89,7 @@ public class YouTubeService { // publishedAfter 필터: 이미 스캔한 영상 이후만 if (publishedAfter != null && publishedAt.compareTo(publishedAfter) <= 0) { // 업로드 재생목록은 최신순이므로 이전 날짜 만나면 중단 - nextPage = null; + stopPaging = true; break; } @@ -105,7 +106,9 @@ public class YouTubeService { } allVideos.addAll(pageVideos); - if (nextPage != null || data.has("nextPageToken")) { + if (stopPaging) { + nextPage = null; + } else { nextPage = data.has("nextPageToken") ? data.path("nextPageToken").asText() : null; } } while (nextPage != null);