build: update build script

This commit is contained in:
cxfksword
2023-11-25 22:48:11 +08:00
parent 2a73919ccb
commit bd32414ac2
2 changed files with 1 additions and 1 deletions

74
scripts/generate_manifest.py Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/env python3
import hashlib
import json
import sys
import re
import os
import subprocess
from datetime import datetime
from urllib.request import urlopen
from urllib.error import HTTPError
def generate_manifest():
return [{
"guid": "5B39DA44-5314-4940-8E26-54C821C17F86",
"name": "Danmu",
"description": "jellyfin的b站弹幕自动下载插件会匹配b站番剧/电影视频,自动下载对应弹幕,并定时更新。",
"overview": "jellyfin弹幕下载插件",
"owner": "cxfksword",
"category": "Metadata",
"imageUrl": "https://jellyfin-plugin-release.pages.dev/danmu/logo.png",
"versions": []
}]
def generate_version(filepath, version, changelog):
return {
'version': f"{version}.0",
'changelog': changelog,
'targetAbi': '10.8.0.0',
'sourceUrl': f'https://jellyfin-plugin-release.pages.dev/danmu/danmu_{version}.0.zip',
'checksum': md5sum(filepath),
'timestamp': datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
}
def md5sum(filename):
with open(filename, 'rb') as f:
return hashlib.md5(f.read()).hexdigest()
def main():
filename = sys.argv[1]
tag = sys.argv[2]
version = tag.lstrip('v')
filepath = os.path.join(os.getcwd(), filename)
result = subprocess.run(['git', 'tag','-l','--format=%(contents)', tag, '-l'], stdout=subprocess.PIPE)
changelog = result.stdout.decode('utf-8').strip()
# 解析旧 manifest
try:
with urlopen('https://raw.githubusercontent.com/cxfksword/jellyfin-release/master/danmu/manifest.json') as f:
manifest = json.load(f)
except HTTPError as err:
if err.code == 404:
manifest = generate_manifest()
else:
raise
# 追加新版本/覆盖旧版本
manifest[0]['versions'] = list(filter(lambda x: x['version'] == version, manifest[0]['versions']))
manifest[0]['versions'].insert(0, generate_version(filepath, version, changelog))
with open('manifest.json', 'w') as f:
json.dump(manifest, f, indent=2)
# # 国内加速
# with open('manifest_cn.json', 'w') as f:
# manifest_cn = json.dumps(manifest, indent=2)
# manifest_cn = re.sub('https://github.com/cxfksword/jellyfin-plugin-danmu/raw/main/doc/logo.png', "https://jellyfin-plugin-release.pages.dev/danmu/logo.png", manifest_cn)
# manifest_cn = re.sub('https://github.com/cxfksword/jellyfin-plugin-danmu/releases/download/v[0-9.]+', "https://jellyfin-plugin-release.pages.dev/danmu", manifest_cn)
# f.write(manifest_cn)
if __name__ == '__main__':
main()