WebAPI: Add a way to download .torrent file using search plugin

* Simplify nova2dl script
* Use search engine name instead of site URL (like nova2 does)
* Add a way to download torrent using search plugin

PR #20824.
This commit is contained in:
Vladimir Golovnev
2024-05-15 08:47:40 +03:00
committed by GitHub
parent 2c47f09d7a
commit 4d8713ce11
11 changed files with 89 additions and 50 deletions

View File

@@ -1,7 +1,9 @@
#VERSION: 1.23
#VERSION: 1.24
# Author:
# Christophe DUMEZ (chris@qbittorrent.org)
# Contributors:
# Vladimir Golovnev (glassez@yandex.ru)
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -27,9 +29,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import glob
import importlib
import os
import pathlib
import sys
@@ -40,34 +40,24 @@ if current_path not in sys.path:
from helpers import download_file
supported_engines = dict()
engines = glob.glob(os.path.join(os.path.dirname(__file__), 'engines', '*.py'))
for engine in engines:
e = engine.split(os.sep)[-1][:-3]
if len(e.strip()) == 0:
continue
if e.startswith('_'):
continue
try:
module = importlib.import_module("engines." + e)
engine_class = getattr(module, e)
globals()[e] = engine_class
engine_url = getattr(engine_class, 'url')
supported_engines[engine_url] = e
except Exception:
pass
if __name__ == '__main__':
if len(sys.argv) < 3:
raise SystemExit('./nova2dl.py engine_url download_parameter')
engine_url = sys.argv[1].strip()
raise SystemExit('./nova2dl.py engine_name download_parameter')
engine_name = sys.argv[1].strip()
download_param = sys.argv[2].strip()
if engine_url not in supported_engines.keys():
raise SystemExit('./nova2dl.py: this engine_url was not recognized')
engine = globals()[supported_engines[engine_url]]()
try:
module = importlib.import_module("engines." + engine_name)
engine_class = getattr(module, engine_name)
engine = engine_class()
except Exception as e:
print(repr(e))
raise SystemExit('./nova2dl.py: this engine_name was not recognized')
if hasattr(engine, 'download_torrent'):
engine.download_torrent(download_param)
else:
print(download_file(download_param))
sys.exit(0)