import json
|
|
def format_regions(regions):
|
"""格式化坐标数组为字符串"""
|
return ",".join(f"({x},{y})" for x, y in regions)
|
|
def parse_camera_list(file_path):
|
with open(file_path, 'r', encoding='utf-8') as file:
|
data = json.load(file)
|
|
output_lines = []
|
|
for channel in data.get("channels", []):
|
channel_id = channel.get("id")
|
url = channel.get("url")
|
|
for action in channel.get("actions", []):
|
action_type = action.get("action")
|
|
if action_type == "JAM":
|
regions = action.get("regions", [])
|
formatted_regions = format_regions(regions)
|
line = f"{url} 0.5 172.18.0.247:9092 3 {channel_id} true {formatted_regions}"
|
output_lines.append(line)
|
|
return output_lines
|
|
if __name__ == "__main__":
|
# 替换为你的文件路径
|
file_path = "camera.list.txt"
|
|
# 解析并输出结果
|
result = parse_camera_list(file_path)
|
for line in result:
|
print(line)
|