diff options
Diffstat (limited to 'cogs/utils')
| -rw-r--r-- | cogs/utils/file_search.py | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/cogs/utils/file_search.py b/cogs/utils/file_search.py index 4a2bdc4..2685e25 100644 --- a/cogs/utils/file_search.py +++ b/cogs/utils/file_search.py | |||
| @@ -3,53 +3,13 @@ | |||
| 3 | # Copyright (C) 2026 Salmonik @ salmonik@tuta.io | 3 | # Copyright (C) 2026 Salmonik @ salmonik@tuta.io |
| 4 | # https://codeberg.org/salmonik/senator-sperma | 4 | # https://codeberg.org/salmonik/senator-sperma |
| 5 | 5 | ||
| 6 | """ | ||
| 7 | Universal File Searcher | ||
| 8 | |||
| 9 | This module provides a universal file searcher that can search for different file types: | ||
| 10 | - Audio files (mp3, wav, mp4, opus, m4a, flac, aac, ogg) | ||
| 11 | - Video files (mp4, avi, mkv, mov, wmv, flv, webm, m4v, 3gp) | ||
| 12 | - Image files (jpg, jpeg, png, gif, bmp, tiff, webp, svg, ico) | ||
| 13 | |||
| 14 | Usage Examples: | ||
| 15 | # Search all file types | ||
| 16 | results = await UniversalSearcher.search_local("query") | ||
| 17 | |||
| 18 | # Search only audio files | ||
| 19 | results = await UniversalSearcher.search_local("query", filetype="Audio") | ||
| 20 | |||
| 21 | # Search only video files | ||
| 22 | results = await UniversalSearcher.search_local("query", filetype="Video") | ||
| 23 | |||
| 24 | # Search only image files | ||
| 25 | results = await UniversalSearcher.search_local("query", filetype="Image") | ||
| 26 | |||
| 27 | # Autocomplete search | ||
| 28 | results = await UniversalSearcher.search_local_autocomplete("partial_query", filetype="Video") | ||
| 29 | |||
| 30 | Settings.json structure: | ||
| 31 | { | ||
| 32 | "file_paths": [ | ||
| 33 | "/path/to/your/media/files", | ||
| 34 | "/another/path/with/mixed/content", | ||
| 35 | "relative/path/to/files" | ||
| 36 | ] | ||
| 37 | } | ||
| 38 | |||
| 39 | Note: file_paths should contain directories that may contain any mix of audio, video, | ||
| 40 | and image files. The searcher will filter by file type automatically based on the | ||
| 41 | filetype parameter. | ||
| 42 | """ | ||
| 43 | |||
| 44 | import json | 6 | import json |
| 45 | import logging | 7 | import logging |
| 46 | import re | 8 | import re |
| 47 | import urllib.parse | ||
| 48 | from pathlib import Path | 9 | from pathlib import Path |
| 49 | import aiofiles | 10 | import aiofiles |
| 50 | from rapidfuzz import fuzz | 11 | from rapidfuzz import fuzz |
| 51 | import aiohttp | 12 | import aiohttp |
| 52 | import asyncio | ||
| 53 | import os | 13 | import os |
| 54 | from dotenv import load_dotenv | 14 | from dotenv import load_dotenv |
| 55 | 15 | ||
| @@ -405,7 +365,7 @@ class UniversalSearcher: | |||
| 405 | 365 | ||
| 406 | try: | 366 | try: |
| 407 | baseurl = await UniversalSearcher._load_baseurl() | 367 | baseurl = await UniversalSearcher._load_baseurl() |
| 408 | password = os.getenv("COPYPARTY_R_PASSWORD") | 368 | password = os.getenv("COPYPARTY_PASSWORD") |
| 409 | 369 | ||
| 410 | async with aiohttp.ClientSession() as session: | 370 | async with aiohttp.ClientSession() as session: |
| 411 | headers = {"Content-Type": "application/json"} | 371 | headers = {"Content-Type": "application/json"} |
