feat: collect complete Feishu media assets

This commit is contained in:
Evilom
2026-07-11 12:30:54 +08:00
parent 3ea50649f6
commit bbafe770b3
662 changed files with 15404 additions and 14017 deletions
@@ -30,6 +30,38 @@ def main():
if r.returncode==0: new+=1
else: print(f" FAIL")
except Exception as e: print(f" ERR: {e}")
print(f"\n下载 {new} 个 -> {DOWNLOAD_DIR}")
media_path = os.path.join(LINKS_DIR, "all_chat_media.json")
media = []
if os.path.isfile(media_path):
with open(media_path, "r", encoding="utf-8") as f: media = json.load(f)
media_dir = os.path.join(DOWNLOAD_DIR, "chat-media")
os.makedirs(media_dir, exist_ok=True)
media_new = 0
for item in media:
resource_id = item.get("resourceId", "")
message_id = item.get("messageId", "")
conversation_id = item.get("conversationId", "")
if not resource_id or not message_id or not conversation_id:
print(f" MEDIA FAIL 缺少下载标识: {message_id or resource_id}")
continue
ext = ".mp4" if item.get("mediaType") == "video" else ".jpg"
stamp = item.get("time", "unknown").replace(":", "").replace(" ", "_").replace("-", "")
safe_id = "".join(ch for ch in message_id if ch.isalnum())[-12:] or "media"
output = os.path.join(media_dir, f"{stamp}_{safe_id}{ext}")
if args.incremental and os.path.isfile(output) and os.path.getsize(output) > 0:
print(f" SKIP {os.path.basename(output)}")
continue
cmd = [dws, "chat", "message", "download-media", "--type", "mediaId",
"--resource-id", resource_id, "--message-id", message_id,
"--open-conversation-id", conversation_id, "--output", output, "-y"]
try:
r = subprocess.run(cmd, capture_output=True, timeout=120)
if r.returncode == 0 and os.path.isfile(output) and os.path.getsize(output) > 0:
media_new += 1
else:
print(f" MEDIA FAIL {message_id}")
except Exception as e: print(f" MEDIA ERR {message_id}: {e}")
print(f"\n下载附件 {new} 个、聊天媒体 {media_new} 个 -> {DOWNLOAD_DIR}")
if __name__ == "__main__": main()