Spaces:
Running
Running
Set 8 (10.22–10.29 国内热点 9 词): manifest, items/credits, scripts, base photos — sync 1/2
c607039 verified Download source/studio/package8.py from Ethscriptions/POLS: direct link, hf CLI and curl.
- Browser
- Download file 5.99 kB
-
https://huggingface.co/spaces/Ethscriptions/POLS/resolve/main/source/studio/package8.py
- Command line
-
hf download hf://spaces/Ethscriptions/POLS/source/studio/package8.py
-
curl -L -o package8.py https://huggingface.co/spaces/Ethscriptions/POLS/resolve/main/source/studio/package8.py
5.99 kB
| """Pair rendered clips as Apple Live Photos (JPG + MOV, with audio), build web previews, ZIP and manifest for set 5.""" | |
| import json, os, shutil, subprocess, sys, zipfile | |
| sys.path.insert(0, os.path.dirname(__file__)) | |
| from pair_live_photo import pair | |
| OUT = '/tmp/work/out' | |
| PUB = '/tmp/work/site/live' | |
| SET = dict(key='h', items='items8.json', credits='credits8.json', | |
| name='第八组 · 本周国内社会热点里的 9 个词(10.22–10.29)', | |
| folder='国内热点英语实况图-第八组', zip='china-hot-topics-week2-live-photos.zip', | |
| title='姆巴佩解约、三丽鸥联名翻车、机器狗爬泰山、国考97:1……这 9 个热搜词你会用英语说吗?', | |
| intro='这一周国内热搜你肯定刷到过:姆巴佩被蒙牛、东鹏集体解约后道歉、三丽鸥联名《VIVANT》深夜致歉、机器狗背 100 斤爬泰山比挑山工还快、三季度 GDP 同比 4.6%、奥美定隆胸 20 年后变质、华为智驾公开赛十万人报名、广交会第二期收官、国考 345 万人通过资格审查……中文天天说,换成英文你能马上说出来吗👀', | |
| tags='#雅思 #托福 #留学 #留学生 #职场英语 #新闻英语 #英语单词 #实况图 #每日英语 #英语学习 #热搜') | |
| README = """国内热点英语 · 实况图素材包({n} 张) | |
| 每张实况图 = 一对同名的 .JPG + .MOV(例如 {example}.JPG / {example}.MOV)。 | |
| 两个文件里写入了相同的苹果实况标识,视频带声音(英语发音 + 音效),全部 ≤ 3 秒,可发微信朋友圈 / 小红书 / 抖音图文。 | |
| Mac 导入方法: | |
| 1. 解压本压缩包; | |
| 2. 全选全部 JPG 和 MOV,一起拖进「照片」App(或 照片 → 文件 → 导入); | |
| 3. 照片会把每一对识别为一张 LIVE 实况照片; | |
| 4. 通过 iCloud 照片或隔空投送到 iPhone,发图文时选择这些照片并保持「实况」开启。 | |
| 注意:JPG 和 MOV 必须成对导入;不要用其他软件重新转码 MOV,否则会丢失配对信息。 | |
| 尺寸 1080×1440(3:4 竖屏),30fps,H.264 + AAC。 | |
| 建议标题:{title} | |
| 建议正文: | |
| {body} | |
| 图片来源: | |
| {credits} | |
| """ | |
| def main(): | |
| items = json.load(open(os.path.join(os.path.dirname(__file__), SET['items']))) | |
| credits = json.load(open(os.path.join(os.path.dirname(__file__), SET['credits']))) | |
| cmap = {c['id']: c for c in credits} | |
| dist = f"/tmp/work/dist/{SET['folder']}" | |
| shutil.rmtree(dist, ignore_errors=True); os.makedirs(dist); os.makedirs(PUB, exist_ok=True) | |
| out_items = [] | |
| for k, it in enumerate(items, 1): | |
| d = os.path.join(OUT, it['id']) | |
| meta = json.load(open(os.path.join(d, 'render.json'))) | |
| live = os.path.join(d, 'live'); shutil.rmtree(live, ignore_errors=True) | |
| m = pair(os.path.join(d, 'cover.jpg'), os.path.join(d, 'motion.mp4'), live, meta['coverTime'], meta['fps']) | |
| assert m['metadataVerified'], m | |
| base = f"LIVE_{it['id']}_{it['en'].replace(' ', '-')}" | |
| shutil.copy(os.path.join(live, 'live.jpg'), os.path.join(dist, base + '.JPG')) | |
| shutil.copy(os.path.join(live, 'live.mov'), os.path.join(dist, base + '.MOV')) | |
| subprocess.run(['ffmpeg', '-v', 'error', '-y', '-i', os.path.join(d, 'cover.jpg'), '-vf', 'scale=720:-2', '-q:v', '3', os.path.join(PUB, f"cover_{it['id']}.jpg")], check=True) | |
| subprocess.run(['ffmpeg', '-v', 'error', '-y', '-i', os.path.join(d, 'final.jpg'), '-vf', 'scale=720:-2', '-q:v', '3', os.path.join(PUB, f"final_{it['id']}.jpg")], check=True) | |
| subprocess.run(['ffmpeg', '-v', 'error', '-y', '-i', os.path.join(d, 'motion.mp4'), '-vf', 'scale=720:-2', '-c:v', 'libx264', '-crf', '24', '-preset', 'medium', '-pix_fmt', 'yuv420p', '-c:a', 'aac', '-b:a', '128k', '-movflags', '+faststart', os.path.join(PUB, f"preview_{it['id']}.mp4")], check=True) | |
| src = 'wikimedia' if it['id'] in cmap else 'ai' | |
| out_items.append({'id': it['id'], 'index': k, 'zh': it['zh'], 'en': it['en'], 'ipa': it['ipa'], 'pos': it['pos'], 'cat': it['cat'], 'hook': it['hook'], | |
| 'source': src, 'duration': round(meta['duration'], 2), 'cover': f"cover_{it['id']}.jpg", 'final': f"final_{it['id']}.jpg", | |
| 'preview': f"preview_{it['id']}.mp4", 'identifier': m['identifier'], 'file': base}) | |
| print('paired', base, m['identifier'], flush=True) | |
| body = (SET['intro'] + '\n先看封面猜一猜,再长按实况看答案(记得开声音🔊)\n评论区报一下你答对了几个~\n\n' | |
| + ' / '.join(i['zh'] for i in items) + '\n\n图片来源:3 张为 Wikimedia Commons 授权照片(作者与授权见素材包内说明),6 张为 AI 生成\n\n' + SET['tags']) | |
| cred_txt = '\n'.join(f"- {c['zh']} / {c['en']}: 「{c['file']}」 by {c['author']} · {c['license']} · {c['page']}" for c in credits) + '\n- 其余 6 张(代言 / 联名 / 挑山工 / 医美 / 辅助驾驶 / 资格)为 AI 生成图片' | |
| open(os.path.join(dist, '使用说明.txt'), 'w', encoding='utf-8').write(README.format(n=len(items), example=f"LIVE_{items[0]['id']}_{items[0]['en']}", title=SET['title'], body=body, credits=cred_txt)) | |
| zp = os.path.join(PUB, SET['zip']) | |
| with zipfile.ZipFile(zp, 'w', zipfile.ZIP_STORED) as z: | |
| for f in sorted(os.listdir(dist)): | |
| z.write(os.path.join(dist, f), f"{SET['folder']}/{f}") | |
| manifest = {'key': SET['key'], 'name': SET['name'], 'zip': SET['zip'], 'zipMB': round(os.path.getsize(zp) / 1e6, 1), 'items': out_items, | |
| 'copy': {'title': SET['title'], 'body': body}, | |
| 'credits': [{'id': c['id'], 'zh': c['zh'], 'en': c['en'], 'author': c['author'], 'license': c['license'], 'licenseUrl': c.get('license_url') or '', 'page': c['page'], 'file': c['file']} for c in credits]} | |
| json.dump(manifest, open('/tmp/work/site/pack8.json', 'w'), ensure_ascii=False, indent=1) | |
| print('zip MB', manifest['zipMB']) | |
| if __name__ == '__main__': | |
| main() | |