|
|
@ -1,3 +1,4 @@ |
|
|
|
from genericpath import exists |
|
|
|
import os, sys |
|
|
|
from asyncio_dvrip import DVRIPCam |
|
|
|
import asyncio |
|
|
@ -10,12 +11,14 @@ from global_funcs import * |
|
|
|
|
|
|
|
class Recorder: |
|
|
|
loop = asyncio.get_event_loop() |
|
|
|
def __init__(self, address, port, username, password, name = ""): |
|
|
|
def __init__(self, address, port, username, password, name = "", index = 0): |
|
|
|
self.address = address |
|
|
|
self.port = int(port) |
|
|
|
self.username = username |
|
|
|
self.password = password |
|
|
|
self.name = name |
|
|
|
self.index = index |
|
|
|
self.channels = 0 |
|
|
|
|
|
|
|
@property |
|
|
|
def nvr(self): |
|
|
@ -58,6 +61,67 @@ class TranscodeStatus: |
|
|
|
break |
|
|
|
yield b"" |
|
|
|
|
|
|
|
class Go2RtcChannel: |
|
|
|
#vhod_hd: dvrip://bfwc:JQWwM146@192.168.5.2:34567?channel=3&subtype=0 |
|
|
|
def __init__(self, recorder: Recorder, count_of_streams = 2) -> None: |
|
|
|
self.proto = "dvrip" |
|
|
|
self.login = recorder.username |
|
|
|
self.password = recorder.password |
|
|
|
self.host = f"{recorder.address}:{recorder.port}" |
|
|
|
self.recorder_index = recorder.index |
|
|
|
self.count_of_channels = recorder.channels |
|
|
|
self.count_of_streams = count_of_streams |
|
|
|
|
|
|
|
def generate_lines(self): |
|
|
|
lines = "" |
|
|
|
for i in range(0, self.count_of_channels): |
|
|
|
for j in range(0, self.count_of_streams): |
|
|
|
lines += f" {self.recorder_index}_{i}_{j}: {self.proto}://{self.login}:{self.password}@{self.host}?channel={i}&subtype={j}\n" |
|
|
|
return lines |
|
|
|
|
|
|
|
class Go2Rtc: |
|
|
|
WIN = "https://github.com/AlexxIT/go2rtc/releases/download/v1.9.4/go2rtc_win64.zip" |
|
|
|
LNX = "https://github.com/AlexxIT/go2rtc/releases/download/v1.9.4/go2rtc_linux_amd64" |
|
|
|
|
|
|
|
def __init__(self) -> None: |
|
|
|
self.enabled = False |
|
|
|
try: |
|
|
|
self.check_exists() |
|
|
|
except: |
|
|
|
print("go2rtc is disabled") |
|
|
|
pass |
|
|
|
|
|
|
|
def check_exists(self): |
|
|
|
go2rtc_directory = os.path.join(app_dir(), "go2rtc") |
|
|
|
if os.path.exists(go2rtc_directory): |
|
|
|
print("Go2Rtc directory exists") |
|
|
|
if platform.system() == "Windows" and os.path.exists(os.path.join(go2rtc_directory, "go2rtc.exe")): |
|
|
|
print("[WIN] Go2Rtc is exists, continue create config") |
|
|
|
self.exec = os.path.join(go2rtc_directory, "go2rtc.exe") |
|
|
|
self.enabled = True |
|
|
|
elif platform.system() == "Linux" and os.path.exists(os.path.join(go2rtc_directory, "go2rtc")): |
|
|
|
print("[LNX] Go2Rtc is exists, continue create config") |
|
|
|
self.exec = os.path.join(go2rtc_directory, "go2rtc") |
|
|
|
self.enabled = True |
|
|
|
else: |
|
|
|
raise Exception(f"go2rtc not downloaded, windows: {self.WIN} linux: {self.LNX}") |
|
|
|
else: |
|
|
|
raise Exception("Go2Rtc not found, he is disabled") |
|
|
|
|
|
|
|
async def start_go2rtc(self, recorders): |
|
|
|
lines = "streams:\n" |
|
|
|
for recorder in recorders: |
|
|
|
lines += Go2RtcChannel(recorder, 2).generate_lines() |
|
|
|
|
|
|
|
cfg_file = os.path.join(app_dir(), "go2rtc", "go2rtc.yaml") |
|
|
|
print(f"go2rtc config: {cfg_file}") |
|
|
|
|
|
|
|
async with aiofiles.open(cfg_file, "w", encoding="utf8") as cfg: |
|
|
|
await cfg.write(lines) |
|
|
|
|
|
|
|
await asyncio.create_subprocess_exec(self.exec, *["-c", cfg_file]) |
|
|
|
|
|
|
|
|
|
|
|
class TranscodeTools: |
|
|
|
statuses:dict[str, TranscodeStatus] = {} |
|
|
|
WIN32PYTHON = "python-win32" |
|
|
@ -237,8 +301,10 @@ class Config: |
|
|
|
self.listen_address = raw.get("backend", {}).get("address", "0.0.0.0") |
|
|
|
self.listen_port = int(raw.get("backend", {}).get("port", "8080")) |
|
|
|
self.recorders = [] |
|
|
|
i = 0 |
|
|
|
for raw_server in raw.get("recorders", []): |
|
|
|
self.recorders.append(Recorder(raw_server.get("ip"), raw_server.get("port"), raw_server.get("user"), raw_server.get("password"), raw_server.get("name", ""))) |
|
|
|
self.recorders.append(Recorder(raw_server.get("ip"), raw_server.get("port"), raw_server.get("user"), raw_server.get("password"), raw_server.get("name", ""), index=i)) |
|
|
|
i += 1 |
|
|
|
if (self.recorders.__len__() == 0): |
|
|
|
print("Recorders not find") |
|
|
|
else: |
|
|
|