feat : 유튜브 영상 설명도 홈페이지 콜백에 함께 전달
deploy / deploy (push) Successful in 25s

yt-dlp --write-description 으로 받은 .description을 읽어 콜백에 싣고 삭제.
설명 파일만 남은 경우를 다운로드 성공으로 착각하지 않도록 checkFileExists에서 제외.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-11-30 11:13:58 +09:00
1 parent dd8dff54a8
commit 991044fe44
1 file changed
+15 -9
+15 -9
View File
@@ -345,6 +345,7 @@ public class DiscordDownloadBot extends ListenerAdapter {
cmdList.add("--merge-output-format"); cmdList.add("--merge-output-format");
cmdList.add("mp4"); cmdList.add("mp4");
cmdList.add("--newline"); // 진행률을 같은 줄 덮어쓰기 대신 한 줄씩 출력 → readLine으로 읽힘 cmdList.add("--newline"); // 진행률을 같은 줄 덮어쓰기 대신 한 줄씩 출력 → readLine으로 읽힘
cmdList.add("--write-description"); // 영상 설명을 "파일명.description"으로 → readCaption이 읽고 지움
cmdList.add("-o"); cmdList.add("-o");
cmdList.add(saveDir + File.separator + "%(title)s_%(id)s_Video" + index + ".%(ext)s"); cmdList.add(saveDir + File.separator + "%(title)s_%(id)s_Video" + index + ".%(ext)s");
@@ -427,17 +428,18 @@ public class DiscordDownloadBot extends ListenerAdapter {
} }
} }
// 인스타 게시물 설명글: gallery-dl이 남긴 .json에서 꺼내고, .json은 지움 (게시판에 파일로 보이지 않게) // 설명글: 인스타는 gallery-dl이 남긴 .json의 description, 유튜브는 yt-dlp가 남긴 .description (글 그대로)
// 설명글이 없으면(유튜브 등) null // 읽은 뒤 지움 (게시판에 파일로 보이지 않게). 설명글이 없으면 null
private static String readCaption(String saveDir) { private static String readCaption(String saveDir) {
File[] jsons = new File(saveDir).listFiles((d, n) -> n.endsWith(".json")); File[] metas = new File(saveDir).listFiles(DiscordDownloadBot::isMetaFile);
if (jsons == null) return null; if (metas == null) return null;
String caption = null; String caption = null;
for (File f : jsons) { for (File f : metas) {
if (caption == null) { if (caption == null) {
try { try {
String text = DataObject.fromJson(new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8)) String text = new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8);
.getString("description", "").trim(); if (f.getName().endsWith(".json")) text = DataObject.fromJson(text).getString("description", "");
text = text.trim();
if (!text.isEmpty()) caption = text; if (!text.isEmpty()) caption = text;
} catch (Exception e) { /* 읽기 실패면 설명 없이 진행 */ } } catch (Exception e) { /* 읽기 실패면 설명 없이 진행 */ }
} }
@@ -446,6 +448,10 @@ public class DiscordDownloadBot extends ListenerAdapter {
return caption; return caption;
} }
private static boolean isMetaFile(File dir, String name) {
return name.endsWith(".json") || name.endsWith(".description");
}
// 파일 생성 확인 함수 // 파일 생성 확인 함수
private boolean checkFileExists(String saveDir, String keyword) { private boolean checkFileExists(String saveDir, String keyword) {
File dir = new File(saveDir); File dir = new File(saveDir);
@@ -453,8 +459,8 @@ public class DiscordDownloadBot extends ListenerAdapter {
if (files == null) return false; if (files == null) return false;
for (File f : files) { for (File f : files) {
// 방금 다운로드 시도한 파일(키워드 포함)이 존재하면 성공 // 방금 다운로드 시도한 파일(키워드 포함)이 존재하면 성공. 설명 파일만 있는 건 실패
if (f.getName().contains(keyword)) { if (f.getName().contains(keyword) && !isMetaFile(dir, f.getName())) {
return true; return true;
} }
} }