mirror of
https://github.com/headporter81/DiscordDownloaderBot.git
synced 2026-12-06 07:41:10 +09:00
gallery-dl --write-metadata 로 받은 .json에서 description을 꺼내 완료 콜백에 싣고, .json은 삭제. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f97f1372a0
commit
dd8dff54a8
1 file changed
+28
-2
@@ -24,6 +24,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -148,9 +149,12 @@ public class DiscordDownloadBot extends ListenerAdapter {
|
||||
.put("progress", percent).put("speed", speed == null ? "" : speed));
|
||||
};
|
||||
Result result = download(url, saveDir, progress);
|
||||
String caption = readCaption(saveDir);
|
||||
System.out.println("🌐 [HTTP] " + folder + " ← " + url + " : " + result);
|
||||
if (!callbackUrl.isEmpty()) {
|
||||
sendCallback(callbackUrl, DataObject.empty().put("folder", folder).put("result", result.name()));
|
||||
DataObject done = DataObject.empty().put("folder", folder).put("result", result.name());
|
||||
if (caption != null) done.put("description", caption);
|
||||
sendCallback(callbackUrl, done);
|
||||
}
|
||||
});
|
||||
send(ex, 202, DataObject.empty().put("status", "accepted").put("folder", folder));
|
||||
@@ -303,7 +307,9 @@ public class DiscordDownloadBot extends ListenerAdapter {
|
||||
try {
|
||||
progressMessage = channel.sendMessage("⏳ **다운로드 시도 중...**").complete();
|
||||
String folder = new File(saveDir).getName();
|
||||
switch (download(url, saveDir, null)) {
|
||||
Result result = download(url, saveDir, null);
|
||||
readCaption(saveDir); // 디스코드는 설명글을 안 쓰지만 .json 파일은 정리
|
||||
switch (result) {
|
||||
case VIDEO:
|
||||
progressMessage.editMessage("✅ **동영상 다운로드 완료!**\n📂 폴더: `" + folder + "`").queue();
|
||||
break;
|
||||
@@ -389,6 +395,7 @@ public class DiscordDownloadBot extends ListenerAdapter {
|
||||
cmdList.add(COOKIES_PATH);
|
||||
cmdList.add("-D"); // 하위 폴더 없이 saveDir에 바로 저장
|
||||
cmdList.add(saveDir);
|
||||
cmdList.add("--write-metadata"); // 파일마다 "파일명.json" (게시물 설명글이 들어 있음) → readCaption이 읽고 지움
|
||||
// 파일명 "이름_코드_Video1.mp4" / "이름_코드_Image2.jpg" (백엔드가 이 규칙으로 제목을 뽑음)
|
||||
// num = 게시물 안 순서. mp4면 Video, 아니면 Image (인스타 영상은 항상 mp4)
|
||||
cmdList.add("-o");
|
||||
@@ -420,6 +427,25 @@ public class DiscordDownloadBot extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// 인스타 게시물 설명글: gallery-dl이 남긴 .json에서 꺼내고, .json은 지움 (게시판에 파일로 보이지 않게)
|
||||
// 설명글이 없으면(유튜브 등) null
|
||||
private static String readCaption(String saveDir) {
|
||||
File[] jsons = new File(saveDir).listFiles((d, n) -> n.endsWith(".json"));
|
||||
if (jsons == null) return null;
|
||||
String caption = null;
|
||||
for (File f : jsons) {
|
||||
if (caption == null) {
|
||||
try {
|
||||
String text = DataObject.fromJson(new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8))
|
||||
.getString("description", "").trim();
|
||||
if (!text.isEmpty()) caption = text;
|
||||
} catch (Exception e) { /* 읽기 실패면 설명 없이 진행 */ }
|
||||
}
|
||||
f.delete();
|
||||
}
|
||||
return caption;
|
||||
}
|
||||
|
||||
// 파일 생성 확인 함수
|
||||
private boolean checkFileExists(String saveDir, String keyword) {
|
||||
File dir = new File(saveDir);
|
||||
|
||||
Reference in new issue
Block a user