"""下載 Vlog 綜藝素材包(只用 Python 標準函式庫)。 python3 fetch_kit.py --list # 列出所有情境 python3 fetch_kit.py --situation 搞笑好笑 # 下載該情境推薦的字卡、小圖、音效、配樂 python3 fetch_kit.py --id lol,sfx_rimshot # 指定 id python3 fetch_kit.py --all # 全部(PNG + MP3;加 --clips 連 Resolve 彈出短片一起) 選項:--out 資料夾(預設 ./vlog-kit) --clips 清單:https://kit.10xboost.org/manifest.json 情境表:https://kit.10xboost.org/GUIDE.md """ import argparse, json, os, urllib.request MANIFEST = 'https://kit.10xboost.org/manifest.json' def get(url): req = urllib.request.Request(url, headers={'User-Agent': 'vlog-kit-fetch/1'}) with urllib.request.urlopen(req, timeout=60) as r: return r.read() def main(): ap = argparse.ArgumentParser() ap.add_argument('--list', action='store_true'); ap.add_argument('--situation'); ap.add_argument('--id') ap.add_argument('--all', action='store_true'); ap.add_argument('--clips', action='store_true'); ap.add_argument('--out', default='vlog-kit') a = ap.parse_args() m = json.loads(get(MANIFEST)) if a.list or not (a.situation or a.id or a.all): for k, s in m['situations'].items(): print(f"{k}:{s['desc']}({len(s['images'])} 圖、{len(s['sounds'])} 音效、{len(s['music'])} 配樂)") return I = {i['id']: i for i in m['images']} A = {x['id']: x for x in m['audio']} if a.all: ids = list(I) + list(A) elif a.situation: s = m['situations'][a.situation] ids = s['images'] + s['sounds'] + s['music'] else: ids = a.id.split(',') paths = [] for x in ids: if x in I: paths.append(I[x]['png']) if a.clips and I[x].get('clip'): paths.append(I[x]['clip']) elif x in A: paths.append(A[x]['mp3']) else: print('unknown id', x) for p in paths: dst = os.path.join(a.out, p) if os.path.exists(dst): continue os.makedirs(os.path.dirname(dst), exist_ok=True) with open(dst, 'wb') as f: f.write(get(m['base_url'] + p)) print('↓', p) with open(os.path.join(a.out, 'manifest.json'), 'wb') as f: f.write(get(MANIFEST)) print(f'{len(paths)} files in {a.out}/') if __name__ == '__main__': main()