Correctly handle "torrent finished" events
[qBittorrent.git] / src / searchengine / nova3 / nova2dl.py
blobc35646654f11d7c5c1becb237cd7e897ff719325
1 #VERSION: 1.24
3 # Author:
4 # Christophe DUMEZ (chris@qbittorrent.org)
5 # Contributors:
6 # Vladimir Golovnev (glassez@yandex.ru)
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
11 # * Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of the author nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
32 import importlib
33 import pathlib
34 import sys
36 # qbt tend to run this script in 'isolate mode' so append the current path manually
37 current_path = str(pathlib.Path(__file__).parent.resolve())
38 if current_path not in sys.path:
39 sys.path.append(current_path)
41 from helpers import download_file
43 if __name__ == '__main__':
44 if len(sys.argv) < 3:
45 raise SystemExit('./nova2dl.py engine_name download_parameter')
47 engine_name = sys.argv[1].strip()
48 download_param = sys.argv[2].strip()
50 try:
51 module = importlib.import_module("engines." + engine_name)
52 engine_class = getattr(module, engine_name)
53 engine = engine_class()
54 except Exception as e:
55 print(repr(e))
56 raise SystemExit('./nova2dl.py: this engine_name was not recognized')
58 if hasattr(engine, 'download_torrent'):
59 engine.download_torrent(download_param)
60 else:
61 print(download_file(download_param))
63 sys.exit(0)