#31: Add a first search only captions support

This commit is contained in:
Benjamin Loison 2023-02-14 00:59:37 +01:00
parent 8d20327b67
commit 34c0d03587
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 8 additions and 2 deletions

View File

@ -13,7 +13,8 @@ Access raw data with: <?php echoUrl('channels/'); ?>.
<form id="form">
<input type="text" autofocus id="search" pattern="[A-Za-z0-9-_ ]+" placeholder="Your [A-Za-z0-9-_ ]+ search"></input>
<input type="submit" value="Search">
<input type="submit" id="search" value="Search">
<input type="submit" id="search-only-captions" value="Search only captions">
</form>
<ul id="channels">
@ -64,7 +65,7 @@ Access raw data with: <?php echoUrl('channels/'); ?>.
function search(event) {
// We don't want to refresh the webpage which is the default behavior.
event.preventDefault();
const query = document.getElementById('search').value;
const query = event.submitter.id + ' ' + document.getElementById('search').value;
if (firstRun) {
firstRun = false;
conn = new WebSocket('wss://crawler.yt.lemnoslife.com/websocket');

View File

@ -7,6 +7,9 @@ path = '/mnt/HDD0/YouTube_captions_search_engine/channels/'
clientId = sys.argv[1]
message = sys.argv[2]
searchOnlyCaptions = message.startswith('search-only-captions ')
message = message[message.find(' ') + 1:]
clientFilePath = f'users/{clientId}.txt'
def write(s):
@ -31,6 +34,8 @@ 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):