From 18ea01dc33cf5ef8402f4ef9193801bf7288e106 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 28 Mar 2026 00:17:18 +0100 Subject: make it work + visual changes --- cogs/utils/file_search.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'cogs/utils') diff --git a/cogs/utils/file_search.py b/cogs/utils/file_search.py index 8d3e5d6..7100f83 100644 --- a/cogs/utils/file_search.py +++ b/cogs/utils/file_search.py @@ -7,6 +7,7 @@ import json import logging import aiohttp import os +from typing import List from dotenv import load_dotenv from cogs.utils.settings import get_baseurl @@ -19,12 +20,13 @@ class UniversalSearcher: """Handles searching for files via copyparty API.""" @staticmethod - async def search_copyparty(query: str, max_results: int = 25): + async def search_copyparty(query: str, max_results: int = 25, file_extensions: List[str] = None): """Search for files using copyparty API (jPOST method). Args: query: Search query string max_results: Maximum number of results to return + file_extensions: Optional list of file extensions to filter by (e.g., ['mp3', 'wav']) Returns: List of matching file URLs @@ -34,7 +36,16 @@ class UniversalSearcher: query = query.strip() logger.info(f"Starting copyparty search for query: '{query}'") - query = f'name like "*{query}*"' + + # Build the query with optional extension filtering + name_query = f'name like "*{query}*"' + if file_extensions: + # Create extension filters using copyparty's .ext$ syntax + ext_filters = [f"name like \"*.{ext.lower()}\"" for ext in file_extensions] + ext_query = " or ".join(ext_filters) + query = f"{name_query} and ({ext_query})" + else: + query = name_query try: baseurl = get_baseurl() @@ -115,7 +126,7 @@ class UniversalSearcher: @staticmethod async def search_copyparty_autocomplete(query: str, max_results: int = 10): - """Wrapper for autocomplete searches using copyparty. + """Wrapper for autocomplete searches using copyparty (general search - no file type filtering). Args: query: Search query string @@ -128,3 +139,21 @@ class UniversalSearcher: return [] return await UniversalSearcher.search_copyparty(query, max_results) + + @staticmethod + async def search_copyparty_autocomplete_audio(query: str, max_results: int = 10): + """Wrapper for autocomplete searches using copyparty (audio files only). + + Args: + query: Search query string + max_results: Maximum number of results to return + + Returns: + List of matching file URLs (audio files only) + """ + if not query: + return [] + + # Audio file extensions for music commands + audio_extensions = ['mp3', 'wav', 'flac', 'ogg', 'm4a', 'aac', 'mp4', "mkv"] + return await UniversalSearcher.search_copyparty(query, max_results, audio_extensions) -- cgit v1.2.3