fix: Improve kb-bilibili-metadata output format
- Wrap result in standard format with success/data/metadata - Change default headless to False (use API by default) - Add error handling with structured output - Improve CLI output readability
This commit is contained in:
@@ -98,8 +98,8 @@ def main():
|
||||
parser.add_argument(
|
||||
'--headless',
|
||||
action='store_true',
|
||||
default=True,
|
||||
help='使用无头模式(浏览器,默认开启)'
|
||||
default=False,
|
||||
help='使用无头模式(浏览器,默认关闭,使用API)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--timeout',
|
||||
@@ -131,18 +131,34 @@ def main():
|
||||
print(f"错误: 不支持的类型 {args.type}")
|
||||
sys.exit(1)
|
||||
|
||||
# 包装为标准输出格式
|
||||
output = {
|
||||
"success": True,
|
||||
"data": result,
|
||||
"metadata": {
|
||||
"type": args.type,
|
||||
"id": args.id,
|
||||
"fetched_at": "2024-01-01T00:00:00"
|
||||
}
|
||||
}
|
||||
|
||||
# 输出结果
|
||||
if not args.output:
|
||||
if args.pretty:
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
print(json.dumps(output, ensure_ascii=False, indent=2))
|
||||
else:
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
print(json.dumps(output, ensure_ascii=False))
|
||||
|
||||
if args.output:
|
||||
print(f"结果已保存到: {args.output}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"错误: {e}", file=sys.stderr)
|
||||
error_output = {
|
||||
"success": False,
|
||||
"error": str(e),
|
||||
"error_type": type(e).__name__
|
||||
}
|
||||
print(json.dumps(error_output, ensure_ascii=False, indent=2))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user