diff --git a/backend/config_parser.py b/backend/config_parser.py index bde6179..75dcbad 100644 --- a/backend/config_parser.py +++ b/backend/config_parser.py @@ -19,11 +19,13 @@ class Recorder: self.name = name self.index = index self.channels = 0 + self.nvr_index = 0 @property def nvr(self): client = DVRIPCam(self.address, port = self.port, user = self.username, password = self.password) - return NVR(client, self.loop) + self.nvr_index += 1 + return NVR(client, self.loop, self.nvr_index) def __str__(self) -> str: if not self.name: diff --git a/backend/nvr_core.py b/backend/nvr_core.py index 8dfa4f4..e331384 100644 --- a/backend/nvr_core.py +++ b/backend/nvr_core.py @@ -19,18 +19,22 @@ def date_today(begin = True): return datetime.now().strftime("%Y-%m-%d 23:59:59") class NVR: - def __init__(self, client, loop) -> None: + def __init__(self, client, loop, index = 0) -> None: self.logger = create_logger(NVR.__name__) self.client:DVRIPCam = client self.loop = loop + self.index = index async def login(self): + self.logger.debug(f"[{self.index}] Login to {self.client}") await self.client.login(self.loop) def logout(self): + self.logger.debug(f"[{self.index}] Logout to {self.client}") self.client.close() async def channels(self): + self.logger.debug(f"[{self.index}] Get channels") return await self.client.get_command("ChannelTitle", 1048) async def files(self, channel, start = None, end = None, ftype = H264, stype = SECONDARY_STREAM, json = False): @@ -38,7 +42,7 @@ class NVR: start = date_today() if not end: end = date_today(False) - self.logger.info(f"Search files from {start} to {end}") + self.logger.info(f"[{self.index}] Search files from {start} to {end}") for raw_file in await list_local_files(self.client, startTime=start, endTime=end, filetype=ftype, channel=channel, streamType=stype): if json: yield NvrFile(raw_file, channel, stype).json @@ -47,13 +51,13 @@ class NVR: async def stream_file(self, file: NvrFile) -> bytes: len_data = await file.generate_first_bytes(self.client) - self.logger.debug(f"len data = {len_data}") + self.logger.debug(f"[{self.index}] len data = {len_data}, streaming file content") if (len_data is None): yield b"" else: async for chunk in file.get_file_stream(self.client, len_data): if (chunk == None): - self.logger.debug("end of file") + self.logger.debug(f"[{self.index}] end of file") break yield chunk @@ -63,4 +67,4 @@ class NVR: async for byte in file.generate_bytes(self.client): f.write(byte) downloaded_bytes += len(byte) - self.logger.debug(f"\r{downloaded_bytes}/{file.size}") \ No newline at end of file + self.logger.debug(f"\r [{self.index}] Downloaded: {downloaded_bytes}/{file.size}") \ No newline at end of file diff --git a/frontend/ang_dvrip/src/app/components/history/history.component.css b/frontend/ang_dvrip/src/app/components/history/history.component.css index 8ce872c..e4ba4dd 100644 --- a/frontend/ang_dvrip/src/app/components/history/history.component.css +++ b/frontend/ang_dvrip/src/app/components/history/history.component.css @@ -9,3 +9,7 @@ .raw { color: black; } + +.processing { + color: coral; +} diff --git a/frontend/ang_dvrip/src/app/components/history/history.component.html b/frontend/ang_dvrip/src/app/components/history/history.component.html index 0a3f968..72fa77a 100644 --- a/frontend/ang_dvrip/src/app/components/history/history.component.html +++ b/frontend/ang_dvrip/src/app/components/history/history.component.html @@ -38,7 +38,7 @@ Действия - {{element.converted?'cloud_done':'cloud_download'}} + {{element.converted?'cloud_done':'cloud_download'}} attachment diff --git a/frontend/ang_dvrip/src/app/components/history/history.component.ts b/frontend/ang_dvrip/src/app/components/history/history.component.ts index e918255..21bf1e5 100644 --- a/frontend/ang_dvrip/src/app/components/history/history.component.ts +++ b/frontend/ang_dvrip/src/app/components/history/history.component.ts @@ -7,13 +7,7 @@ import {MatDatepickerInputEvent} from "@angular/material/datepicker"; import {MatDialog} from "@angular/material/dialog"; import {TranscodeModalComponent} from "../../modals/transcode-modal/transcode-modal.component"; import {BaseUtils} from "../../utils/BaseUtils"; - -export interface DVRFILE { - filename:string, - size:number, - b64:string, - converted:boolean -} +import DVRFILE from "../../entities/DVRFILE"; @Component({ selector: 'app-history', @@ -63,7 +57,14 @@ export class HistoryComponent implements OnInit { this.getHistory(); } - openTransCodeDialog(b64:string) { - const dialog = this.dialog.open(TranscodeModalComponent, {data:{b64:b64, recorder_index:this.route.snapshot.paramMap.get('recorderId')}}); + openTransCodeDialog(dvrfile:DVRFILE) { + const dialog = this.dialog.open(TranscodeModalComponent, {data:{b64:dvrfile.b64, recorder_index:this.route.snapshot.paramMap.get('recorderId')}}); + dialog.afterOpened().subscribe(() => dvrfile.processing = true); + dialog.afterClosed().subscribe((res:boolean) => { + dvrfile.converted = res; + if (res) { + dvrfile.processing = null; + } + }); } } diff --git a/frontend/ang_dvrip/src/app/entities/DVRFILE.ts b/frontend/ang_dvrip/src/app/entities/DVRFILE.ts new file mode 100644 index 0000000..21ea5d8 --- /dev/null +++ b/frontend/ang_dvrip/src/app/entities/DVRFILE.ts @@ -0,0 +1,7 @@ +export default interface DVRFILE { + filename:string, + size:number, + b64:string, + converted:boolean, + processing:boolean|null +} diff --git a/frontend/ang_dvrip/src/app/modals/transcode-modal/transcode-modal.component.ts b/frontend/ang_dvrip/src/app/modals/transcode-modal/transcode-modal.component.ts index b878766..6019406 100644 --- a/frontend/ang_dvrip/src/app/modals/transcode-modal/transcode-modal.component.ts +++ b/frontend/ang_dvrip/src/app/modals/transcode-modal/transcode-modal.component.ts @@ -32,7 +32,7 @@ export class TranscodeModalComponent implements OnInit { close():void { clearInterval(this.interval); - this.dialogRef.close(); + this.dialogRef.close(this.status.done); } getStatus() {