From 4449d488c97c55e1497acb2b11f21ca8a18e8ef6 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Tue, 14 Feb 2023 01:08:05 +0100 Subject: [PATCH] Fix #38: Add a loading message with progress on end-user interface --- website/index.php | 6 ++++-- website/search.py | 26 +++++++++++++------------- website/websocket.php | 2 -- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/website/index.php b/website/index.php index 7d07c60..141f6b0 100644 --- a/website/index.php +++ b/website/index.php @@ -17,6 +17,8 @@ Access raw data with: . +Progress: + @@ -36,8 +38,8 @@ Access raw data with: . function treatLine(line) { console.log(line); - if (line.startsWith('alert:')) { - alert(line.replace('alert:', '')); + if (line.startsWith('progress:')) { + document.getElementById('progress').innerHTML = line.replace('progress:', ''); } else { var channelsDom = document.getElementById('channels'); const channelFileParts = line.split('/'); diff --git a/website/search.py b/website/search.py index ff4038c..f506884 100755 --- a/website/search.py +++ b/website/search.py @@ -28,20 +28,20 @@ def write(s): except Exception as e: sys.exit(e) -# Unclear if `os.listdir` takes a lot of time, as it's a generator. # As `zipgrep` doesn't support arguments to stop on first match for each file, we proceed manually to keep a good theoretical complexity. -for file in os.listdir(path): - if file.endswith('.zip'): - zip = zipfile.ZipFile(path + file) - for fileInZip in zip.namelist(): - if searchOnlyCaptions and not fileInZip.endswith('.vtt'): - continue - f = zip.open(fileInZip) - for line in f.readlines(): - if message in str(line): - write(f'{file}/{fileInZip}') - break - f.close() +files = [file for file in os.listdir(path) if file.endswith('.zip')] +for fileIndex, file in enumerate(files): + write(f'progress:{fileIndex + 1} / {len(files)}') + zip = zipfile.ZipFile(path + file) + for fileInZip in zip.namelist(): + if searchOnlyCaptions and not fileInZip.endswith('.vtt'): + continue + f = zip.open(fileInZip) + for line in f.readlines(): + if message in str(line): + write(f'{file}/{fileInZip}') + break + f.close() f = open(clientFilePath) while True: diff --git a/website/websocket.php b/website/websocket.php index 6bf4ace..ea20dca 100644 --- a/website/websocket.php +++ b/website/websocket.php @@ -96,7 +96,6 @@ class MyProcess implements MessageComponentInterface if (preg_match("/^[a-zA-Z0-9-_ ]+$/", $msg) !== 1) { return; } - $from->send('alert:Started searching...'); $client = $this->clients->offsetGet($from); // If a previous request was received, we execute the new one with another client for simplicity otherwise with current file deletion approach, we can't tell the worker `search.py` that we don't care about its execution anymore. if ($client->pid !== null) { @@ -138,7 +137,6 @@ class MyProcess implements MessageComponentInterface } else { // We don't need the periodic timer anymore, as the worker finished its work and acknowledged that `websocket.php` completely read its output. $this->loop->cancelTimer($client->timer); - $from->send('alert:Search finished!'); } }); }