Improve abstraction of search plugin

To make intentions clear and avoid misuse.
Now it should be possible to inherit `Engine` class and create an usable subclass from it.

PR #23232.
This commit is contained in:
Chocobo1 2025-09-07 17:50:39 +08:00 committed by GitHub
parent 5c0010ac6c
commit 94ef038f3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
# VERSION: 1.49 # VERSION: 1.50
# Author: # Author:
# Fabien Devaux <fab AT gnux DOT info> # Fabien Devaux <fab AT gnux DOT info>
@ -39,6 +39,7 @@ import sys
import traceback import traceback
import urllib.parse import urllib.parse
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from abc import ABC, abstractmethod
from collections.abc import Iterable from collections.abc import Iterable
from enum import Enum from enum import Enum
from glob import glob from glob import glob
@ -77,19 +78,21 @@ Category = Enum('Category', ['all', 'anime', 'books', 'games', 'movies', 'music'
EngineModuleName = str # the filename of the engine plugin EngineModuleName = str # the filename of the engine plugin
class Engine: class Engine(ABC):
url: str
name: str name: str
url: str
supported_categories: dict[str, str] supported_categories: dict[str, str]
def __init__(self) -> None: @abstractmethod
pass def search(self, query: str, category: str = Category.all.name) -> None:
#novaprinter.prettyPrinter()
raise NotImplementedError
def search(self, what: str, cat: str = Category.all.name) -> None: """
pass Provide customized .torrent file download implementation. For example in your own subclass:
def download_torrent(self, url: str) -> None:
def download_torrent(self, info: str) -> None: print(helpers.download_file(url))
pass """
# global state # global state