# Example usage indexer = MovieIndexer("/path/to/movies") indexer.scan_and_index()
# Example usage query = "intitleindex of hobbit avi" parser = SearchQueryParser(query) results = parser.search(indexer) intitleindex of hobbit avi
class SearchQueryParser: def __init__(self, query): self.query = query file) # Infer title from filename
def scan_and_index(self): for root, dirs, files in os.walk(self.root_dir): for file in files: if file.endswith(".avi"): filename = os.path.join(root, file) # Infer title from filename, for simplicity, let's assume filename without extension is the title title = os.path.splitext(file)[0].lower() self.index[filename] = title title_query): # Simple search
def search_by_title(self, title_query): # Simple search, could be more complex with fuzzy matching, etc. return {filename: title for filename, title in self.index.items() if title_query.lower() in title}
# Searching results = indexer.search_by_title("hobbit") for filename, title in results.items(): print(f"{filename}: {title}") To handle a specific query like "intitleindex of hobbit avi", you might parse the query to extract keywords ("hobbit") and filter results based on those.
def search(self, indexer): keywords = self.parse() results = {} for keyword in keywords: keyword_results = indexer.search_by_title(keyword) results.update(keyword_results) return results