Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2015 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of toktokkie.
6toktokkie is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11toktokkie is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with toktokkie. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import List, Dict, Set
21from toktokkie.utils.update.TvUpdater import TvUpdater, DownloadInstructions
22from torrent_download.exceptions import MissingConfig
23from torrent_download.search import search_engines
24from torrent_download.search.SearchEngine import SearchEngine
25from torrent_download.entities.TorrentDownload import TorrentDownload
26from torrent_download.download.QBittorrentDownloader import \
27 QBittorrentDownloader
30class TorrentUpdater(TvUpdater):
31 """
32 Class that handles the configuration and execution of an xdcc update
33 """
35 @classmethod
36 def name(cls) -> str:
37 """
38 :return: The name of the Updater
39 """
40 return "torrent"
42 @classmethod
43 def search_engine_names(cls) -> Set[str]:
44 """
45 :return: The names of applicable search engines
46 """
47 return {x.name() for x in search_engines}
49 @property
50 def search_engine(self) -> SearchEngine:
51 """
52 :return: The search engine to use
53 """
54 return {
55 x.name(): x for x in search_engines
56 }[self.config["search_engine"]]()
58 @classmethod
59 def predefined_patterns(cls) -> Dict[str, str]:
60 """
61 :return: Predefined search patterns for this updater
62 """
63 return {
64 "erai-raws": "[Erai-raws] @{NAME} - @{EPI-2} "
65 "@{ANY}[@{RES-P}]@{ANY}.mkv",
66 "subsplease": "[SubsPlease] @{NAME} - @{EPI-2} "
67 "(@{RES-P}) [@{HASH}].mkv"
68 }
70 def download(self, download_instructions: List[DownloadInstructions]):
71 """
72 Performs a download
73 :param download_instructions: The download instrcutions
74 :return: None
75 """
76 try:
77 downloader = QBittorrentDownloader.from_config()
78 except MissingConfig:
79 self.logger.warning("Missing torrent-download config."
80 "Run tdl-config-gen.")
81 return
82 torrents = [
83 TorrentDownload(x.search_result, x.directory, x.filename)
84 for x in download_instructions
85 ]
86 downloader.download(torrents)