73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
"""
|
|||
|
|
摄像头配置恢复助手
|
|||
|
|
如果云端配置丢失,使用此脚本手动添加摄像头配置
|
|||
|
|
"""
|
|||
|
|
import sys
|
|||
|
|
from pathlib import Path
|
|||
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|||
|
|
|
|||
|
|
from config.database import get_sqlite_manager
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
print("=== Camera Config Recovery Tool ===\n")
|
|||
|
|
print("This tool helps you restore the 3 missing camera configs")
|
|||
|
|
print("You need to provide the RTSP URLs for:")
|
|||
|
|
print(" 1. cam_1f0e3dad9990")
|
|||
|
|
print(" 2. cam_6f4922f45568")
|
|||
|
|
print(" 3. cam_c51ce410c124")
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
cameras_to_add = []
|
|||
|
|
|
|||
|
|
for i, cam_id in enumerate(['cam_1f0e3dad9990', 'cam_6f4922f45568', 'cam_c51ce410c124'], 1):
|
|||
|
|
print(f"\nCamera {i}: {cam_id}")
|
|||
|
|
rtsp_url = input(f" RTSP URL (or press Enter to skip): ").strip()
|
|||
|
|
|
|||
|
|
if not rtsp_url:
|
|||
|
|
print(f" Skipped")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
name = input(f" Display Name (default: {cam_id}): ").strip() or cam_id
|
|||
|
|
|
|||
|
|
cameras_to_add.append({
|
|||
|
|
"camera_id": cam_id,
|
|||
|
|
"rtsp_url": rtsp_url,
|
|||
|
|
"name": name
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if not cameras_to_add:
|
|||
|
|
print("\n[CANCELLED] No cameras to add")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 50)
|
|||
|
|
print("Summary:")
|
|||
|
|
for cam in cameras_to_add:
|
|||
|
|
print(f" - {cam['camera_id']}: {cam['name']}")
|
|||
|
|
print(f" RTSP: {cam['rtsp_url'][:50]}...")
|
|||
|
|
print("=" * 50)
|
|||
|
|
|
|||
|
|
response = input("\nAdd these cameras to database? (yes/no): ").strip().lower()
|
|||
|
|
|
|||
|
|
if response != 'yes':
|
|||
|
|
print("\n[CANCELLED]")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# Add cameras to database
|
|||
|
|
db_manager = get_sqlite_manager()
|
|||
|
|
|
|||
|
|
for cam in cameras_to_add:
|
|||
|
|
try:
|
|||
|
|
db_manager.save_camera_config(cam)
|
|||
|
|
print(f" [OK] Added: {cam['camera_id']}")
|
|||
|
|
except Exception as e:
|
|||
|
|
print(f" [FAIL] Failed to add {cam['camera_id']}: {e}")
|
|||
|
|
|
|||
|
|
print("\n[SUCCESS] Cameras added to database")
|
|||
|
|
print("\nNext steps:")
|
|||
|
|
print(" 1. Restart the Edge service")
|
|||
|
|
print(" 2. The 3 cameras should now start streaming")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|