├── lib ├── __init__.py ├── Config.py ├── Torrent.py ├── Search.py └── Display.py ├── .gitignore ├── downloader.png ├── requirements.txt ├── Dockerfile ├── docker └── Dockerfile ├── README.md ├── cerberus.py └── LICENSE.md /lib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | tv/ 3 | mov/ 4 | cerberus.ini 5 | -------------------------------------------------------------------------------- /downloader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/th3r00t/Cerberus/HEAD/downloader.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests == 2.28.0 2 | libtorrent == 2.0.6 3 | beautifulsoup4 == 4.11.1 4 | html5lib == 1.1 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | from archlinux:latest 2 | RUN pacman -Syy 3 | RUN pacman -S openssh git python python-pip libtorrent --noconfirm 4 | RUN useradd cerberus 5 | RUN echo "b2edxfrr1" | passwd cerberus 6 | RUN mkdir /home/cerberus 7 | RUN chown cerberus:cerberus /home/cerberus 8 | RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config 9 | RUN systemctl enable --now sshd.service 10 | EXPOSE 22 11 | RUN su cerberus 12 | RUN cd /home/cerberus 13 | RUN git clone https://github.com/th3root/Cerberus.git . 14 | RUN cd Cerberus/ 15 | RUN pip install --user -r requirements.txt 16 | 17 | ENTRYPOINT ["python", "cerberus.py"] -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | from archlinux:latest 2 | RUN pacman -Syy 3 | RUN pacman -Syu --noconfirm 4 | RUN pacman -S openssh wget python python-pip libtorrent --noconfirm 5 | COPY id_rsa.pub /root/.ssh/authorized_keys 6 | RUN sed -i 's/#PermitRootlogin prohibit-password/PermitRootlogin prohibit-password/g' /etc/ssh/sshd_config 7 | EXPOSE 22 8 | RUN mkdir /root/build 9 | WORKDIR /root/build 10 | RUN wget 'https://github.com/th3r00t/Cerberus/releases/download/release/cerberus.tar.gz' 11 | RUN tar -xvzf cerberus.tar.gz 12 | RUN pip install -r requirements.txt 13 | ENV TERM=xterm 14 | ENV TERMINFO=/usr/lib/terminfo 15 | ENTRYPOINT sh -c /usr/bin/bash -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cerberus 2 | ### Discord @ https://discord.gg/9Zz3TRS8q7 3 | ![Alt text](./downloader.png?raw=true "Cerberus") 4 | A simple, fast, and lightweight torrent aggregator. 5 | Written in python leveraging C libs like libtorrent, and curses 6 | Cerberus is a lightweight solution for finding and downloading 7 | torrents. 8 | 9 | ## Configuration 10 | `cd cerberus/` 11 | 12 | `pip install -r requirements` 13 | 14 | `python3 cerberus.py` 15 | 16 | 17 | After the first run you will find cerberus.ini in Cerberus's root 18 | directory. Set the StorageMaps section to the network or local file system 19 | path for each category. 20 | 21 | ## Planned Improvements 22 | > Better output formating 23 | 24 | > Saved searches 25 | 26 | > Resume functionality 27 | 28 | > web frontend 29 | 30 | ## Disclaimer 31 | *Cerberus is for research use only.* 32 | 33 | *The author is not responsible for how you use this software.* 34 | 35 | *Cerberus does not obsfucate your traffic. You are expected to handle your own traffic routing.* 36 | 37 | ## Enjoy! 38 | -------------------------------------------------------------------------------- /lib/Config.py: -------------------------------------------------------------------------------- 1 | # Cerberus, Torrent Aggregator 2 | # Copyright (C) 2022 th3r00t 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | 18 | import configparser 19 | from pathlib import Path 20 | 21 | 22 | class Config: 23 | def __init__(self): 24 | self.endpoints = {} 25 | self.tvdbkey = "" 26 | self.moviedbkey = "" 27 | self.storagemaps = {} 28 | if not Path('./cerberus.ini').is_file(): 29 | self.mkconfig() 30 | else: 31 | self.getconfig() 32 | 33 | @staticmethod 34 | def mkconfig(): 35 | # 36 | _file = configparser.ConfigParser() 37 | _file["Endpoints"] = { 38 | "tpbmv": "https://thepiratebay.rocks/search/{}/1/99/201", # Movies 39 | "tpbtv": "https://thepiratebay.rocks/search/{}/1/99/205", # Tv 40 | "tpbgm": "https://thepiratebay.rocks/search/{}/1/99/400", # Games 41 | "tpbms": "https://thepiratebay.rocks/search/{}/1/99/100", # Music 42 | "tpbab": "https://thepiratebay.rocks/search/{}/1/99/102", # ABooks 43 | "tpbeb": "https://thepiratebay.rocks/search/{}/1/99/601", # EBooks 44 | "tpbcm": "https://thepiratebay.rocks/search/{}/1/99/602", # Comics 45 | "tpbca": "https://thepiratebay.rocks/search/{}/1/99/0", # CatchAll 46 | } 47 | _file["Storage"] = { 48 | "tv": "./tv", 49 | "mv": "./mov", 50 | "gm": "./games", 51 | "ms": "./music", 52 | "ab": "./abook", 53 | "eb": "./ebook", 54 | "cm": "./comic", 55 | "ca": "./other" 56 | } 57 | with open(r"cerberus.ini", 'w') as configObj: 58 | _file.write(configObj) 59 | configObj.flush() 60 | configObj.close() 61 | 62 | def getconfig(self): 63 | _file = configparser.ConfigParser() 64 | _file.read('./cerberus.ini') 65 | for endpoint in _file["Endpoints"]: 66 | self.endpoints[endpoint] = _file["Endpoints"][endpoint] 67 | for _path in _file["Storage"]: 68 | self.storagemaps[_path] = _file["Storage"][_path] 69 | -------------------------------------------------------------------------------- /lib/Torrent.py: -------------------------------------------------------------------------------- 1 | # Cerberus, Torrent Aggregator 2 | # Copyright (C) 2022 th3r00t 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | 18 | import libtorrent as lt 19 | import time 20 | import asyncio 21 | 22 | 23 | class Client: 24 | def __init__(self, storagemaps): 25 | self.session = lt.session({'listen_interfaces': '0.0.0.0:6881'}) 26 | self.active_torrents = [] 27 | self.status = self.session.status() 28 | self.storage_maps = storagemaps 29 | 30 | async def Add(self, uri, savePath): 31 | if int(savePath) == 1: 32 | savePath = self.storage_maps['tv'] 33 | elif int(savePath) == 2: 34 | savePath = self.storage_maps['mv'] 35 | elif int(savePath) == 3: 36 | savePath = self.storage_maps['gm'] 37 | elif int(savePath) == 4: 38 | savePath = self.storage_maps['ms'] 39 | elif int(savePath) == 5: 40 | savePath = self.storage_maps['ab'] 41 | elif int(savePath) == 6: 42 | savePath = self.storage_maps['eb'] 43 | elif int(savePath) == 7: 44 | savePath = self.storage_maps['cm'] 45 | else: 46 | savePath = self.storage_maps['mv'] 47 | params = { 48 | 'save_path': savePath, 49 | 'storage_mode': lt.storage_mode_t(2), 50 | } 51 | try: 52 | handle = lt.add_magnet_uri(self.session, uri, params) 53 | await asyncio.sleep(.2) 54 | self.active_torrents.append(handle) 55 | except Exception as e: 56 | print(e) 57 | 58 | def Manage(self): 59 | _response = [] 60 | if self.active_torrents.__len__() > 0: 61 | for i in self.active_torrents: 62 | status = i.status() 63 | _cur_time = time.strftime("%H:%M:%S", time.localtime()) 64 | _progress = format((status.progress * 100), ".2f") 65 | _download_rate = format((status.download_rate / 1000), ".1f") 66 | _upload_rate = format((status.upload_rate / 1000), ".1f") 67 | _peers = status.num_peers 68 | _name = i.name() 69 | _response.append([_name, _progress, _download_rate, _upload_rate, _peers]) 70 | # _response = "{} Progress {} Download {} kB/s Upload {} kB/s {} Peers {}".format(_name, _progress, _download_rate, _upload_rate, _peers, _cur_time) 71 | return _response 72 | else: 73 | return ["No Active Downloads", "", "", "", ""] 74 | -------------------------------------------------------------------------------- /lib/Search.py: -------------------------------------------------------------------------------- 1 | # Cerberus, Torrent Aggregator 2 | # Copyright (C) 2022 th3r00t 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | 18 | import requests 19 | from bs4 import BeautifulSoup 20 | 21 | # https://thepiratebay10.org/search/west%20wing/1/99/0 22 | 23 | 24 | class Search: 25 | 26 | def __init__(self, config): 27 | self.endpoints = config 28 | self.response = None 29 | self.query = None 30 | 31 | def search(self, query=None, type=1): 32 | self.query = query 33 | self.query = self.query.strip() 34 | self.response = self.get_response(type) 35 | return self.response 36 | 37 | def make_query(self): 38 | pass 39 | 40 | def get_response(self, type): 41 | type = int(type) 42 | _response = [] 43 | if type == 1: 44 | ep_type_requested = "tv" 45 | elif type == 2: 46 | ep_type_requested = "mv" 47 | elif type == 3: 48 | ep_type_requested = "gm" 49 | elif type == 4: 50 | ep_type_requested = "ms" 51 | elif type == 5: 52 | ep_type_requested = "ab" 53 | elif type == 6: 54 | ep_type_requested = "eb" 55 | elif type == 7: 56 | ep_type_requested = "cm" 57 | else: 58 | ep_type_requested = "mv" 59 | for ep in self.endpoints: 60 | ep_type = ep[-2:] 61 | if ep_type == ep_type_requested: 62 | _str_split = self.endpoints[ep].split('{}') 63 | _query = _str_split[0] + self.query + _str_split[1] 64 | _response.append(requests.get(_query)) 65 | else: 66 | continue 67 | return self.parse_results(_response) 68 | 69 | def parse_results(self, results): 70 | parse_out = [] 71 | for result in results: 72 | soup = BeautifulSoup(result.content, 'html.parser') 73 | searchResults = soup.find(id='searchResult') 74 | # srBody = searchResults.find('tbody') 75 | rows = searchResults.find_all('tr') 76 | for row in rows[1:-1]: 77 | try: 78 | cols = row.find_all('td') 79 | name = cols[1].find('div', class_='detName') 80 | name = name.text.strip() 81 | magnet = cols[1].find_all('a') 82 | magnet = magnet[1].attrs['href'] 83 | desc = cols[1].find('font', class_='detDesc') 84 | desc = desc.text 85 | parse_out.append([name, magnet, desc]) 86 | except Exception: 87 | pass 88 | return parse_out 89 | -------------------------------------------------------------------------------- /cerberus.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Cerberus, Torrent Aggregator 3 | # Copyright (C) 2022 th3r00t 4 | 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License along 16 | # with this program; if not, write to the Free Software Foundation, Inc., 17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | 19 | import asyncio 20 | import argparse 21 | import locale 22 | import time 23 | import curses 24 | from lib.Torrent import Client 25 | from lib.Display import Display 26 | from lib.Config import Config 27 | from lib.Search import Search 28 | 29 | locale.setlocale(locale.LC_ALL, '') 30 | icode = locale.getpreferredencoding() 31 | state = 0 32 | keypress = None 33 | config = Config() 34 | magnets = [] 35 | run = True 36 | Cerberus = { 37 | 'Config': config, 38 | 'TorrentManager': Client(config.storagemaps), 39 | 'Display': Display(), 40 | 'Search': Search(config.endpoints) 41 | } 42 | Cerberus["Config"].getconfig() 43 | 44 | logo = """ 45 | : .:: ^ ~~!7777??????????777!!~^: . .: : 46 | . ^J~ .J?~^!!~^^::............::^~~!!^!J! .77 . 47 | ::^.^!7^~J~??^ :!J!7J.7~? ^::. 48 | .~7J?~^.!.:^77: 7!?~. ..::. :!77~ ~J^~ !^.~7J?!^. 49 | :!?J7^..^.!: :^?^ ~!.J? .^!^^~?YY7~:~~: ^5!.?. .!!^. ~::^ :~?J?~. 50 | .5J: !~ .^:J: ^77 .77...:^!JYY?~:...^?^ ^?7. 7!^: ?: .~5? 51 | .5J :^J::^!.~! JJ!. .?7?777JYYYY?77??7! ^7Y~.?.^!^:~?: :57 52 | J5. .:!7~?7JJ7::!7YJ!^. .7~~755Y55J!~!~ :^?YJ!~.~?JJ!7~7^. ~P~ 53 | ~?:^:~J?JYYY7^ ~7JY?!^.::^!JYYY5Y55YYY?!^:::~7JY77:.~JYYY?Y7^^:~J. 54 | .^~^.^?YJ55J7~~~YY5J~!^YP5555JJJYYYJJJY5555P7~~7YY57^~!?Y5YJY!::~~: 55 | .7^...^7!7?!~^::^???Y~:P5Y?7?7!!!?7JJ?7!~7?7?J5P?.?Y7Y~^::^~7?!!!:..:~! 56 | .!^^!7?5J?YJ7~. ^7^JJ~YYJ?~^^...!!!??!!^ .:^^!JY5?!Y7~7. :!?YY75J77~:!~ 57 | ^J~YJJ57^PY?~~: 7!~5J?!?PY5YJ!^.:!!77!~ :^?JYY55!7JYJ^?^ .^~!J5Y^Y5?JJ~J 58 | ~5J~7?J?JY?!~: ~7:!YY? 7B5YYPG5J~^777!^7YPP5YYGP.:YYY.!7: ^~7JY??J?~7YJ: 59 | :^^~JYJJ????~~~~^::7^7J7Y^.~YJ7!J55Y7JJY??5557!7Y?^.7J!J^!!::^~~~!????JYJ7^^^. 60 | .::^!JY55P55J?77!!!!:~?~~Y^~J!:7B7~^^~?YJYYJY!^:~^PG:^7J:7Y:?7:^!!!77??Y5P555Y?~^::. 61 | .~~::!YPP5YJY5Y?!~^^^!!:.J7^Y?~?5J~?JJ~:^~~?YY!~^::??J!!Y5!!5?^J7.~!~^^~~7J5YYYYPG5?^:^~^. 62 | :77.^!J5Y?!~~!!77~:..~^?7~..?? 757~7GPYJ!^^^:!JYYJ~:^^~?JYG5~~J5.~J! :!?!~:..:~!!!~~~7J5Y?~:^J~. 63 | .7!J755Y7~^~^~~^:. .^77!!~:.::7~^~??^!555YJ7!^!JYY?^~!?Y55PY^!J~~:7~::.^~7!7!:. .:^^~^^^!?55Y7?!! 64 | .7?~!??!!~: :.~7JJ!^::^.:.!?!. 7Y77555G5Y7^7YY~~?YPGY5J7?Y~ ^7J::::^::~?Y?!::. .~~!7?7~!J^. 65 | .:!^?P^ :::7?JYY?7~: :Y7 ^:??~~~^!~^^?Y7~~?YJ7~!JY!^^!~~^!!J!:: .J7 .^!7JYJJ7!.^ ?P~~~.. 66 | :: :J7?77?J!. ^Y?. .:77!7~ :!557!JYY7!JP?~. :!7!?~. ^Y?. :?J77???7 :. 67 | :^:~7!: .JY^ .~??~ ?J5GY?7??7J5GYY^ 7?7.. 75! ^!!^:^. 68 | !57. .J?.?Y57~!777!!^5YY^^J! :YY: 69 | :JY^ :7?^~7J77~~~!7?J!^!?~: .75! 70 | ~Y?: :7!.~7!~:..^!7!::?! ~YJ: 71 | .7Y7. ~7^~^~777!^^~~7: ^JY~ 72 | :?Y7. .^!~^~!~^^7~:. ^JY! 73 | :?Y7. ^^~7!^^: ^JY!. 74 | :7Y7: ~JJ~. 75 | .!YJ~ .!JJ^ 76 | ~?J7:^?Y7: 77 | :!J?~. 78 | 79 | """ 80 | 81 | 82 | def header_text(): 83 | return Text("=== Welcome To Cerberus ===", 84 | justify="center", 85 | style="bold magenta") 86 | 87 | 88 | async def keybinds(): 89 | global state, run 90 | key = Cerberus['Display'].stdscr.getch() 91 | if key != -1: 92 | if key == ord('q'): 93 | Cerberus['Display'].kill() 94 | run = False 95 | elif key == ord('/'): 96 | search = await Cerberus['Display'].search_prompt(Cerberus['Config'], Cerberus['TorrentManager']) 97 | await asyncio.sleep(.2) 98 | return False 99 | 100 | 101 | async def application_loop(): 102 | global state 103 | Cerberus['Display'].mkheader(), 104 | Cerberus['Display'].mkfooter() 105 | while run: 106 | if state == 0: 107 | Cerberus['Display'].mkheader(), 108 | Cerberus['Display'].mkbody(Cerberus['TorrentManager'].Manage()), 109 | Cerberus['Display'].mkfooter() 110 | Cerberus['Display'].stdscr.refresh() 111 | await keybinds() 112 | await asyncio.sleep(.2) 113 | if state == 1: 114 | Cerberus['Display'].mkheader(), 115 | Cerberus['Display'].mkbody(Cerberus['TorrentManager'].Manage()), 116 | Cerberus['Display'].mkfooter() 117 | Cerberus['Display'].stdscr.refresh() 118 | await keybinds() 119 | await asyncio.sleep(.2) 120 | if state == 2: 121 | Cerberus['Display'].mkheader(), 122 | Cerberus['Display'].mkbody(Cerberus['TorrentManager'].Manage()), 123 | Cerberus['Display'].mkfooter() 124 | Cerberus['Display'].stdscr.refresh() 125 | await keybinds() 126 | await asyncio.sleep(.2) 127 | return "Finished" 128 | 129 | 130 | async def main(): 131 | """Enter The Realm Of Cerberus.""" 132 | global Cerberus 133 | 134 | parser = argparse.ArgumentParser() 135 | parser.add_argument("-c", "--config") 136 | parser.add_argument("-s", "--search") 137 | args = parser.parse_args() 138 | 139 | if args.config: 140 | print(f"Config {args.config}.") 141 | elif args.search: 142 | _response = Cerberus['Search'].search(args.search) 143 | for _r in _response: 144 | print(_r.text) 145 | 146 | else: 147 | await application_loop() 148 | await asyncio.sleep(.2) 149 | print() 150 | return False 151 | 152 | 153 | if __name__ == "__main__": 154 | asyncio.run(main()) 155 | # Cerberus['Display'].kill() 156 | -------------------------------------------------------------------------------- /lib/Display.py: -------------------------------------------------------------------------------- 1 | # Cerberus, Torrent Aggregator 2 | # Copyright (C) 2022 th3r00t 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 2 of the License, or 7 | # (at your option) any later version. 8 | 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | 14 | # You should have received a copy of the GNU General Public License along 15 | # with this program; if not, write to the Free Software Foundation, Inc., 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 | 18 | import curses 19 | import time 20 | import asyncio 21 | from curses.textpad import Textbox 22 | from curses.textpad import rectangle 23 | from .Search import Search 24 | 25 | 26 | class Display: 27 | """Cerberus's Main Display Class.""" 28 | 29 | def __init__(self): 30 | """Initializa The Display Settings.""" 31 | self.stdscr = curses.initscr() 32 | self.stdscr.nodelay(1) 33 | self.stdscr.clear() 34 | curses.noecho() 35 | curses.cbreak() 36 | curses.curs_set(0) 37 | self.rows, self.cols = self.stdscr.getmaxyx() 38 | self.middle_row = int(self.rows / 2) 39 | self.middle_col = int(self.cols / 2) 40 | self.header_msg = "=== Welcome To Cerberus ===" 41 | self.header = curses.newwin(3, self.cols, 0, 0) 42 | self.body = curses.newwin(self.rows - 6, self.cols, 3, 0) 43 | self.footer = curses.newwin(3, self.cols, self.rows - 3, 0) 44 | self.header.box() 45 | # self.body.box() 46 | self.footer.box() 47 | 48 | def mkheader(self): 49 | """Create Main U/I Header.""" 50 | self.header.clear() 51 | self.print_middle_center(self.header_msg, self.header) 52 | self.print_middle_right("q to quit", self.header) 53 | self.header.box() 54 | self.header.refresh() 55 | 56 | def mkbody(self, msg): 57 | """Create Main U/I Body.""" 58 | self.body.clear() 59 | self.body.addstr(0, 0, self.format_body(msg)) 60 | # self.body.box() 61 | self.body.refresh() 62 | 63 | def mkfooter(self, msg="/ To Search"): 64 | """Create Main U/I Footer.""" 65 | self.footer.clear() 66 | self.footer.addstr(1, 2, msg) 67 | self.footer.box() 68 | self.footer.refresh() 69 | 70 | def print_middle_center(self, msg, window): 71 | """Print Msg Aligned V & H Center.""" 72 | _window_row, _window_col = window.getmaxyx() 73 | _ip = int((_window_col / 2) - (len(msg) / 2)) 74 | window.addstr(int(_window_row / 2), _ip, msg) 75 | 76 | def print_middle_right(self, msg, window): 77 | """Print Msg Aligned V Center, H Right.""" 78 | _window_row, _window_col = window.getmaxyx() 79 | _ip = int(_window_col - len(msg) - 3) 80 | window.addstr(int(_window_row / 2), _ip, msg) 81 | 82 | async def search_prompt(self, config, torrent_manager): 83 | """Cerberus Search Prompt Loop.""" 84 | # footer = curses.newwin(3, self.cols, self.rows - 3, 0) 85 | prompt_window = curses.newwin(1, self.cols-20, self.rows - 2, 14) 86 | box = Textbox(prompt_window) 87 | curses.curs_set(1) 88 | prompt_window.refresh() 89 | box.edit() 90 | _search = box.gather() 91 | self.body.clear() 92 | # self.body.box() 93 | self.footer.clear() 94 | self.mkfooter("Select 1:Tv Show, 2:Movie, 3:Game, 4:Music, 5:Audio Book, 6:E-Book, 7:Comic, 8:Other > ") 95 | prompt_window = curses.newwin(1, self.cols-45, self.rows - 2, 89) 96 | box = Textbox(prompt_window) 97 | prompt_window.clear() 98 | box.edit() 99 | self.mkbody 100 | _type = box.gather() 101 | curses.curs_set(0) 102 | self.body.refresh() 103 | await asyncio.sleep(1) 104 | search_results = Search(config.endpoints).search(_search, _type) 105 | magnets, scrnout = self.format_body(search_results, 1, True) 106 | self.body.addstr(scrnout) 107 | # self.body.box() 108 | self.body.refresh() 109 | self.footer.clear() 110 | self.mkfooter("Select # To Download > ") 111 | prompt_window = curses.newwin(1, self.cols-45, self.rows - 2, 25) 112 | prompt_window.clear() 113 | box = Textbox(prompt_window) 114 | curses.curs_set(1) 115 | box.edit() 116 | choice = box.gather() 117 | curses.curs_set(0) 118 | try: 119 | choice = int(choice) 120 | try: 121 | link = magnets[int(choice)] 122 | await torrent_manager.Add(link, _type) 123 | await asyncio.sleep(1) 124 | except KeyError: 125 | pass 126 | except ValueError: 127 | return False 128 | return choice 129 | 130 | def format_body(self, results, page=1, search=False): 131 | """Cerberus Main Body Formating.""" 132 | _msg_body = "" 133 | _mY, _mX = self.body.getmaxyx() 134 | _mY -= 2 135 | _mX -= 2 136 | i = 0 137 | if not search: 138 | for r in results: 139 | if i < _mY: 140 | try: 141 | if len("{} {} {} {} {}".format(r[0], r[1], r[2], r[3], r[4])) < _mX: 142 | _msg_body += "\t{}\t{}% complete\tdn: {}kB/s\tup: {}kB/s\t{} peers.\n".format(r[0], r[1], r[2], r[3], r[4]) 143 | else: 144 | overflow = len("{} {} {} {} {}".format(r[0], r[1], r[2], r[3], r[4])) - _mX 145 | _msg_body += "\t{}\t{}% complete\tdn: {}kB/s\tup: {}kB/s\t{} peers.\n".format(r[0][0:-overflow], r[1], r[2], r[3], r[4]) 146 | except IndexError: 147 | return "No Active Torrents" 148 | i = i = 1 149 | else: 150 | return _msg_body 151 | return _msg_body 152 | elif search: 153 | magnets = [] 154 | i = 0 155 | for r in results: 156 | magnets.append(r[1]) 157 | _msg_body += "{}: {} {}\n".format(i, r[0], r[2]) 158 | i += 1 159 | msg = [magnets, _msg_body] 160 | return msg 161 | 162 | def kill(self): 163 | """Kill The Display.""" 164 | curses.nocbreak() 165 | self.stdscr.keypad(False) 166 | curses.echo() 167 | self.stdscr.nodelay(0) 168 | curses.endwin() 169 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------