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
@@ -4,15 +4,22 @@ import argparse, json, os, subprocess, sys, time
from datetime import datetime
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from paths import LINKS_DIR, DOCS_DIR, OUTPUT_DIR
from paths import LINKS_DIR, DOCS_DIR, OUTPUT_DIR, find_lark_cli
LARK = r'C:\Users\admin\AppData\Roaming\npm\node_modules\@larksuite\cli\bin\lark-cli.exe'
LARK = find_lark_cli()
IMAGES_DIR = os.path.join(OUTPUT_DIR, 'feishu-images')
def lark_api(path, timeout=30):
r = subprocess.run([LARK, 'api', 'GET', path, '--format', 'json'], capture_output=True, timeout=timeout)
def lark_api(path, params=None, timeout=30):
cmd = [LARK, 'api', 'GET', path, '--format', 'json']
if params:
cmd += ['--params', json.dumps(params, ensure_ascii=False)]
r = subprocess.run(cmd, capture_output=True, timeout=timeout)
out = r.stdout.decode('utf-8', errors='replace')
try: return json.loads(out)
try:
result = json.loads(out)
if result.get('ok') is True:
return {'code': 0, 'data': result.get('data', {})}
return result
except: return None
def download_media(token, local_path, timeout=30):
@@ -29,7 +36,7 @@ def download_media(token, local_path, timeout=30):
except: return False
def resolve_wiki(node_id):
data = lark_api(f'/open-apis/wiki/v2/spaces/get_node?token={node_id}')
data = lark_api('/open-apis/wiki/v2/spaces/get_node', params={'token': node_id})
if data and data.get('code') == 0:
node = data.get('data', {}).get('node', {})
return node.get('obj_token', ''), node.get('title', '')
@@ -192,7 +199,14 @@ def main():
if not args.rebuild and doc_id in existing:
old = existing[doc_id]
if old.get('fetched', False) and old.get('content_length', 0) > 200 and old.get('images_downloaded', 0) > 0:
image_blocks = old.get('image_blocks')
images_downloaded = old.get('images_downloaded')
media_complete = (
image_blocks is not None
and images_downloaded is not None
and images_downloaded >= image_blocks
)
if old.get('fetched', False) and old.get('content_length', 0) > 200 and media_complete:
skip += 1
continue