├── pirate ├── __init__.py ├── data │ ├── blacklist.json │ ├── sorts.json │ └── categories.json ├── data.py ├── local.py ├── print.py ├── torrent.py └── pirate.py ├── tests ├── __init__.py ├── data │ ├── blocked.html │ ├── no_hits.json │ ├── db.csv │ ├── debian_iso.json │ ├── rich.xml │ └── result.json ├── util.py ├── test_version.py ├── test_local.py ├── test_print.py ├── test_torrent.py └── test_pirate.py ├── requirements.txt ├── requirements-test.txt ├── renovate.json ├── .coveragerc ├── circle.yml ├── .gitignore ├── setup.py ├── README.md └── LICENSE /pirate/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/data/blocked.html: -------------------------------------------------------------------------------- 1 | blocked. 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # this is a reference to setup.py 2 | . 3 | -------------------------------------------------------------------------------- /requirements-test.txt: -------------------------------------------------------------------------------- 1 | -r requirements.txt 2 | coverage 3 | coveralls 4 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = True 3 | [report] 4 | include = /home/ubuntu/pirate-get/* 5 | omit = */tests/*,*__init__* 6 | [html] 7 | directory = /home/ubuntu/pirate-get/htmlcov/ 8 | -------------------------------------------------------------------------------- /pirate/data/blacklist.json: -------------------------------------------------------------------------------- 1 | [ 2 | "https://thebay.tv", 3 | "https://piratebaymirror.eu", 4 | "http://proxyspotting.in", 5 | "https://proxyspotting.in", 6 | "https://knaben.xyz/ThePirateBay.php" 7 | ] 8 | -------------------------------------------------------------------------------- /tests/util.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def data_path(name): 4 | return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', name) 5 | 6 | def open_data(name): 7 | return open(data_path(name)) 8 | -------------------------------------------------------------------------------- /tests/data/no_hits.json: -------------------------------------------------------------------------------- 1 | [{"id":"0","name":"No results returned","info_hash":"0000000000000000000000000000000000000000","leechers":"0","seeders":"0","num_files":"0","size":"0","username":"","added":"0","status":"member","category":"0","imdb":"","total_found":"1"}] 2 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/python:3.6 6 | steps: 7 | - checkout 8 | - run: pip install -r requirements-test.txt 9 | - run: coverage run -m unittest discover 10 | - run: coveralls 11 | -------------------------------------------------------------------------------- /pirate/data/sorts.json: -------------------------------------------------------------------------------- 1 | { 2 | "TitleDsc": [1, "name", true], 3 | "TitleAsc": [2, "name", false], 4 | "DateDsc": [3, "raw_uploaded", true], 5 | "DateAsc": [4, "raw_uploaded", false], 6 | "SizeDsc": [5, "raw_size", true], 7 | "SizeAsc": [6, "raw_size", false], 8 | "SeedersDsc": [7, "seeders", true], 9 | "SeedersAsc": [8, "seeders", false], 10 | "LeechersDsc": [9, "leechers", true], 11 | "LeechersAsc": [10, "leechers", false], 12 | "CategoryDsc": [13, "category", true], 13 | "CategoryAsc": [14, "category", false], 14 | "Default": [99, "seeders", true] 15 | } 16 | -------------------------------------------------------------------------------- /pirate/data.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pkgutil 3 | 4 | 5 | def get_resource(filename): 6 | return pkgutil.get_data(__package__, 'data/' + filename) 7 | 8 | 9 | version = '0.4.2' 10 | 11 | categories = json.loads(get_resource('categories.json').decode()) 12 | sorts = json.loads(get_resource('sorts.json').decode()) 13 | blacklist = set(json.loads(get_resource('blacklist.json').decode())) 14 | 15 | default_headers = {'User-Agent': 'pirate get'} 16 | default_timeout = 10 17 | 18 | default_mirror = 'https://apibay.org' 19 | mirror_list = 'https://proxy-bay.app/list.txt' 20 | -------------------------------------------------------------------------------- /tests/data/db.csv: -------------------------------------------------------------------------------- 1 | #ADDED;HASH(B64);NAME;SIZE(BYTES) 2 | 2018-May-14 11:05:31;NJMGdO87uTF/tfJjzKgw9SaFI1s=;"ubuntu-14.04.5-desktop-amd64.iso";1104052224 3 | 2018-Apr-15 00:04:09;8H4LBYR0W3vLNemAl0iNNOaGI9A=;"Ubuntu 17.10.1 Desktop (amd64)";1502576640 4 | 2017-Aug-01 15:08:07;QJbsEpQEaJzrgFbZB+OE/4csLOk=;"LINUX UBUNTU 16.10 32X64";1610612736 5 | 2011-Sep-08 05:09:05;ckpvsYAbR5lzUYMQObadGXuIzGo=;"Ron White: They Call Me \"Tater Salad\"(2004)DVDRip.AC3(ENG)-D";732773299 6 | 2018-May-24 04:05:43;qgqKW9ViZkP7DaZOwCPO6GmXi7M=;"Lovita Fate & Lindsey Cruz (Cooze Cruz)\";3593992996 7 | 2018-May-26 18:05:44;f0A6IspuoBd8Bb/uLhaqPZLhjYc=;"A.Return.to.Salem&#039;s.Lot.1987.DVDRip.x264";2026593072 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | .virtualenv 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *,cover 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | # vim 62 | *.swp 63 | 64 | # setup.py 65 | publish/* 66 | 67 | .pypirc 68 | -------------------------------------------------------------------------------- /tests/test_version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os.path 4 | import unittest 5 | import importlib 6 | from unittest import mock 7 | from unittest.mock import patch, call, MagicMock 8 | 9 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 10 | 11 | import setup 12 | 13 | class TestPirate(unittest.TestCase): 14 | 15 | @patch('sys.exit') 16 | def test_unsupported(self, mock_exit): 17 | sys.version = '3.2.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' 18 | importlib.reload(setup) 19 | mock_exit.assert_called_once_with(1) 20 | 21 | @patch('sys.exit') 22 | def test_unsupported2(self, mock_exit): 23 | sys.version = '2.5.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' 24 | importlib.reload(setup) 25 | mock_exit.assert_called_once_with(1) 26 | 27 | 28 | @patch('sys.exit') 29 | def test_supported(self, mock_exit): 30 | sys.version = '3.5.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' 31 | importlib.reload(setup) 32 | mock_exit.assert_not_called() 33 | 34 | @patch('sys.exit') 35 | def test_supported_exact(self, mock_exit): 36 | sys.version = '3.4.0 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' 37 | importlib.reload(setup) 38 | mock_exit.assert_not_called() 39 | 40 | if __name__ == '__main__': 41 | unittest.main() 42 | -------------------------------------------------------------------------------- /pirate/data/categories.json: -------------------------------------------------------------------------------- 1 | { 2 | "All": 0, 3 | "Applications": 300, 4 | "Applications/Android": 306, 5 | "Applications/Handheld": 304, 6 | "Applications/IOS (iPad/iPhone)": 305, 7 | "Applications/Mac": 302, 8 | "Applications/Other OS": 399, 9 | "Applications/UNIX": 303, 10 | "Applications/Windows": 301, 11 | "Audio": 100, 12 | "Audio/Audio books": 102, 13 | "Audio/FLAC": 104, 14 | "Audio/Music": 101, 15 | "Audio/Other": 199, 16 | "Audio/Sound clips": 103, 17 | "Games": 400, 18 | "Games/Android": 408, 19 | "Games/Handheld": 406, 20 | "Games/IOS (iPad/iPhone)": 407, 21 | "Games/Mac": 402, 22 | "Games/Other": 499, 23 | "Games/PC": 401, 24 | "Games/PSx": 403, 25 | "Games/Wii": 405, 26 | "Games/XBOX360": 404, 27 | "Other": 600, 28 | "Other/Comics": 602, 29 | "Other/Covers": 604, 30 | "Other/E-books": 601, 31 | "Other/Other": 699, 32 | "Other/Physibles": 605, 33 | "Other/Pictures": 603, 34 | "Porn": 500, 35 | "Porn/Games": 504, 36 | "Porn/HD - Movies": 505, 37 | "Porn/Movie clips": 506, 38 | "Porn/Movies": 501, 39 | "Porn/Movies DVDR": 502, 40 | "Porn/Other": 599, 41 | "Porn/Pictures": 503, 42 | "Video": 200, 43 | "Video/3D": 209, 44 | "Video/HD - Movies": 207, 45 | "Video/HD - TV shows": 208, 46 | "Video/Handheld": 206, 47 | "Video/Movie clips": 204, 48 | "Video/Movies": 201, 49 | "Video/Movies DVDR": 202, 50 | "Video/Music videos": 203, 51 | "Video/Other": 299, 52 | "Video/TV shows": 205 53 | } 54 | -------------------------------------------------------------------------------- /tests/test_local.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import unittest 3 | import pirate.local 4 | import os 5 | import base64 6 | 7 | from tests import util 8 | 9 | 10 | class TestLocal(unittest.TestCase): 11 | 12 | def test_local_csv_db(self): 13 | path = util.data_path('db.csv') 14 | expected = [ 15 | { 16 | 'date':'2018-May-14 11:05:31', 17 | 'magnet': 'magnet:?xt=urn:btih:34930674EF3BB9317FB5F263CCA830F52685235B&dn=ubuntu-14.04.5-desktop-amd64.iso', 18 | 'size': '1.0 GiB', 19 | }, 20 | { 21 | 'date': '2018-Apr-15 00:04:09', 22 | 'magnet': 'magnet:?xt=urn:btih:F07E0B0584745B7BCB35E98097488D34E68623D0&dn=Ubuntu%2017.10.1%20Desktop%20%28amd64%29', 23 | 'size': '1.4 GiB', 24 | }, 25 | { 26 | 'date': '2017-Aug-01 15:08:07', 27 | 'magnet': 'magnet:?xt=urn:btih:4096EC129404689CEB8056D907E384FF872C2CE9&dn=LINUX%20UBUNTU%2016.10%2032X64', 28 | 'size': '1.5 GiB', 29 | }, 30 | ] 31 | actual = pirate.local.search(path, ('ubuntu',)) 32 | self.assertEqual(len(actual), len(expected)) 33 | for i in range(len(expected)): 34 | self.assertDictEqual(actual[i], expected[i]) 35 | 36 | if __name__ == '__main__': 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from setuptools import setup, find_packages 3 | from distutils.version import LooseVersion 4 | import sys 5 | import pirate.data 6 | 7 | if LooseVersion(sys.version) < LooseVersion("3.4.0"): 8 | print("pirate-get requires at least python 3.4.0." 9 | " Your version is %s." % sys.version.split()[0]) 10 | sys.exit(1) 11 | 12 | if __name__ == '__main__': 13 | setup(name='pirate-get', 14 | version=pirate.data.version, 15 | description='A command line interface for The Pirate Bay', 16 | url='https://github.com/vikstrous/pirate-get', 17 | author='vikstrous', 18 | author_email='me@viktorstanchev.com', 19 | license='AGPL', 20 | packages=find_packages(), 21 | package_data={'': ["data/*", "tests/data/*"]}, 22 | entry_points={ 23 | 'console_scripts': ['pirate-get = pirate.pirate:main'] 24 | }, 25 | install_requires=['colorama>=0.3.3', 26 | 'veryprettytable>=0.8.1', 27 | 'pyperclip>=1.6.2'], 28 | keywords=['torrent', 'magnet', 'download', 'tpb', 'client'], 29 | classifiers=[ 30 | 'Topic :: Utilities', 31 | 'Topic :: Terminals', 32 | 'Topic :: System :: Networking', 33 | 'Programming Language :: Python :: 3 :: Only', 34 | 'Programming Language :: Python :: 3.4', 35 | 'License :: OSI Approved :: GNU General Public License (GPL)', 36 | ], 37 | test_suite='tests') 38 | -------------------------------------------------------------------------------- /pirate/local.py: -------------------------------------------------------------------------------- 1 | import urllib.parse as parse 2 | import base64 3 | import csv 4 | 5 | # this is used to remove null bytes from the input stream because 6 | # apparently they exist 7 | def replace_iter(iterable): 8 | for value in iterable: 9 | yield value.replace("\0", "") 10 | 11 | # https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size#1094933 12 | def sizeof_fmt(num, suffix='B'): 13 | for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: 14 | if abs(num) < 1024.0: 15 | return "%3.1f %s%s" % (num, unit, suffix) 16 | num /= 1024.0 17 | return "%.1f %s%s" % (num, 'Yi', suffix) 18 | 19 | def search(db, terms): 20 | with open(db, 'r') as f: 21 | results = [] 22 | reader = csv.reader(replace_iter(f), delimiter=';') 23 | for row in reader: 24 | # skip comments 25 | if row[0][0] == '#': 26 | continue 27 | # 0 is date in rfc 3339 format 28 | # 1 magnet link hash 29 | # 2 is title 30 | # 3 is size in bytes 31 | if ' '.join(terms).lower() in row[2].lower(): 32 | result = { 33 | 'date': row[0], 34 | 'size': sizeof_fmt(int(row[3])), 35 | 'magnet': 36 | 'magnet:?xt=urn:btih:' + 37 | base64.b16encode(base64.b64decode(row[1])).decode('utf-8') + 38 | '&dn=' + 39 | parse.quote(row[2]), 40 | } 41 | results.append(result) 42 | # limit page size to not print walls of results 43 | # TODO: consider pagination 44 | results = results[:30] 45 | return results 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pirate-get 2 | [![Circle CI](https://img.shields.io/circleci/project/vikstrous/pirate-get/master.svg)](https://circleci.com/gh/vikstrous/pirate-get/tree/master) [![Coverage Status](https://img.shields.io/coveralls/vikstrous/pirate-get/master.svg)](https://coveralls.io/github/vikstrous/pirate-get?branch=master) [![Code Climate](https://img.shields.io/codeclimate/github/vikstrous/pirate-get.svg)](https://codeclimate.com/github/vikstrous/pirate-get) [![Codacy Badge](https://api.codacy.com/project/badge/8e5fc16afd23496dbcf74db710d1ef2c)](https://www.codacy.com/app/me_29/pirate-get) [![Gemnasium](https://img.shields.io/gemnasium/vikstrous/pirate-get.svg)](https://gemnasium.com/vikstrous/pirate-get) [![License](https://img.shields.io/pypi/l/pirate-get.svg)](https://raw.githubusercontent.com/vikstrous/pirate-get/master/LICENSE) [![Version](https://img.shields.io/pypi/v/pirate-get.svg)](https://pypi.python.org/pypi/pirate-get/) [![Downloads](https://img.shields.io/pypi/dm/pirate-get.svg)](https://pypi.python.org/pypi/pirate-get/) 3 | 4 | pirate-get is a convenient command line tool (inspired by APT) to speed up your trip to the Pirate Bay and get your completely legal torrents more quickly. 5 | 6 | ## Installation 7 | Make sure you have python 3.4 and pip installed. On Ubuntu 14.04 you may also need to install the libxslt1-dev and libxml2-dev packages. 8 | 9 | Run `pip3 install pirate-get` 10 | 11 | ## Usage 12 | 13 | To search use `pirate-get [search term]`. 14 | 15 | See `pirate-get -h` for more options. 16 | 17 | Watch [this](http://showterm.io/d6f7a0c2a5de1da9ea317) for an example usage. 18 | 19 | 20 | ## Configuration file 21 | You can use a file to override pirate-get's default settings. 22 | Default is `$XDG_CONFIG_HOME/pirate-get`. 23 | If it does not exist then `$HOME/.config/pirate-get`. 24 | 25 | ### Default config file 26 | Here the available options and their behaviors are when unset: 27 | 28 | ```INI 29 | [Save] 30 | ; directory where to save files 31 | directory = $PWD 32 | 33 | ; save each selected magnet link in a .magnet file 34 | magnets = false 35 | 36 | ; save each selected torrent in a .torrent file 37 | torrents = false 38 | 39 | [LocalDB] 40 | ; use a local copy of the csv formatted pirate bay database 41 | enabled = false 42 | 43 | ; path of the database 44 | path = ~/downloads/pirate-get/db 45 | 46 | [Search] 47 | ; maximum number of results to show 48 | total-results = 50 49 | 50 | [Misc] 51 | ; specify a custom command for opening the magnet 52 | ; ex. myprogram --open %s 53 | ; %s represent the magnet uri 54 | openCommand = 55 | 56 | ; open magnets with transmission-remote client 57 | transmission = false 58 | ; set to username:password if needed 59 | transmission-auth = 60 | ; set to the port number if needed 61 | transmission-port = 62 | 63 | ; use colored output 64 | colors = true 65 | 66 | ; the pirate bay mirror(s) to use: 67 | ; one or more space separated URLs 68 | mirror = http://thepiratebay.org 69 | ``` 70 | 71 | Note: 72 | Any command line option will override its respective setting in the config file. 73 | 74 | 75 | ## Local Database 76 | If you want to use a local copy of the Pirate Bay database download a copy here (or wherever the latest version is currently): 77 | 78 | https://thepiratebay.org/static/dump/csv/ 79 | 80 | ## License 81 | pirate-get is licensed under the GNU Affero General Public License version 3 or later. 82 | See the accompanying file LICENSE or http://www.gnu.org/licenses/agpl.html. 83 | -------------------------------------------------------------------------------- /pirate/print.py: -------------------------------------------------------------------------------- 1 | import builtins 2 | import re 3 | import gzip 4 | import urllib.request as request 5 | import shutil 6 | import json 7 | import sys 8 | 9 | import pirate.data 10 | import pirate.torrent 11 | 12 | import colorama 13 | import veryprettytable as pretty 14 | 15 | from io import BytesIO 16 | 17 | 18 | class Printer: 19 | def __init__(self, enable_color): 20 | self.enable_color = enable_color 21 | 22 | def print(self, *args, **kwargs): 23 | if kwargs.get('color', False) and self.enable_color: 24 | colorama.init() 25 | color_dict = { 26 | 'default': '', 27 | 'header': colorama.Back.BLACK + colorama.Fore.WHITE, 28 | 'alt': colorama.Fore.YELLOW, 29 | 'zebra_0': '', 30 | 'zebra_1': colorama.Fore.BLUE, 31 | 'WARN': colorama.Fore.MAGENTA, 32 | 'ERROR': colorama.Fore.RED} 33 | 34 | c = color_dict[kwargs.pop('color')] 35 | args = (c + args[0],) + args[1:] + (colorama.Style.RESET_ALL,) 36 | kwargs.pop('color', None) 37 | return builtins.print(*args, file=sys.stderr, **kwargs) 38 | else: 39 | kwargs.pop('color', None) 40 | return builtins.print(*args, file=sys.stderr, **kwargs) 41 | 42 | # TODO: extract the name from the search results 43 | # instead of from the magnet link when possible 44 | def search_results(self, results, local=None): 45 | columns = shutil.get_terminal_size((80, 20)).columns 46 | even = True 47 | 48 | if local: 49 | table = pretty.VeryPrettyTable(['LINK', 'DATE', 'SIZE', 'NAME']) 50 | 51 | table.align['SIZE'] = 'r' 52 | table.align['NAME'] = 'l' 53 | else: 54 | table = pretty.VeryPrettyTable(['LINK', 'SEED', 'LEECH', 55 | 'RATIO', 'SIZE', 56 | 'UPLOAD', 'NAME']) 57 | table.align['NAME'] = 'l' 58 | table.align['SEED'] = 'r' 59 | table.align['LEECH'] = 'r' 60 | table.align['RATIO'] = 'r' 61 | table.align['SIZE'] = 'r' 62 | table.align['UPLOAD'] = 'l' 63 | 64 | table.max_width = columns 65 | table.border = False 66 | table.padding_width = 1 67 | 68 | for n, result in enumerate(results): 69 | torrent_name = result['name'] 70 | 71 | if local: 72 | content = [n, result['date'], result['size'], 73 | torrent_name[:columns - 42]] 74 | else: 75 | no_seeders = int(result['seeders']) 76 | no_leechers = int(result['leechers']) 77 | size = result['size'] 78 | date = result['uploaded'] 79 | 80 | # compute the S/L ratio (Higher is better) 81 | try: 82 | ratio = no_seeders / no_leechers 83 | except ZeroDivisionError: 84 | ratio = float('inf') 85 | 86 | content = [n, no_seeders, no_leechers, 87 | '{:.1f}'.format(ratio), 88 | size, date, torrent_name[:columns - 50]] 89 | 90 | if even or not self.enable_color: 91 | table.add_row(content) 92 | else: 93 | table.add_row(content, fore_color='blue') 94 | 95 | # Alternate between colors 96 | even = not even 97 | self.print(table) 98 | 99 | def descriptions(self, chosen_links, results, site, timeout): 100 | for link in chosen_links: 101 | result = results[link] 102 | req = request.Request( 103 | site + '/t.php?id=' + str(result['id']), 104 | headers=pirate.data.default_headers) 105 | req.add_header('Accept-encoding', 'gzip') 106 | f = request.urlopen(req, timeout=timeout) 107 | 108 | if f.info().get('Content-Encoding') == 'gzip': 109 | f = gzip.GzipFile(fileobj=BytesIO(f.read())) 110 | 111 | res = json.load(f) 112 | 113 | # Replace HTML links with markdown style versions 114 | desc = re.sub(r']*>(\s*)([^<]+?)(\s*' 115 | r')', r'\2[\3](\1)\4', res['descr']) 116 | 117 | self.print('Description for "{}":'.format(result['name']), 118 | color='zebra_1') 119 | self.print(desc, color='zebra_0') 120 | 121 | def file_lists(self, chosen_links, results, site, timeout): 122 | # the API may returns object instead of list 123 | def get(obj): 124 | try: 125 | return obj[0] 126 | except KeyError: 127 | return obj['0'] 128 | 129 | for link in chosen_links: 130 | result = results[link] 131 | req = request.Request( 132 | site + '/f.php?id=' + str(result['id']), 133 | headers=pirate.data.default_headers) 134 | req.add_header('Accept-encoding', 'gzip') 135 | f = request.urlopen(req, timeout=timeout) 136 | 137 | if f.info().get('Content-Encoding') == 'gzip': 138 | f = gzip.GzipFile(fileobj=BytesIO(f.read())) 139 | 140 | res = json.load(f) 141 | 142 | if len(res) == 1 and 'not found' in get(res[0]['name']): 143 | self.print('File list not available.') 144 | return 145 | 146 | self.print('Files in {}:'.format(result['name']), color='zebra_1') 147 | cur_color = 'zebra_0' 148 | 149 | for f in res: 150 | name = get(f['name']) 151 | size = pirate.torrent.pretty_size(int(get(f['size']))) 152 | self.print('{:>11} {}'.format( 153 | size, name), 154 | color=cur_color) 155 | cur_color = 'zebra_0' if cur_color == 'zebra_1' else 'zebra_1' 156 | -------------------------------------------------------------------------------- /tests/test_print.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import os 3 | import unittest 4 | import json 5 | import sys 6 | 7 | from unittest.mock import patch, call, MagicMock 8 | from pirate.print import Printer 9 | 10 | 11 | class TestPrint(unittest.TestCase): 12 | @classmethod 13 | def setUpClass(cls): 14 | # needed to display the results table 15 | os.environ['COLUMNS'] = '80' 16 | 17 | def test_print_results_remote(self): 18 | class MockTable: 19 | add_row = MagicMock() 20 | align = {} 21 | mock = MockTable() 22 | printer = Printer(False) 23 | printer.print = MagicMock() 24 | with patch('veryprettytable.VeryPrettyTable', 25 | return_value=mock) as prettytable: 26 | results = [{ 27 | 'name': 'name', 28 | 'seeders': 1, 29 | 'leechers': 2, 30 | 'size': '3.0 MiB', 31 | 'uploaded': 'never' 32 | }] 33 | printer.search_results(results) 34 | prettytable.assert_called_once_with([ 35 | 'LINK', 'SEED', 'LEECH', 'RATIO', 36 | 'SIZE', 'UPLOAD', 'NAME']) 37 | mock.add_row.assert_has_calls([ 38 | call([0, 1, 2, '0.5', '3.0 MiB', 'never', 'name'])]) 39 | 40 | def test_print_results_local(self): 41 | class MockTable: 42 | add_row = MagicMock() 43 | align = {} 44 | mock = MockTable() 45 | printer = Printer(False) 46 | printer.print = MagicMock() 47 | with patch('veryprettytable.VeryPrettyTable', 48 | return_value=mock) as prettytable: 49 | results = [{ 50 | 'name': 'name1', 51 | 'date': '1', 52 | 'size': '1', 53 | }, { 54 | 'name': 'name2', 55 | 'date': '2', 56 | 'size': '2', 57 | }] 58 | printer.search_results(results, local=True) 59 | prettytable.assert_called_once_with( 60 | ['LINK', 'DATE', 'SIZE', 'NAME']) 61 | mock.add_row.assert_has_calls( 62 | [call([0, '1', '1', 'name1']), call([1, '2', '2', 'name2'])]) 63 | 64 | def test_print_color(self): 65 | printer = Printer(False) 66 | with patch('pirate.print.builtins.print') as mock_print: 67 | printer.print('abc', color='zebra_1') 68 | mock_print.assert_called_once_with( 69 | 'abc', 70 | file=sys.stderr) 71 | printer = Printer(True) 72 | with patch('pirate.print.builtins.print') as mock_print: 73 | printer.print('abc', color='zebra_1') 74 | mock_print.assert_called_once_with( 75 | '\x1b[34mabc', '\x1b[0m', 76 | file=sys.stderr) 77 | 78 | def test_print_results_local2(self): 79 | class MockTable: 80 | add_row = MagicMock() 81 | align = {} 82 | mock = MockTable() 83 | printer = Printer(True) 84 | printer.print = MagicMock() 85 | with patch('veryprettytable.VeryPrettyTable', 86 | return_value=mock) as prettytable: 87 | results = [{ 88 | 'name': 'name1', 89 | 'date': '1', 90 | 'size': '1', 91 | }, { 92 | 'name': 'name2', 93 | 'date': '2', 94 | 'size': '2', 95 | }] 96 | printer.search_results(results, local=True) 97 | prettytable.assert_called_once_with( 98 | ['LINK', 'DATE', 'SIZE', 'NAME']) 99 | mock.add_row.assert_has_calls([ 100 | call([0, '1', '1', 'name1']), 101 | call([1, '2', '2', 'name2'], fore_color='blue')]) 102 | 103 | def test_print_descriptions(self): 104 | printer = Printer(False) 105 | printer.print = MagicMock() 106 | 107 | class MockRequest(): 108 | add_header = MagicMock() 109 | request_obj = MockRequest() 110 | 111 | class MockResponse(): 112 | read = MagicMock(return_value=json.dumps( 113 | {'name': 'cool torrent', 114 | 'descr': 'A fake torrent.\n'})) 115 | info = MagicMock() 116 | response_obj = MockResponse() 117 | 118 | with patch('urllib.request.Request', return_value=request_obj): 119 | with patch('urllib.request.urlopen', 120 | return_value=response_obj): 121 | printer.descriptions([0], [{'id': '1', 'name': 'name'}], 122 | 'example.com', 9) 123 | printer.print.assert_has_calls([ 124 | call('Description for "name":', color='zebra_1'), 125 | call('A fake torrent.\n', color='zebra_0')]) 126 | 127 | def test_print_file_lists(self): 128 | printer = Printer(False) 129 | printer.print = MagicMock() 130 | 131 | class MockRequest(): 132 | add_header = MagicMock() 133 | info = MagicMock() 134 | request_obj = MockRequest() 135 | 136 | class MockResponse(): 137 | read = MagicMock(return_value=json.dumps( 138 | [{'name': ['readme.txt'], 'size': [16]}, 139 | {'name': ['a.mkv'], 'size': [677739464]}, 140 | {'name': ['b.nfo'], 'size': [61]}])) 141 | info = MagicMock() 142 | response_obj = MockResponse() 143 | 144 | with patch('urllib.request.Request', 145 | return_value=request_obj): 146 | with patch('urllib.request.urlopen', 147 | return_value=response_obj): 148 | printer.file_lists([0], [{'id': '1', 'name': 'name'}], 149 | 'example.com', 9) 150 | printer.print.assert_has_calls([ 151 | call('Files in name:', color='zebra_1'), 152 | call(' 16 B readme.txt', color='zebra_0'), 153 | call(' 646.3 MiB a.mkv', color='zebra_1'), 154 | call(' 61 B b.nfo', color='zebra_0')]) 155 | 156 | 157 | if __name__ == '__main__': 158 | unittest.main() 159 | -------------------------------------------------------------------------------- /tests/test_torrent.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import unittest 3 | from unittest import mock 4 | from unittest.mock import patch, MagicMock 5 | import io 6 | import urllib 7 | import json 8 | import os 9 | import time 10 | 11 | import pirate.torrent 12 | import pirate.data 13 | from pirate.print import Printer 14 | from tests import util 15 | 16 | 17 | class TestTorrent(unittest.TestCase): 18 | 19 | @classmethod 20 | def setUpClass(cls): 21 | # to make test deterministic 22 | os.environ['TZ'] = 'Etc/UTC' 23 | time.tzset() 24 | 25 | def test_no_hits(self): 26 | expected = [] 27 | with util.open_data('no_hits.json') as res: 28 | actual = pirate.torrent.parse_page(res) 29 | self.assertEqual(actual, expected) 30 | 31 | def test_blocked_mirror(self): 32 | with util.open_data('blocked.html') as res: 33 | with self.assertRaises(IOError): 34 | pirate.torrent.parse_page(res) 35 | 36 | def test_search_results(self): 37 | with util.open_data('result.json') as file: 38 | expected = json.load(file) 39 | with util.open_data('debian_iso.json') as res: 40 | actual = pirate.torrent.parse_page(res) 41 | json.dump(actual, open('result.json', 'w')) 42 | self.assertEqual(actual, expected) 43 | 44 | def test_parse_category(self): 45 | category = pirate.torrent.parse_category(MagicMock(Printer), 'Audio') 46 | self.assertEqual(100, category) 47 | category = pirate.torrent.parse_category(MagicMock(Printer), 'Video') 48 | self.assertEqual(200, category) 49 | category = pirate.torrent.parse_category(MagicMock(Printer), '100') 50 | self.assertEqual(100, category) 51 | category = pirate.torrent.parse_category(MagicMock(Printer), 'asdf') 52 | self.assertEqual(0, category) 53 | category = pirate.torrent.parse_category(MagicMock(Printer), '9001') 54 | self.assertEqual(0, category) 55 | 56 | def test_parse_sort(self): 57 | sort = pirate.torrent.parse_sort(MagicMock(Printer), 'SeedersDsc') 58 | self.assertEqual(['seeders', True], sort) 59 | sort = pirate.torrent.parse_sort(MagicMock(Printer), 'CategoryAsc') 60 | self.assertEqual(['category', False], sort) 61 | sort = pirate.torrent.parse_sort(MagicMock(Printer), 'DateAsc') 62 | self.assertEqual(['raw_uploaded', False], sort) 63 | sort = pirate.torrent.parse_sort(MagicMock(Printer), '7') 64 | self.assertEqual(['seeders', True], sort) 65 | sort = pirate.torrent.parse_sort(MagicMock(Printer), 'asdf') 66 | self.assertEqual(['seeders', True], sort) 67 | sort = pirate.torrent.parse_sort(MagicMock(Printer), '7000') 68 | self.assertEqual(['seeders', True], sort) 69 | 70 | def test_request_path(self): 71 | # the args are (mode, category, terms) 72 | succeed = [ 73 | (('recent', 1, 0, []), '/precompiled/data_top100_recent_1.json'), 74 | (('recent', 2, 100, []), '/precompiled/data_top100_recent_2.json'), 75 | (('top', 1, 0, []), '/precompiled/data_top100_all.json'), 76 | (('top', 1, 100, []), '/precompiled/data_top100_100.json'), 77 | (('search', 1, 100, ['abc']), '/q.php?q=abc&cat=100'), 78 | (('search', 1, 100, ['abc', 'def']), '/q.php?q=abc%20def&cat=100'), 79 | (('search', 1, 100, ['\u1234']), '/q.php?q=%E1%88%B4&cat=100'), 80 | (('browse', 1, 100, []), '/q.php?q=category%3A100'), 81 | ] 82 | fail = [ 83 | (('browse', 1, 0, []), Exception), 84 | (('asdf', 1, 100, []), Exception) 85 | ] 86 | for inp, out in succeed: 87 | path = pirate.torrent.build_request_path(*inp) 88 | self.assertEqual(out, path) 89 | for inp, out, in fail: 90 | with self.assertRaises(out): 91 | pirate.torrent.build_request_path(*inp) 92 | 93 | @patch('pirate.torrent.get_torrent') 94 | def test_save_torrents(self, get_torrent): 95 | with patch('pirate.torrent.open', 96 | mock.mock_open(), create=True) as open_: 97 | pirate.torrent.save_torrents( 98 | MagicMock(Printer), [0], 99 | [{'name': 'cool torrent', 100 | 'info_hash': 3735928559, 101 | 'magnet': 'magnet:?xt=urn:btih:deadbeef'}], 'path', 9) 102 | get_torrent.assert_called_once_with(3735928559, 9) 103 | open_.assert_called_once_with('path/cool torrent.torrent', 'wb') 104 | 105 | @patch('pirate.torrent.get_torrent', 106 | side_effect=urllib.error.HTTPError('', '', '', '', io.StringIO())) 107 | def test_save_torrents_fail(self, get_torrent): 108 | pirate.torrent.save_torrents( 109 | MagicMock(Printer), [0], 110 | [{'name': 'cool torrent', 111 | 'info_hash': 3735928559, 112 | 'magnet': 'magnet:?xt=urn:btih:deadbeef'}], 'path', 9) 113 | 114 | def test_save_magnets(self): 115 | with patch('pirate.torrent.open', 116 | mock.mock_open(), create=True) as open_: 117 | pirate.torrent.save_magnets( 118 | MagicMock(Printer), [0], 119 | [{'name': 'cool torrent', 120 | 'info_hash': 3735928559, 121 | 'magnet': 'magnet:?xt=urn:btih:deadbeef'}], 'path') 122 | open_.assert_called_once_with('path/cool torrent.magnet', 'w') 123 | 124 | @patch('urllib.request.urlopen') 125 | def test_get_torrent(self, urlopen): 126 | class MockRequest(): 127 | add_header = mock.MagicMock() 128 | request_obj = MockRequest() 129 | with patch('urllib.request.Request', return_value=request_obj) as req: 130 | pirate.torrent.get_torrent(100000000000000, 9) 131 | req.assert_called_once_with( 132 | 'http://itorrents.org/torrent/5AF3107A4000.torrent', 133 | headers=pirate.data.default_headers) 134 | urlopen.assert_called_once_with( 135 | request_obj, 136 | timeout=9) 137 | 138 | def test_remote(self): 139 | class MockRequest(): 140 | add_header = mock.MagicMock() 141 | req_obj = MockRequest() 142 | 143 | class MockInfo(): 144 | get_content_type = mock.MagicMock(return_value='application/json') 145 | get = mock.MagicMock() 146 | 147 | class MockResponse(): 148 | read = mock.MagicMock(return_value=b'[]') 149 | info = mock.MagicMock(return_value=MockInfo()) 150 | res_obj = MockResponse() 151 | 152 | sort = pirate.torrent.parse_sort(MagicMock(Printer), 10) 153 | 154 | with patch('urllib.request.Request', return_value=req_obj) as req: 155 | with patch('urllib.request.urlopen', return_value=res_obj) as res: 156 | results = pirate.torrent.remote( 157 | MagicMock(Printer), 1, 100, sort, 'top', 158 | [], 'http://example.com', 9) 159 | req.assert_called_once_with( 160 | 'http://example.com/precompiled/data_top100_100.json', 161 | headers=pirate.data.default_headers) 162 | res.assert_called_once_with(req_obj, timeout=9) 163 | self.assertEqual(results, []) 164 | 165 | 166 | if __name__ == '__main__': 167 | unittest.main() 168 | -------------------------------------------------------------------------------- /pirate/torrent.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | import gzip 4 | import pyperclip 5 | import urllib.request as request 6 | import urllib.parse as parse 7 | import urllib.error 8 | import os.path 9 | 10 | import pirate.data 11 | import json 12 | 13 | from datetime import datetime 14 | from io import BytesIO 15 | 16 | 17 | def parse_category(printer, category): 18 | try: 19 | category = int(category) 20 | except ValueError: 21 | pass 22 | if category in pirate.data.categories.values(): 23 | return category 24 | elif category in pirate.data.categories.keys(): 25 | return pirate.data.categories[category] 26 | else: 27 | printer.print('Invalid category ignored', color='WARN') 28 | return 0 29 | 30 | 31 | def parse_sort(printer, sort): 32 | try: 33 | sort = int(sort) 34 | except ValueError: 35 | pass 36 | for key, val in pirate.data.sorts.items(): 37 | if sort == key or sort == val[0]: 38 | return val[1:] 39 | else: 40 | printer.print('Invalid sort ignored', color='WARN') 41 | return pirate.data.sorts['Default'][1:] 42 | 43 | 44 | def parse_page(page): 45 | results = [] 46 | try: 47 | data = json.load(page) 48 | except json.decoder.JSONDecodeError: 49 | raise IOError('invalid JSON in API reply: blocked mirror?') 50 | 51 | if len(data) == 1 and 'No results' in data[0]['name']: 52 | return results 53 | 54 | for res in data: 55 | res['raw_size'] = int(res['size']) 56 | res['size'] = pretty_size(int(res['size'])) 57 | res['magnet'] = build_magnet(res['name'], res['info_hash']) 58 | res['info_hash'] = int(res['info_hash'], 16) 59 | res['raw_uploaded'] = int(res['added']) 60 | res['uploaded'] = pretty_date(res['added']) 61 | res['seeders'] = int(res['seeders']) 62 | res['leechers'] = int(res['leechers']) 63 | res['category'] = int(res['category']) 64 | results.append(res) 65 | 66 | return results 67 | 68 | 69 | def sort_results(sort, res): 70 | key, reverse = sort 71 | return sorted(res, key=lambda x: x[key], reverse=reverse) 72 | 73 | 74 | def pretty_size(size): 75 | ranges = [('PiB', 1125899906842624), 76 | ('TiB', 1099511627776), 77 | ('GiB', 1073741824), 78 | ('MiB', 1048576), 79 | ('KiB', 1024)] 80 | for unit, value in ranges: 81 | if size >= value: 82 | return '{:.1f} {}'.format(size/value, unit) 83 | return str(size) + ' B' 84 | 85 | 86 | def pretty_date(ts): 87 | date = datetime.fromtimestamp(int(ts)) 88 | return date.strftime('%Y-%m-%d %H:%M') 89 | 90 | 91 | def build_magnet(name, info_hash): 92 | return 'magnet:?xt=urn:btih:{}&dn={}'.format( 93 | info_hash, parse.quote(name, '')) 94 | 95 | 96 | def build_request_path(mode, page, category, terms): 97 | if mode == 'search': 98 | query = '/q.php?q={}&cat={}'.format(' '.join(terms), category) 99 | elif mode == 'top': 100 | cat = 'all' if category == 0 else category 101 | query = '/precompiled/data_top100_{}.json'.format(cat) 102 | elif mode == 'recent': 103 | query = '/precompiled/data_top100_recent_{}.json'.format(page) 104 | elif mode == 'browse': 105 | if category == 0: 106 | raise Exception('You must specify a category') 107 | query = '/q.php?q=category:{}'.format(category) 108 | else: 109 | raise Exception('Invalid mode', mode) 110 | 111 | return parse.quote(query, '?=&/') 112 | 113 | 114 | def remote(printer, pages, category, sort, mode, terms, mirror, timeout): 115 | results = [] 116 | for i in range(1, pages + 1): 117 | query = build_request_path(mode, i, category, terms) 118 | 119 | # Catch the Ctrl-C exception and exit cleanly 120 | try: 121 | req = request.Request( 122 | mirror + query, 123 | headers=pirate.data.default_headers) 124 | try: 125 | f = request.urlopen(req, timeout=timeout) 126 | except urllib.error.URLError as e: 127 | raise e 128 | 129 | if f.info().get('Content-Encoding') == 'gzip': 130 | f = gzip.GzipFile(fileobj=BytesIO(f.read())) 131 | except KeyboardInterrupt: 132 | printer.print('\nCancelled.') 133 | sys.exit(0) 134 | 135 | results.extend(parse_page(f)) 136 | 137 | return sort_results(sort, results) 138 | 139 | 140 | def find_api(mirror, timeout): 141 | # try common paths 142 | for path in ['', '/apip', '/api.php?url=']: 143 | req = request.Request(mirror + path + '/q.php?q=test&cat=0', 144 | headers=pirate.data.default_headers) 145 | try: 146 | f = request.urlopen(req, timeout=timeout) 147 | if f.info().get_content_type() == 'application/json': 148 | return mirror + path 149 | except urllib.error.HTTPError as e: 150 | res = e.fp.read().decode() 151 | if e.code == 503 and 'cf-browser-verification' in res: 152 | raise IOError('Cloudflare protected') 153 | 154 | # extract api path from main.js 155 | req = request.Request(mirror + '/static/main.js', 156 | headers=pirate.data.default_headers) 157 | try: 158 | f = request.urlopen(req, timeout=timeout) 159 | if f.info().get_content_type() == 'application/javascript': 160 | match = re.search("var server='([^']+)'", f.read().decode()) 161 | return mirror + match.group(1) 162 | except urllib.error.URLError: 163 | raise IOError('API not found: no main.js') 164 | 165 | raise IOError('API not found') 166 | 167 | 168 | def get_torrent(info_hash, timeout): 169 | url = 'http://itorrents.org/torrent/{:X}.torrent' 170 | req = request.Request(url.format(info_hash), 171 | headers=pirate.data.default_headers) 172 | req.add_header('Accept-encoding', 'gzip') 173 | 174 | torrent = request.urlopen(req, timeout=timeout) 175 | if torrent.info().get('Content-Encoding') == 'gzip': 176 | torrent = gzip.GzipFile(fileobj=BytesIO(torrent.read())) 177 | 178 | return torrent.read() 179 | 180 | 181 | def save_torrents(printer, chosen_links, results, folder, timeout): 182 | for link in chosen_links: 183 | result = results[link] 184 | torrent_name = result['name'].replace('/', '_').replace('\\', '_') 185 | file = os.path.join(folder, torrent_name + '.torrent') 186 | 187 | try: 188 | torrent = get_torrent(result['info_hash'], timeout) 189 | except urllib.error.HTTPError as e: 190 | printer.print('There is no cached file for this torrent :(' 191 | ' \nCode: {} - {}'.format(e.code, e.reason), 192 | color='ERROR') 193 | else: 194 | open(file, 'wb').write(torrent) 195 | printer.print('Saved {:X} in {}'.format(result['info_hash'], file)) 196 | 197 | 198 | def save_magnets(printer, chosen_links, results, folder): 199 | for link in chosen_links: 200 | result = results[link] 201 | torrent_name = result['name'].replace('/', '_').replace('\\', '_') 202 | file = os.path.join(folder, torrent_name + '.magnet') 203 | 204 | printer.print('Saved {:X} in {}'.format(result['info_hash'], file)) 205 | with open(file, 'w') as f: 206 | f.write(result['magnet'] + '\n') 207 | 208 | 209 | def copy_magnets(printer, chosen_links, results): 210 | clipboard_text = '' 211 | for link in chosen_links: 212 | result = results[link] 213 | clipboard_text += result['magnet'] + "\n" 214 | printer.print('Copying {:X} to clipboard'.format(result['info_hash'])) 215 | 216 | pyperclip.copy(clipboard_text) 217 | -------------------------------------------------------------------------------- /tests/test_pirate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import socket 3 | import unittest 4 | from argparse import Namespace 5 | from unittest import mock 6 | from unittest.mock import patch, call, MagicMock 7 | 8 | import pirate.pirate 9 | import pirate.data 10 | from pirate.print import Printer 11 | 12 | 13 | class TestPirate(unittest.TestCase): 14 | 15 | def test_parse_cmd(self): 16 | tests = [ 17 | [['abc', ''], ['abc']], 18 | [['abc %s', 'url'], ['abc', 'url']], 19 | [['abc "%s"', 'url'], ['abc', 'url']], 20 | [["abc \'%s\'", 'url'], ['abc', 'url']], 21 | [['abc bash -c "\'%s\'"', 'url'], ['abc', 'bash', '-c', "'url'"]], 22 | [['abc %s %s', 'url'], ['abc', 'url', 'url']], 23 | ] 24 | for test in tests: 25 | self.assertEqual(pirate.pirate.parse_cmd(*test[0]), test[1]) 26 | 27 | @patch('subprocess.call') 28 | def test_main(self, mock_call): 29 | result = { 30 | 'name': 'derp', 31 | 'magnet': 'magnet:?xt=urn:btih:deadbeef&dn=derp', 32 | 'seeders': '1', 33 | 'leechers': '1', 34 | 'size': '1 MB', 35 | 'uploaded': '1', 36 | } 37 | with patch('pirate.pirate.connect_mirror', 38 | return_value=([result], '')): 39 | config = pirate.pirate.parse_config_file('') 40 | args = pirate.pirate.combine_configs( 41 | config, 42 | pirate.pirate.parse_args(['-0', 'term', '-C', 'blah %s'])) 43 | pirate.pirate.pirate_main(args) 44 | mock_call.assert_called_once_with( 45 | ['blah', 'magnet:?xt=urn:btih:deadbeef&dn=derp']) 46 | 47 | @patch('pirate.pirate.builtins.input', return_value='0') 48 | @patch('subprocess.call') 49 | def test_main_choice(self, mock_call, mock_input): 50 | result = { 51 | 'name': 'derp', 52 | 'magnet': 'magnet:?xt=urn:btih:deadbeef&dn=derp', 53 | 'seeders': '1', 54 | 'leechers': '1', 55 | 'size': '1 MB', 56 | 'uploaded': '1', 57 | } 58 | with patch('pirate.pirate.connect_mirror', 59 | return_value=([result], '')): 60 | config = pirate.pirate.parse_config_file('') 61 | args = pirate.pirate.combine_configs( 62 | config, pirate.pirate.parse_args(['term', '-C', 'blah %s'])) 63 | pirate.pirate.pirate_main(args) 64 | mock_call.assert_called_once_with( 65 | ['blah', 'magnet:?xt=urn:btih:deadbeef&dn=derp']) 66 | 67 | def test_parse_torrent_command(self): 68 | tests = [ 69 | [['h'], ('h', [])], 70 | [['q'], ('q', [])], 71 | [['d1'], ('d', [1])], 72 | [['f1'], ('f', [1])], 73 | [['p1'], ('p', [1])], 74 | [['t1'], ('t', [1])], 75 | [['m1'], ('m', [1])], 76 | [['d 23'], ('d', [23])], 77 | [['d 23,1'], ('d', [23, 1])], 78 | [['d 23, 1'], ('d', [23, 1])], 79 | [['1d'], ('d', [1])], 80 | [['1 ... d'], ('d', [1])], 81 | [['1-3 d'], ('d', [1, 2, 3])], 82 | [['1-3'], (None, [1, 2, 3])], 83 | ] 84 | for test in tests: 85 | self.assertEqual( 86 | pirate.pirate.parse_torrent_command(*test[0]), 87 | test[1]) 88 | 89 | def test_parse_config_file(self): 90 | types = { 91 | 'Save': { 92 | 'magnets': bool, 93 | 'Magnets': bool, 94 | 'torrents': bool, 95 | 'directory': str, 96 | }, 97 | 'LocalDB': { 98 | 'enabled': bool, 99 | 'path': str, 100 | } 101 | } 102 | config1 = """ 103 | [Save] 104 | magnets=False 105 | directory=dir 106 | [LocalDB] 107 | enabled=true 108 | path=abc 109 | """ 110 | config2 = """ 111 | [Save] 112 | Magnets=True 113 | """ 114 | tests = [ 115 | (config1, {'Save': {'magnets': False}}), 116 | (config1, {'Save': {'torrents': False}}), 117 | (config1, {'Save': {'directory': 'dir'}}), 118 | (config1, {'LocalDB': {'enabled': True}}), 119 | (config1, {'LocalDB': {'path': 'abc'}}), 120 | (config2, {'Save': {'magnets': True}}), 121 | ] 122 | for test in tests: 123 | config = pirate.pirate.parse_config_file(test[0]) 124 | for section in test[1].keys(): 125 | for name in test[1][section].keys(): 126 | if types[section][name] == bool: 127 | lhs = config.getboolean(section, name) 128 | else: 129 | lhs = config.get(section, name) 130 | rhs = test[1][section][name] 131 | self.assertEqual(lhs, rhs) 132 | 133 | def test_parse_args(self): 134 | tests = [ 135 | ('', ['-b'], {'action': 'browse'}), 136 | ('', [], {'action': 'top'}), 137 | ('', ['-R'], {'action': 'recent'}), 138 | ('', ['-l'], {'action': 'list_categories'}), 139 | ('', ['--list_sorts'], {'action': 'list_sorts'}), 140 | ('', ['term'], {'action': 'search', 'source': 'tpb'}), 141 | ('', 142 | ['-L', 'filename', 'term'], 143 | {'action': 'search', 'source': 'local_tpb', 144 | 'database': 'filename'}), 145 | ('', 146 | ['term', '-S', 'dir'], 147 | {'action': 'search', 'save_directory': 'dir'}), 148 | ('', 149 | ['-E', 'localhost:1337'], 150 | {'transmission_command': 151 | ['transmission-remote', 'localhost:1337']}), 152 | ('', ['term'], {'output': 'browser_open'}), 153 | ('', ['term', '-t'], {'output': 'transmission'}), 154 | ('', ['term', '--save-magnets'], {'output': 'save_magnet_files'}), 155 | ('', 156 | ['term', '-C', 'command'], 157 | {'output': 'open_command', 'open_command': 'command'}), 158 | ('', ['internets'], {'action': 'search', 'search': ['internets']}), 159 | ('', 160 | ['term', '--save-torrents'], 161 | {'output': 'save_torrent_files'}), 162 | ('', 163 | ['internets lol', 'lel'], 164 | {'action': 'search', 'search': ['internets lol', 'lel']}), 165 | ] 166 | for test in tests: 167 | args = pirate.pirate.parse_args(test[1]) 168 | config = pirate.pirate.parse_config_file(test[0]) 169 | args = pirate.pirate.combine_configs(config, args) 170 | for option in test[2].keys(): 171 | value = getattr(args, option) 172 | self.assertEqual(test[2][option], value) 173 | 174 | def test_search_mirrors(self): 175 | args = Namespace( 176 | category=100, sort=10, 177 | action='browse', search=[], 178 | mirror=[pirate.data.default_mirror], 179 | timeout=pirate.data.default_timeout) 180 | 181 | class MockResponse(): 182 | readlines = mock.MagicMock( 183 | return_value=[ 184 | x.encode('utf-8') for x in 185 | ['', '', '', 'https://example.com']]) 186 | info = mock.MagicMock() 187 | getcode = mock.MagicMock(return_value=200) 188 | response_obj = MockResponse() 189 | 190 | returns = [None, ([], 'https://example.com')] 191 | 192 | printer = MagicMock(Printer) 193 | with patch('pirate.pirate.connect_mirror', 194 | side_effect=returns) as connect: 195 | with patch('urllib.request.urlopen', return_value=response_obj): 196 | results, mirror = pirate.pirate.search_mirrors(printer, args) 197 | 198 | connect.assert_has_calls([ 199 | call(pirate.data.default_mirror, printer, args), 200 | call('https://example.com', printer, args)]) 201 | 202 | self.assertEqual(results, []) 203 | self.assertEqual(mirror, 'https://example.com') 204 | 205 | 206 | if __name__ == '__main__': 207 | unittest.main() 208 | -------------------------------------------------------------------------------- /tests/data/debian_iso.json: -------------------------------------------------------------------------------- 1 | [{"id":"6089103","name":"Linux Mint Debian [201012] [ISO] [64-Bit] [geno7744] ","info_hash":"0E270463CD1AD2D856EA89859829BC1E63E3B228","leechers":"1","seeders":"1","num_files":"1","size":"1021560832","username":"geno7744","added":"1294464892","status":"member","category":"303","imdb":""},{"id":"8442441","name":"debian-7.0.0-i386-DVD-1.iso","info_hash":"7E919FB33216E2BC6C31ADE3594A3866D260B9BF","leechers":"0","seeders":"1","num_files":"1","size":"3998007296","username":"mmxx_01","added":"1367797189","status":"member","category":"303","imdb":""},{"id":"3357155","name":"debian_gnu_linux_31r0a_ia64_1_iso","info_hash":"78B281DF90ED64F8E6D13555C9108A54C9472606","leechers":"1","seeders":"0","num_files":"2","size":"4640233753","username":"gigli","added":"1121550810","status":"member","category":"303","imdb":""},{"id":"3441282","name":"Debian 3.1r1 i386 binary No. 1 (of 14) ISO file","info_hash":"A1690B1129AE13E5F01457338F5D06223F8174F1","leechers":"0","seeders":"0","num_files":"1","size":"669585408","username":"PixelHermit","added":"1139313316","status":"member","category":"303","imdb":""},{"id":"3441283","name":"Debian 3.1r1 i386 binary No. 2 (of 14) ISO file","info_hash":"B226D8C4192EB6994FEAF0DBCA04C6126DC7FBC4","leechers":"0","seeders":"0","num_files":"1","size":"671037440","username":"PixelHermit","added":"1139313488","status":"member","category":"303","imdb":""},{"id":"3441284","name":"Debian 3.1r1 i386 binary No. 3 (of 14) ISO file","info_hash":"EAF6853B9438EB757D066BFDE0D13AD9F657F2B1","leechers":"1","seeders":"0","num_files":"1","size":"673679360","username":"PixelHermit","added":"1139313671","status":"member","category":"303","imdb":""},{"id":"3578845","name":"debian-31r4-i386-netinst.iso","info_hash":"D08019524B9FD86A48D31347BFC3714408B09D5B","leechers":"0","seeders":"0","num_files":"1","size":"117620736","username":"keep_patrick","added":"1166383842","status":"member","category":"303","imdb":""},{"id":"3795842","name":"Debian 4.0 ETCH.iso","info_hash":"3BC2C61C420A62DE7442E44698E6AED05A499078","leechers":"0","seeders":"0","num_files":"1","size":"3833810944","username":"lkonti","added":"1188950149","status":"member","category":"303","imdb":""},{"id":"3860812","name":"debian-live-etch-i386-standard.iso","info_hash":"41BA5E3833E9D678DB41673183EC49AD32EA366C","leechers":"0","seeders":"0","num_files":"1","size":"85168128","username":"superunix","added":"1193471893","status":"member","category":"303","imdb":""},{"id":"3872700","name":"debian-kde4beta4-live-cd-i386.iso","info_hash":"2CAAABE42A03A3EFB28F33DE93C2FBB278EAA891","leechers":"0","seeders":"0","num_files":"1","size":"438484992","username":"jknotzke","added":"1194191588","status":"member","category":"303","imdb":""},{"id":"3947454","name":"Debian 4.0 r1 Update.iso","info_hash":"6A52953C8C8C6DAE89D867EB3DEB1C66AC43E7BC","leechers":"0","seeders":"0","num_files":"1","size":"1374822400","username":"shasi420","added":"1198595636","status":"member","category":"303","imdb":""},{"id":"4224808","name":"debian-hamm-source-cs.iso","info_hash":"0ACE55B2D81A56E1139A2E7C070F54B2F82F319B","leechers":"0","seeders":"0","num_files":"1","size":"631373824","username":"geier","added":"1212764102","status":"trusted","category":"303","imdb":""},{"id":"4244856","name":"debian-40r3-i386-netinst.iso","info_hash":"8527DE9E12B4196A1C443853C2DD349C8E264AA6","leechers":"0","seeders":"0","num_files":"1","size":"167313408","username":"rabenkind","added":"1213728149","status":"member","category":"303","imdb":""},{"id":"4512019","name":"debian-testing-amd64-i386-powerpc-netinst.iso","info_hash":"A755AAE126AAF9047B89D0075FF19F702B6B4DDF","leechers":"0","seeders":"0","num_files":"1","size":"492965888","username":"AMDFreak78","added":"1226817859","status":"member","category":"303","imdb":""},{"id":"4725085","name":"debian-500-i386-businesscard.iso","info_hash":"018FF30FE833FA680A6E35B73C1B5DD6F0EAA539","leechers":"0","seeders":"0","num_files":"1","size":"37136384","username":"dreamszz","added":"1234708307","status":"member","category":"303","imdb":""},{"id":"4727053","name":"debian-500-i386-netinst.iso","info_hash":"F1AED2E515A0BDF141549D440047AB97812B6916","leechers":"0","seeders":"0","num_files":"1","size":"157204480","username":"dreamszz","added":"1234806400","status":"member","category":"303","imdb":""},{"id":"4734148","name":"debian-500-i386-DVD-1.iso","info_hash":"CF92138268871BC3BB964ED69DB1EC36C2CE9759","leechers":"1","seeders":"0","num_files":"1","size":"4698322944","username":"KRZR","added":"1235186603","status":"member","category":"303","imdb":""},{"id":"4774275","name":"debian-40r6-i386-amd64-powerpc-source-DVD-1.iso","info_hash":"AC58CDFD2577CCE93F7040F88BB4B782B5244FC3","leechers":"0","seeders":"0","num_files":"1","size":"4385832960","username":"CriogenicFear","added":"1237149753","status":"member","category":"303","imdb":""},{"id":"5247569","name":"Debian 5.03 on a Blu-Ray ISO. Downloaded only a few days ago.","info_hash":"2CB339DD437A0A05BC65DACFF89E8A68EF671FFE","leechers":"0","seeders":"0","num_files":"1","size":"20066349056","username":"cerre","added":"1262216973","status":"member","category":"303","imdb":""},{"id":"5724168","name":"clonezilla-live-1.2.5.38 iso files (Testing Debian-based)","info_hash":"E1E684A0061FB8C26A6FEF7A912347A7AB09B8EA","leechers":"1","seeders":"0","num_files":"3","size":"383778816","username":"Anonymous","added":"1280391570","status":"member","category":"699","imdb":""},{"id":"5772142","name":"Debian-Linux-2010.iso","info_hash":"AB58CC1423C06E30343BDCA6856A533D63531053","leechers":"0","seeders":"0","num_files":"1","size":"4681738240","username":"Maizer911","added":"1282132638","status":"member","category":"303","imdb":""},{"id":"5817670","name":"Linux Mint Debian [201009] [ISO] [geno7744]","info_hash":"C88ED91734EFE4AB5DA1C1851F3F6CF472157DB1","leechers":"1","seeders":"0","num_files":"1","size":"917123072","username":"geno7744","added":"1283915768","status":"member","category":"303","imdb":""},{"id":"5948268","name":"debian-506-i386-DVD-1.iso","info_hash":"8D8A114979524D0A2F881E758F42BD14C10A91A7","leechers":"0","seeders":"0","num_files":"1","size":"4675819520","username":"NickShim","added":"1289441340","status":"member","category":"699","imdb":""},{"id":"6039270","name":"debian-privacy-remix.iso","info_hash":"FFACF7F1C5922C70FEF99A887D94D8765BAE45BD","leechers":"0","seeders":"0","num_files":"1","size":"1531969536","username":"Brage P","added":"1292329538","status":"member","category":"303","imdb":""},{"id":"6089092","name":"Linux Mint Debian [201101] [ISO] [32-Bit] [geno7744] ","info_hash":"2E99D97F1768644A86A8E99BFD80C816490F959B","leechers":"0","seeders":"0","num_files":"1","size":"1033945088","username":"geno7744","added":"1294464609","status":"member","category":"303","imdb":""},{"id":"6235937","name":"debian-live-6.0.0-i686-openbox-installer.iso","info_hash":"5A81DE1AEA89A3CEA01FAF1BF24F5CE1922E9AA1","leechers":"0","seeders":"0","num_files":"1","size":"159383552","username":"alretz","added":"1299868684","status":"member","category":"303","imdb":""},{"id":"6302628","name":"Linux Mint \\\"Debian\\\" - Linux Mint Xfce [201104] [32-Bit] [ISO","info_hash":"D097C0636EE45D235AE839AD7F1019CDB542D335","leechers":"0","seeders":"0","num_files":"1","size":"1004662784","username":"geno7744","added":"1302202364","status":"member","category":"303","imdb":""},{"id":"6302634","name":"Linux Mint \\\"Debian\\\" - Linux Mint Xfce [201104] [64-Bit] [ISO","info_hash":"C2B15F18A60573D075D15D917F5708FF854A082F","leechers":"0","seeders":"0","num_files":"1","size":"988688384","username":"geno7744","added":"1302202595","status":"member","category":"303","imdb":""},{"id":"7456182","name":"Debian_6.0.5_i386_netinst.iso","info_hash":"AC10EB57213131A1113321C66B991EC125AAFE55","leechers":"0","seeders":"0","num_files":"1","size":"200278016","username":"futurerealm","added":"1342663638","status":"member","category":"303","imdb":""},{"id":"7740588","name":"debian-testing-amd64-xfce-CD-1.iso","info_hash":"BE7968DC49EBC2994EC4129A7D42350831C95BB5","leechers":"1","seeders":"0","num_files":"1","size":"675741696","username":"ghostsquad57","added":"1350607428","status":"member","category":"303","imdb":""},{"id":"8166079","name":"Debian Wheezy 7.0 RC1 - Netinstall Amd64 ISO","info_hash":"5ED1E9731051E027FB0F097FC1D034F153192D7C","leechers":"0","seeders":"0","num_files":"1","size":"231735296","username":"melaur","added":"1361333871","status":"member","category":"303","imdb":""},{"id":"8166080","name":"Debian Wheezy 7.0 RC1 - CD1 Amd64 ISO","info_hash":"B0517AA899E8D81DF8731BF926408A10F615DC75","leechers":"0","seeders":"0","num_files":"1","size":"661651456","username":"melaur","added":"1361333966","status":"member","category":"303","imdb":""},{"id":"8166081","name":"Debian Wheezy 7.0 RC1 - DVD1 Amd64 ISO","info_hash":"2875DA262892568665D580B2043E5C0D49BD409F","leechers":"0","seeders":"0","num_files":"1","size":"3994091520","username":"melaur","added":"1361334036","status":"member","category":"303","imdb":""},{"id":"8447624","name":"debian-live-7.0.0-amd64-kde-desktop.iso","info_hash":"D0D5EC725AF658B964D7E319E3FF57A5CF17E773","leechers":"0","seeders":"0","num_files":"1","size":"1268842496","username":"arakus","added":"1367924014","status":"member","category":"303","imdb":""},{"id":"8452217","name":"debian-7.0.0-i386-DVD-1.iso","info_hash":"81BFB500A1C0BE3F1FA9C24FC6668882DA2BE1E7","leechers":"0","seeders":"0","num_files":"1","size":"3998007296","username":"LabelReunion","added":"1368023496","status":"member","category":"303","imdb":""},{"id":"8476583","name":"debian-7.0.0-amd64-DVD-1.iso","info_hash":"96534331D2D75ACF14F8162770495BD5B05A17A9","leechers":"0","seeders":"0","num_files":"1","size":"3998007296","username":"Caeden","added":"1368620918","status":"member","category":"303","imdb":""},{"id":"8476585","name":"debian-7.0.0-amd64-DVD-2.iso","info_hash":"9B9F7FC23507F56B24DF2CA8EA2ADD6DBA1665E9","leechers":"0","seeders":"0","num_files":"1","size":"4696872960","username":"Caeden","added":"1368620988","status":"member","category":"303","imdb":""},{"id":"8476587","name":"debian-7.0.0-amd64-DVD-3.iso","info_hash":"F32DE312C4819C405CE0D6A75578053AF517B45E","leechers":"0","seeders":"0","num_files":"1","size":"4698955776","username":"Caeden","added":"1368621052","status":"member","category":"303","imdb":""},{"id":"8717112","name":"debian-live-7.0.0-amd64-kde-desktop+nonfree.iso","info_hash":"5A7D58A79AE9F48CB480148340FCEFFE3A9F69DF","leechers":"0","seeders":"0","num_files":"1","size":"1268842496","username":"Agoing","added":"1374341366","status":"member","category":"399","imdb":""},{"id":"9167094","name":"Debian wheezy 7.2.0, 64-bit installer iso for CD or USB flash dr","info_hash":"5DFCA00F9C030A0E8404435F6FF3E8CB90EFBDC3","leechers":"1","seeders":"0","num_files":"1","size":"232783872","username":"rduke15","added":"1384003532","status":"member","category":"303","imdb":""},{"id":"10605619","name":"debian 7.6.0 versão mais recente.iso ","info_hash":"BDF336E0BB7B2EDDC586EECAFB8551B310D78480","leechers":"0","seeders":"0","num_files":"1","size":"679477248","username":"Bruno-kun","added":"1405975347","status":"member","category":"399","imdb":""}] 2 | -------------------------------------------------------------------------------- /tests/data/rich.xml: -------------------------------------------------------------------------------- 1 | 2 | 3211594 3 | High.Chaparall.S02E02.PDTV.XViD.SWEDiSH-HuBBaTiX 4 | b03c8641415d3a0fc7077f5bf567634442989a74 5 | 375299009 6 | 1 7 | 0 8 | 00 9 | 2004-03-25 23:08:00 10 | Andra avsnittet på säsong två av High Chaparall. 11 | 12 | 2004-04-05 18:56kan nån seeda första avsnittet 13 | 2004-05-03 19:18Ja snälla ta och seeda saknar 0,9%. 14 | 2004-05-25 18:32Snälla, kan någon seeda?<br /> 15 | 1 % kvar :S 16 | 2004-05-26 11:28asså har legat på 99% nu i 2 veckor, dryyyyyyyygt!! 17 | 2004-05-27 21:14Legat på 99 % ett bra tag nu jag också, vore tacksam om någon kunde seeda 18 | 2006-06-22 23:03Er det helt nye afsnit? :D 19 | 2006-06-25 17:03Wow, the piratebay has really gone to shit, What happened? 20 | 2006-06-26 07:22wth is going on 21 | 2006-06-30 07:44INFO av avsnit ????? 22 | 2006-06-30 07:44avsnitt 23 | 2006-08-22 02:10Uri Geller?<br /> 24 | 2008-10-04 18:14Form, I was going to say that :( 25 | 2009-01-28 20:49lol first torrent on TPB EVER.<br /> 26 | <br /> 27 | <br /> 28 | wow.<br /> 29 | <br /> 30 | <br /> 31 | u think he could have picked a better name than kbdcb lolololol 32 | 2009-03-03 22:59It's the oldest TV Show torrent that hasn't been deleted,<br /> 33 | <br /> 34 | yet 35 | 2010-04-11 08:26wow i found that this is the first torrent ever to be uploaded to tpb 36 | 2010-07-13 13:59oldest torrent evur 37 | 2010-08-04 16:54precisely my thought... :) 38 | 2011-01-02 18:57Well I have a torrent that uploaded 09-02 2004.<br /> 39 | And it´s still active :D<br /> 40 | 7 Years ftw guys!! 41 | 2011-11-26 02:22"...Querido diario íntimo: mi corazón estalló de emoción al descubrir el torrent más viejo en 'The Pirate Bay'. Estoy feliz por comentar esta publicación y ser parte de la historia de TPB. Es como escalar el Everest. Sinceramente, gracias...".<br /> 42 | <br /> 43 | "... Dear diary, my heart burst of excitement to discover the oldest torrent in The Pirate Bay '. I am happy to comment on this book and be part of the history of TPB. It's like climbing Everest. Sincerely, thanks ...".<br /> 44 | <br /> 45 | "... Kära dagbok, mitt hjärta brast av spänning för att upptäcka den äldsta torrent i The Pirate Bay". Jag är glad att kommentera denna bok och vara en del av historien om TPB. Det är som att klättra Everest. Vänliga hälsningar, tack ...".<br /> 46 | <br /> 47 | "... Liebes Tagebuch, mein Herz brach der Aufregung um die älteste torrent in The Pirate Bay" zu entdecken. Ich freue mich auf dieses Buch kommentieren und werden Sie Teil der Geschichte der TPB. Es ist wie Bergsteigen Everest. Mit freundlichen Grüßen, dank ...". 48 | 2012-01-09 11:04just find this first torrent on TPB, from the help of manOtor m8, thanks 4 ur work kbdcb :) 49 | 50 | 51 | 52 | 53 | 3211609 54 | School.Of.Rock.PROPER.DVDRip.XviD-DMT 55 | a896f7155237fb27e2eaa06033b5796d7ae84a1d 56 | 739308799 57 | 0 58 | 2 59 | 00 60 | 2004-03-26 09:35:17 61 | OrginalRelease 62 | 63 | 2004-04-06 06:24hur fan öppnar jag filmen 64 | 2004-04-17 19:42med winrar<br /> 65 | 2004-04-18 21:19lite seg i början... men riktigt bra efter ett tag 66 | 2004-04-28 21:03Seeda... 67 | 2004-05-05 12:30Kan ingen seeda... Ligger på 97%... Skojj... 68 | 2004-05-08 09:57hur fixar man filmen när den bara"darrar" bilden likson skakar hela tiden. Någon som vet?? 69 | 2004-05-09 22:53"hur fixar man filmen när den bara"darrar" bilden likson skakar hela tiden. Någon som vet?"<br /> 70 | <br /> 71 | precis samma sak för mig, försökt med alla codecs mm. fatar 0:an! någon som vet? 72 | 2004-05-10 11:11Ni som lyckats med denna film kan väl höra av er och berätta hur ni gjort! 73 | 2004-06-07 00:51SWESUB: <a href="http://www.undertexter.se/index.php?p=subark&id=1148" rel="nofollow" target="_new">http://www.undertexter.se/index.php?p=subark&id=1148</a> 74 | 2004-06-22 23:44snälla seeda. 75 | 2004-08-04 08:15Nån måste läea mig hur man lägger in subs!!<br /> 76 | Och mitt nero (nyaste) bränner INTE avi filer.... :S<br /> 77 | <br /> 78 | :axe: 79 | 2004-09-02 22:04mrmaniac å erikapa Haft samma problem...lösningen heter vlc media player!! spelar upp allt perfect...till och med filer som windows ej kan identifiera=) har tyvärr ej URL...men kolla google... lycka till! 80 | 2004-09-05 07:53Om ni ska ha vlc, kika in på <a href="http://www.videolan.org./vlc/" rel="nofollow" target="_new">http://www.videolan.org./vlc/</a> 81 | 2004-09-06 21:37Nero som inte bränner avi? Det låter ju asdumt. Hur kommer man på något sånt? Säkert någon jäkla anti-piratgrej. *grr* 82 | 2004-09-11 19:56Fyfan så bra film, synd att man inte hade en gitarr att rocka med =(. SEVÄRD! 83 | 2004-09-29 05:59Fin kvalite och bra ljud. Hoppas bara att den funkar på DVD-spelarn nu :) 84 | 2004-10-09 01:09hmm.. kan inte alla dela med sig mera när dom seedar.. snålt :/ 85 | 2004-12-14 16:33kan inte alla seeda när dom laddar ner:/ eller??? 86 | 2004-12-14 16:35SEEDAAA DE GÅR TRÖÖÖÖGT LIGGER PÅ 20 kb/s!!!:@ 87 | 2004-12-20 20:41Kan inte någon seeda lite mer än 20 kbs 88 | 2004-12-21 14:27vlc- player spiller bare filer / filmer i et par sekunder så stopper den . åssen fixer jg dette 89 | 2004-12-21 16:44Kan inte någon Seeda alla ligger på 81.8% Finns det inte nåon som vill försöka hålla igång det här så det funkar bra. 90 | 2005-01-04 13:10Seeda plz 91 | 2005-01-04 13:11jag kan seeda sen men ja vill gärna ha filmen först<br /> 92 | 2006-06-22 17:23Seeda! Fast på 99.6% Jag ska hjälpa till om jag får ner filmen! 93 | 2006-06-22 23:28seeda förfan sitter på 99.0%<br /> 94 | <br /> 95 | ooooooooooooooorka 96 | 2006-06-23 09:19Va faen, jag fattar inget. Allt på hela TPB står med bara 1 seed, inkl. YOP 100. Igår var hela TOP 100 annorlunda med jävla "irish drinking songs" å "simpsons" på första plats. Inget verkar va sig likt eftr. tillslaget. Vad har hänt? 97 | 2006-06-24 13:11Please seed. I'm at 93.3%, and have been for three days now.<br /> 98 | And also... piet00piet, please stop spamming your comments. It's annoying. 99 | 2006-06-27 20:07why cant i download the movie?<br /> 100 | <br /> 101 | can i have a step by step on how to do it? 102 | 2006-06-29 16:37Fan Vad LOL Filmen Var Upp o ner när man spela upp den 103 | 2006-07-03 13:25This movie roxorz 104 | 2006-07-03 14:32PirateBay used to be good, but something has chnaged, now it sucks! You can not tell how many Seeders there are or no one seems to be seeding. 105 | 2006-07-07 18:33Tänkte bara påpeka att gula sidorna finns på internet... och att Pirates of the Carribean: Dead Man Chest finns på IsoHunt nu. <br /> 106 | <br /> 107 | Har inte en susning om kvaliteteten håller på att slanga den själv nu. 108 | 2006-07-08 17:42this is a funny movie! Both for kids and adults. 109 | 2006-07-09 02:52Good stuff!!! 110 | 2011-11-01 18:01< a href="<a href="http://www.imdb.com/title/tt0332379/" rel="nofollow" target="_new">http://www.imdb.com/title/tt0332379/</a>">< IMG SRC = "<a href="http://www.imdb.com/title/tt0332379/" rel="nofollow" target="_new">http://www.imdb.com/title/tt0332379/</a>" >< / a > 111 | 2011-11-01 18:04The School Of Rock 112 | 2011-11-01 18:29<a href="http://www.imdb.com/title/tt0332379/" rel="nofollow" target="_new">http://www.imdb.com/title/tt0332379/</a> 113 | 2011-11-01 18:54< IMG SRC = "<a href="http://www.imdb.com/media/rm3808337152/tt0332379" rel="nofollow" target="_new">http://www.imdb.com/media/rm3808337152/tt0332379</a>" >< / a > 114 | 2011-11-01 19:05<a href="LINKhttp://www.imdb.com/title/tt0332379/" rel="nofollow" target="_new">LINKhttp://www.imdb.com/title/tt0332379/</a> 115 | 2011-11-01 19:24LINK;<a href="http://www.imdb.com/title/tt0332379/" rel="nofollow" target="_new">http://www.imdb.com/title/tt0332379/</a> 116 | 2011-11-01 20:01<a href="http://www.imdb.com/media/rm3808337152/tt0332379" rel="nofollow" target="_new">http://www.imdb.com/media/rm3808337152/tt0332379</a> 117 | 2011-11-01 20:36 118 | 119 | 120 | 121 | 122 | 3211623 123 | Gyllene Tider-Samtliga Hits-SE-2004-WLM 124 | 3ebb7aa97076cac0ac1b0812f5e16cf46d5daf41 125 | 127185941 126 | 7 127 | 1 128 | 10 129 | 2004-03-29 09:00:10 130 | Tanka på 131 | 132 | 2004-05-16 06:59Seeda plz!<br /> 133 | Solen skiner och det GT är ett måste :P 134 | 2004-05-20 15:43seeda lite te..... plezzz måste ha den här samlingen råkade radera den innan 135 | 2004-05-31 11:43kan nån jävel seeda?!?!<br /> 136 | 2004-05-31 18:11ligger på 87,6% varför seedar ingen?!?!?!?!?!??! 137 | 2004-06-02 07:49Jag såg att det behövdes någon som seedar. Håll till godo. 138 | 2004-06-02 16:45tack... har väntat flera dar för att få ner den här 139 | 2004-06-13 08:07Fan vaa nice! 140 | 2004-06-25 18:28Varför kan jag inte koppla upp mig mot ngn peer!? :evil:<br /> 141 | <br /> 142 | Varenda annan jäkla torrent funkar men inte denna :'( 143 | 2004-08-12 12:35TackaR! Detta har jag letat efter 144 | 2004-08-19 11:30uh, men förfan, reseeda, så håller jag igång den i ett par veckor!<br /> 145 | <br /> 146 | orka ladda om när man bara har 10% kvar... 147 | 2005-04-02 05:23seeda tack! 148 | 2006-06-23 17:02We need seeders. I'm stuck at 99.7%. Is there anyone who could seed this? 149 | 2006-06-24 22:49Sitter med på 99,7%. 150 | 2006-06-26 22:32Seeda för helvete! 151 | 2006-06-26 22:346 stycken peers - Alla har 99,7% - Hooray! 152 | 2006-06-29 22:35när jag trycker: download this torrent, så kommer den upp i typ en halv sekund, sen försvinner den. <br /> 153 | vad gör jag för fel? 154 | 2006-06-30 14:25SEEDA....vilken djävla dum kommentar!<br /> 155 | <br /> 156 | Klart att man seedar...iaf på riktiga trackers LOL<br /> 157 | <br /> 158 | 2006-07-01 21:33shyst !! jävligt bra ,,, tack m8 för att du ladda upp den xD. 159 | 2006-07-05 13:19Bra att ni seedade nu<br /> 160 | <br /> 161 | Tack så hemskt mycket :) 162 | 2006-07-18 14:54SNÄLLA SNÄLLA!! Seeda jag har stannat på 99% sen säkert en vecka... 163 | 2012-07-24 23:07I sorted all of the music torrents by upload date and this came up as the oldest one. Unsurprising considering this is a Swedish website.<br /> 164 | <br /> 165 | Per Gessle rocks! Whooooo! 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /tests/data/result.json: -------------------------------------------------------------------------------- 1 | [{"id": "6089103", "name": "Linux Mint Debian [201012] [ISO] [64-Bit] [geno7744] ", "info_hash": 80795982264005515156107154982012464690660356648, "leechers": 1, "seeders": 1, "num_files": "1", "size": "974.2 MiB", "username": "geno7744", "added": "1294464892", "status": "member", "category": 303, "imdb": "", "raw_size": 1021560832, "magnet": "magnet:?xt=urn:btih:0E270463CD1AD2D856EA89859829BC1E63E3B228&dn=Linux%20Mint%20Debian%20%5B201012%5D%20%5BISO%5D%20%5B64-Bit%5D%20%5Bgeno7744%5D%20", "raw_uploaded": 1294464892, "uploaded": "2011-01-08 05:34"}, {"id": "8442441", "name": "debian-7.0.0-i386-DVD-1.iso", "info_hash": 722580357008177778209183558297497340197820479935, "leechers": 0, "seeders": 1, "num_files": "1", "size": "3.7 GiB", "username": "mmxx_01", "added": "1367797189", "status": "member", "category": 303, "imdb": "", "raw_size": 3998007296, "magnet": "magnet:?xt=urn:btih:7E919FB33216E2BC6C31ADE3594A3866D260B9BF&dn=debian-7.0.0-i386-DVD-1.iso", "raw_uploaded": 1367797189, "uploaded": "2013-05-05 23:39"}, {"id": "3357155", "name": "debian_gnu_linux_31r0a_ia64_1_iso", "info_hash": 689059738704693667977745168177664313802663339526, "leechers": 1, "seeders": 0, "num_files": "2", "size": "4.3 GiB", "username": "gigli", "added": "1121550810", "status": "member", "category": 303, "imdb": "", "raw_size": 4640233753, "magnet": "magnet:?xt=urn:btih:78B281DF90ED64F8E6D13555C9108A54C9472606&dn=debian_gnu_linux_31r0a_ia64_1_iso", "raw_uploaded": 1121550810, "uploaded": "2005-07-16 21:53"}, {"id": "3441282", "name": "Debian 3.1r1 i386 binary No. 1 (of 14) ISO file", "info_hash": 921490056423831576913963695099571046100261500145, "leechers": 0, "seeders": 0, "num_files": "1", "size": "638.6 MiB", "username": "PixelHermit", "added": "1139313316", "status": "member", "category": 303, "imdb": "", "raw_size": 669585408, "magnet": "magnet:?xt=urn:btih:A1690B1129AE13E5F01457338F5D06223F8174F1&dn=Debian%203.1r1%20i386%20binary%20No.%201%20%28of%2014%29%20ISO%20file", "raw_uploaded": 1139313316, "uploaded": "2006-02-07 11:55"}, {"id": "3441283", "name": "Debian 3.1r1 i386 binary No. 2 (of 14) ISO file", "info_hash": 1017066668506766024805398047146111070264848022468, "leechers": 0, "seeders": 0, "num_files": "1", "size": "640.0 MiB", "username": "PixelHermit", "added": "1139313488", "status": "member", "category": 303, "imdb": "", "raw_size": 671037440, "magnet": "magnet:?xt=urn:btih:B226D8C4192EB6994FEAF0DBCA04C6126DC7FBC4&dn=Debian%203.1r1%20i386%20binary%20No.%202%20%28of%2014%29%20ISO%20file", "raw_uploaded": 1139313488, "uploaded": "2006-02-07 11:58"}, {"id": "3441284", "name": "Debian 3.1r1 i386 binary No. 3 (of 14) ISO file", "info_hash": 1341401429899326842086437561024998431776375829169, "leechers": 1, "seeders": 0, "num_files": "1", "size": "642.5 MiB", "username": "PixelHermit", "added": "1139313671", "status": "member", "category": 303, "imdb": "", "raw_size": 673679360, "magnet": "magnet:?xt=urn:btih:EAF6853B9438EB757D066BFDE0D13AD9F657F2B1&dn=Debian%203.1r1%20i386%20binary%20No.%203%20%28of%2014%29%20ISO%20file", "raw_uploaded": 1139313671, "uploaded": "2006-02-07 12:01"}, {"id": "3578845", "name": "debian-31r4-i386-netinst.iso", "info_hash": 1190326781527594986631304106552213100503470480731, "leechers": 0, "seeders": 0, "num_files": "1", "size": "112.2 MiB", "username": "keep_patrick", "added": "1166383842", "status": "member", "category": 303, "imdb": "", "raw_size": 117620736, "magnet": "magnet:?xt=urn:btih:D08019524B9FD86A48D31347BFC3714408B09D5B&dn=debian-31r4-i386-netinst.iso", "raw_uploaded": 1166383842, "uploaded": "2006-12-17 19:30"}, {"id": "3795842", "name": "Debian 4.0 ETCH.iso", "info_hash": 341174057895425211125490586805104666098960797816, "leechers": 0, "seeders": 0, "num_files": "1", "size": "3.6 GiB", "username": "lkonti", "added": "1188950149", "status": "member", "category": 303, "imdb": "", "raw_size": 3833810944, "magnet": "magnet:?xt=urn:btih:3BC2C61C420A62DE7442E44698E6AED05A499078&dn=Debian%204.0%20ETCH.iso", "raw_uploaded": 1188950149, "uploaded": "2007-09-04 23:55"}, {"id": "3860812", "name": "debian-live-etch-i386-standard.iso", "info_hash": 375240546390171180979179024422139356658954548844, "leechers": 0, "seeders": 0, "num_files": "1", "size": "81.2 MiB", "username": "superunix", "added": "1193471893", "status": "member", "category": 303, "imdb": "", "raw_size": 85168128, "magnet": "magnet:?xt=urn:btih:41BA5E3833E9D678DB41673183EC49AD32EA366C&dn=debian-live-etch-i386-standard.iso", "raw_uploaded": 1193471893, "uploaded": "2007-10-27 07:58"}, {"id": "3872700", "name": "debian-kde4beta4-live-cd-i386.iso", "info_hash": 255001694441119611713565405428907543400911906961, "leechers": 0, "seeders": 0, "num_files": "1", "size": "418.2 MiB", "username": "jknotzke", "added": "1194191588", "status": "member", "category": 303, "imdb": "", "raw_size": 438484992, "magnet": "magnet:?xt=urn:btih:2CAAABE42A03A3EFB28F33DE93C2FBB278EAA891&dn=debian-kde4beta4-live-cd-i386.iso", "raw_uploaded": 1194191588, "uploaded": "2007-11-04 15:53"}, {"id": "3947454", "name": "Debian 4.0 r1 Update.iso", "info_hash": 606994683147973413780468573362798954490278176700, "leechers": 0, "seeders": 0, "num_files": "1", "size": "1.3 GiB", "username": "shasi420", "added": "1198595636", "status": "member", "category": 303, "imdb": "", "raw_size": 1374822400, "magnet": "magnet:?xt=urn:btih:6A52953C8C8C6DAE89D867EB3DEB1C66AC43E7BC&dn=Debian%204.0%20r1%20Update.iso", "raw_uploaded": 1198595636, "uploaded": "2007-12-25 15:13"}, {"id": "4224808", "name": "debian-hamm-source-cs.iso", "info_hash": 61691326620951224084992079352569146745579057563, "leechers": 0, "seeders": 0, "num_files": "1", "size": "602.1 MiB", "username": "geier", "added": "1212764102", "status": "trusted", "category": 303, "imdb": "", "raw_size": 631373824, "magnet": "magnet:?xt=urn:btih:0ACE55B2D81A56E1139A2E7C070F54B2F82F319B&dn=debian-hamm-source-cs.iso", "raw_uploaded": 1212764102, "uploaded": "2008-06-06 14:55"}, {"id": "4244856", "name": "debian-40r3-i386-netinst.iso", "info_hash": 760184894299265408134398932196202327732386155174, "leechers": 0, "seeders": 0, "num_files": "1", "size": "159.6 MiB", "username": "rabenkind", "added": "1213728149", "status": "member", "category": 303, "imdb": "", "raw_size": 167313408, "magnet": "magnet:?xt=urn:btih:8527DE9E12B4196A1C443853C2DD349C8E264AA6&dn=debian-40r3-i386-netinst.iso", "raw_uploaded": 1213728149, "uploaded": "2008-06-17 18:42"}, {"id": "4512019", "name": "debian-testing-amd64-i386-powerpc-netinst.iso", "info_hash": 955311907772995664947964713591409505697817906655, "leechers": 0, "seeders": 0, "num_files": "1", "size": "470.1 MiB", "username": "AMDFreak78", "added": "1226817859", "status": "member", "category": 303, "imdb": "", "raw_size": 492965888, "magnet": "magnet:?xt=urn:btih:A755AAE126AAF9047B89D0075FF19F702B6B4DDF&dn=debian-testing-amd64-i386-powerpc-netinst.iso", "raw_uploaded": 1226817859, "uploaded": "2008-11-16 06:44"}, {"id": "4725085", "name": "debian-500-i386-businesscard.iso", "info_hash": 8919171032581421194728491876700289114433037625, "leechers": 0, "seeders": 0, "num_files": "1", "size": "35.4 MiB", "username": "dreamszz", "added": "1234708307", "status": "member", "category": 303, "imdb": "", "raw_size": 37136384, "magnet": "magnet:?xt=urn:btih:018FF30FE833FA680A6E35B73C1B5DD6F0EAA539&dn=debian-500-i386-businesscard.iso", "raw_uploaded": 1234708307, "uploaded": "2009-02-15 14:31"}, {"id": "4727053", "name": "debian-500-i386-netinst.iso", "info_hash": 1379765476966545756211988693588566713117000296726, "leechers": 0, "seeders": 0, "num_files": "1", "size": "149.9 MiB", "username": "dreamszz", "added": "1234806400", "status": "member", "category": 303, "imdb": "", "raw_size": 157204480, "magnet": "magnet:?xt=urn:btih:F1AED2E515A0BDF141549D440047AB97812B6916&dn=debian-500-i386-netinst.iso", "raw_uploaded": 1234806400, "uploaded": "2009-02-16 17:46"}, {"id": "4734148", "name": "debian-500-i386-DVD-1.iso", "info_hash": 1185018697868601890431751383066358717434374821721, "leechers": 1, "seeders": 0, "num_files": "1", "size": "4.4 GiB", "username": "KRZR", "added": "1235186603", "status": "member", "category": 303, "imdb": "", "raw_size": 4698322944, "magnet": "magnet:?xt=urn:btih:CF92138268871BC3BB964ED69DB1EC36C2CE9759&dn=debian-500-i386-DVD-1.iso", "raw_uploaded": 1235186603, "uploaded": "2009-02-21 03:23"}, {"id": "4774275", "name": "debian-40r6-i386-amd64-powerpc-source-DVD-1.iso", "info_hash": 983926822319029410114111508998868428479086743491, "leechers": 0, "seeders": 0, "num_files": "1", "size": "4.1 GiB", "username": "CriogenicFear", "added": "1237149753", "status": "member", "category": 303, "imdb": "", "raw_size": 4385832960, "magnet": "magnet:?xt=urn:btih:AC58CDFD2577CCE93F7040F88BB4B782B5244FC3&dn=debian-40r6-i386-amd64-powerpc-source-DVD-1.iso", "raw_uploaded": 1237149753, "uploaded": "2009-03-15 20:42"}, {"id": "5247569", "name": "Debian 5.03 on a Blu-Ray ISO. Downloaded only a few days ago.", "info_hash": 255192467999179059682926285371714956385092837374, "leechers": 0, "seeders": 0, "num_files": "1", "size": "18.7 GiB", "username": "cerre", "added": "1262216973", "status": "member", "category": 303, "imdb": "", "raw_size": 20066349056, "magnet": "magnet:?xt=urn:btih:2CB339DD437A0A05BC65DACFF89E8A68EF671FFE&dn=Debian%205.03%20on%20a%20Blu-Ray%20ISO.%20Downloaded%20only%20a%20few%20days%20ago.", "raw_uploaded": 1262216973, "uploaded": "2009-12-30 23:49"}, {"id": "5724168", "name": "clonezilla-live-1.2.5.38 iso files (Testing Debian-based)", "info_hash": 1289663648106087712521617503484063321980943317226, "leechers": 1, "seeders": 0, "num_files": "3", "size": "366.0 MiB", "username": "Anonymous", "added": "1280391570", "status": "member", "category": 699, "imdb": "", "raw_size": 383778816, "magnet": "magnet:?xt=urn:btih:E1E684A0061FB8C26A6FEF7A912347A7AB09B8EA&dn=clonezilla-live-1.2.5.38%20iso%20files%20%28Testing%20Debian-based%29", "raw_uploaded": 1280391570, "uploaded": "2010-07-29 08:19"}, {"id": "5772142", "name": "Debian-Linux-2010.iso", "info_hash": 978217665147846806722892460805650877619966775379, "leechers": 0, "seeders": 0, "num_files": "1", "size": "4.4 GiB", "username": "Maizer911", "added": "1282132638", "status": "member", "category": 303, "imdb": "", "raw_size": 4681738240, "magnet": "magnet:?xt=urn:btih:AB58CC1423C06E30343BDCA6856A533D63531053&dn=Debian-Linux-2010.iso", "raw_uploaded": 1282132638, "uploaded": "2010-08-18 11:57"}, {"id": "5817670", "name": "Linux Mint Debian [201009] [ISO] [geno7744]", "info_hash": 1144983771245866337184222353155138181654247734705, "leechers": 1, "seeders": 0, "num_files": "1", "size": "874.6 MiB", "username": "geno7744", "added": "1283915768", "status": "member", "category": 303, "imdb": "", "raw_size": 917123072, "magnet": "magnet:?xt=urn:btih:C88ED91734EFE4AB5DA1C1851F3F6CF472157DB1&dn=Linux%20Mint%20Debian%20%5B201009%5D%20%5BISO%5D%20%5Bgeno7744%5D", "raw_uploaded": 1283915768, "uploaded": "2010-09-08 03:16"}, {"id": "5948268", "name": "debian-506-i386-DVD-1.iso", "info_hash": 808046707434296142448012177344602162952657342887, "leechers": 0, "seeders": 0, "num_files": "1", "size": "4.4 GiB", "username": "NickShim", "added": "1289441340", "status": "member", "category": 699, "imdb": "", "raw_size": 4675819520, "magnet": "magnet:?xt=urn:btih:8D8A114979524D0A2F881E758F42BD14C10A91A7&dn=debian-506-i386-DVD-1.iso", "raw_uploaded": 1289441340, "uploaded": "2010-11-11 02:09"}, {"id": "6039270", "name": "debian-privacy-remix.iso", "info_hash": 1459649973739518810476349462010708323032997184957, "leechers": 0, "seeders": 0, "num_files": "1", "size": "1.4 GiB", "username": "Brage P", "added": "1292329538", "status": "member", "category": 303, "imdb": "", "raw_size": 1531969536, "magnet": "magnet:?xt=urn:btih:FFACF7F1C5922C70FEF99A887D94D8765BAE45BD&dn=debian-privacy-remix.iso", "raw_uploaded": 1292329538, "uploaded": "2010-12-14 12:25"}, {"id": "6089092", "name": "Linux Mint Debian [201101] [ISO] [32-Bit] [geno7744] ", "info_hash": 266044536086293871309947032924605765528595699099, "leechers": 0, "seeders": 0, "num_files": "1", "size": "986.0 MiB", "username": "geno7744", "added": "1294464609", "status": "member", "category": 303, "imdb": "", "raw_size": 1033945088, "magnet": "magnet:?xt=urn:btih:2E99D97F1768644A86A8E99BFD80C816490F959B&dn=Linux%20Mint%20Debian%20%5B201101%5D%20%5BISO%5D%20%5B32-Bit%5D%20%5Bgeno7744%5D%20", "raw_uploaded": 1294464609, "uploaded": "2011-01-08 05:30"}, {"id": "6235937", "name": "debian-live-6.0.0-i686-openbox-installer.iso", "info_hash": 516705313591328416372009021219231554066424175265, "leechers": 0, "seeders": 0, "num_files": "1", "size": "152.0 MiB", "username": "alretz", "added": "1299868684", "status": "member", "category": 303, "imdb": "", "raw_size": 159383552, "magnet": "magnet:?xt=urn:btih:5A81DE1AEA89A3CEA01FAF1BF24F5CE1922E9AA1&dn=debian-live-6.0.0-i686-openbox-installer.iso", "raw_uploaded": 1299868684, "uploaded": "2011-03-11 18:38"}, {"id": "6302628", "name": "Linux Mint \\\"Debian\\\" - Linux Mint Xfce [201104] [32-Bit] [ISO", "info_hash": 1190854252250590780560429763076669195625374602037, "leechers": 0, "seeders": 0, "num_files": "1", "size": "958.1 MiB", "username": "geno7744", "added": "1302202364", "status": "member", "category": 303, "imdb": "", "raw_size": 1004662784, "magnet": "magnet:?xt=urn:btih:D097C0636EE45D235AE839AD7F1019CDB542D335&dn=Linux%20Mint%20%5C%22Debian%5C%22%20-%20Linux%20Mint%20Xfce%20%5B201104%5D%20%5B32-Bit%5D%20%5BISO", "raw_uploaded": 1302202364, "uploaded": "2011-04-07 18:52"}, {"id": "6302634", "name": "Linux Mint \\\"Debian\\\" - Linux Mint Xfce [201104] [64-Bit] [ISO", "info_hash": 1111499725494585269100850072277199343426671872047, "leechers": 0, "seeders": 0, "num_files": "1", "size": "942.9 MiB", "username": "geno7744", "added": "1302202595", "status": "member", "category": 303, "imdb": "", "raw_size": 988688384, "magnet": "magnet:?xt=urn:btih:C2B15F18A60573D075D15D917F5708FF854A082F&dn=Linux%20Mint%20%5C%22Debian%5C%22%20-%20Linux%20Mint%20Xfce%20%5B201104%5D%20%5B64-Bit%5D%20%5BISO", "raw_uploaded": 1302202595, "uploaded": "2011-04-07 18:56"}, {"id": "7456182", "name": "Debian_6.0.5_i386_netinst.iso", "info_hash": 982323725540756726924071830373687458237552197205, "leechers": 0, "seeders": 0, "num_files": "1", "size": "191.0 MiB", "username": "futurerealm", "added": "1342663638", "status": "member", "category": 303, "imdb": "", "raw_size": 200278016, "magnet": "magnet:?xt=urn:btih:AC10EB57213131A1113321C66B991EC125AAFE55&dn=Debian_6.0.5_i386_netinst.iso", "raw_uploaded": 1342663638, "uploaded": "2012-07-19 02:07"}, {"id": "7740588", "name": "debian-testing-amd64-xfce-CD-1.iso", "info_hash": 1087415771263667121064339753920887629991960468405, "leechers": 1, "seeders": 0, "num_files": "1", "size": "644.4 MiB", "username": "ghostsquad57", "added": "1350607428", "status": "member", "category": 303, "imdb": "", "raw_size": 675741696, "magnet": "magnet:?xt=urn:btih:BE7968DC49EBC2994EC4129A7D42350831C95BB5&dn=debian-testing-amd64-xfce-CD-1.iso", "raw_uploaded": 1350607428, "uploaded": "2012-10-19 00:43"}, {"id": "8166079", "name": "Debian Wheezy 7.0 RC1 - Netinstall Amd64 ISO", "info_hash": 541326324520720881965336898533966032628960800124, "leechers": 0, "seeders": 0, "num_files": "1", "size": "221.0 MiB", "username": "melaur", "added": "1361333871", "status": "member", "category": 303, "imdb": "", "raw_size": 231735296, "magnet": "magnet:?xt=urn:btih:5ED1E9731051E027FB0F097FC1D034F153192D7C&dn=Debian%20Wheezy%207.0%20RC1%20-%20Netinstall%20Amd64%20ISO", "raw_uploaded": 1361333871, "uploaded": "2013-02-20 04:17"}, {"id": "8166080", "name": "Debian Wheezy 7.0 RC1 - CD1 Amd64 ISO", "info_hash": 1006599421096978933808505216878621295017941392501, "leechers": 0, "seeders": 0, "num_files": "1", "size": "631.0 MiB", "username": "melaur", "added": "1361333966", "status": "member", "category": 303, "imdb": "", "raw_size": 661651456, "magnet": "magnet:?xt=urn:btih:B0517AA899E8D81DF8731BF926408A10F615DC75&dn=Debian%20Wheezy%207.0%20RC1%20-%20CD1%20Amd64%20ISO", "raw_uploaded": 1361333966, "uploaded": "2013-02-20 04:19"}, {"id": "8166081", "name": "Debian Wheezy 7.0 RC1 - DVD1 Amd64 ISO", "info_hash": 230987821484173680714374515411410949945908084895, "leechers": 0, "seeders": 0, "num_files": "1", "size": "3.7 GiB", "username": "melaur", "added": "1361334036", "status": "member", "category": 303, "imdb": "", "raw_size": 3994091520, "magnet": "magnet:?xt=urn:btih:2875DA262892568665D580B2043E5C0D49BD409F&dn=Debian%20Wheezy%207.0%20RC1%20-%20DVD1%20Amd64%20ISO", "raw_uploaded": 1361334036, "uploaded": "2013-02-20 04:20"}, {"id": "8447624", "name": "debian-live-7.0.0-amd64-kde-desktop.iso", "info_hash": 1192240736471224992363141147771043610819590350707, "leechers": 0, "seeders": 0, "num_files": "1", "size": "1.2 GiB", "username": "arakus", "added": "1367924014", "status": "member", "category": 303, "imdb": "", "raw_size": 1268842496, "magnet": "magnet:?xt=urn:btih:D0D5EC725AF658B964D7E319E3FF57A5CF17E773&dn=debian-live-7.0.0-amd64-kde-desktop.iso", "raw_uploaded": 1367924014, "uploaded": "2013-05-07 10:53"}, {"id": "8452217", "name": "debian-7.0.0-i386-DVD-1.iso", "info_hash": 740735019307954783227960257388713188362285736423, "leechers": 0, "seeders": 0, "num_files": "1", "size": "3.7 GiB", "username": "LabelReunion", "added": "1368023496", "status": "member", "category": 303, "imdb": "", "raw_size": 3998007296, "magnet": "magnet:?xt=urn:btih:81BFB500A1C0BE3F1FA9C24FC6668882DA2BE1E7&dn=debian-7.0.0-i386-DVD-1.iso", "raw_uploaded": 1368023496, "uploaded": "2013-05-08 14:31"}, {"id": "8476583", "name": "debian-7.0.0-amd64-DVD-1.iso", "info_hash": 858205430952303442181229988565206976761100375977, "leechers": 0, "seeders": 0, "num_files": "1", "size": "3.7 GiB", "username": "Caeden", "added": "1368620918", "status": "member", "category": 303, "imdb": "", "raw_size": 3998007296, "magnet": "magnet:?xt=urn:btih:96534331D2D75ACF14F8162770495BD5B05A17A9&dn=debian-7.0.0-amd64-DVD-1.iso", "raw_uploaded": 1368620918, "uploaded": "2013-05-15 12:28"}, {"id": "8476585", "name": "debian-7.0.0-amd64-DVD-2.iso", "info_hash": 888450517309844419082815343848182492547694093801, "leechers": 0, "seeders": 0, "num_files": "1", "size": "4.4 GiB", "username": "Caeden", "added": "1368620988", "status": "member", "category": 303, "imdb": "", "raw_size": 4696872960, "magnet": "magnet:?xt=urn:btih:9B9F7FC23507F56B24DF2CA8EA2ADD6DBA1665E9&dn=debian-7.0.0-amd64-DVD-2.iso", "raw_uploaded": 1368620988, "uploaded": "2013-05-15 12:29"}, {"id": "8476587", "name": "debian-7.0.0-amd64-DVD-3.iso", "info_hash": 1388308071719317659206743703980188513029953401950, "leechers": 0, "seeders": 0, "num_files": "1", "size": "4.4 GiB", "username": "Caeden", "added": "1368621052", "status": "member", "category": 303, "imdb": "", "raw_size": 4698955776, "magnet": "magnet:?xt=urn:btih:F32DE312C4819C405CE0D6A75578053AF517B45E&dn=debian-7.0.0-amd64-DVD-3.iso", "raw_uploaded": 1368621052, "uploaded": "2013-05-15 12:30"}, {"id": "8717112", "name": "debian-live-7.0.0-amd64-kde-desktop+nonfree.iso", "info_hash": 516604485438195032346767058483128354960364759519, "leechers": 0, "seeders": 0, "num_files": "1", "size": "1.2 GiB", "username": "Agoing", "added": "1374341366", "status": "member", "category": 399, "imdb": "", "raw_size": 1268842496, "magnet": "magnet:?xt=urn:btih:5A7D58A79AE9F48CB480148340FCEFFE3A9F69DF&dn=debian-live-7.0.0-amd64-kde-desktop%2Bnonfree.iso", "raw_uploaded": 1374341366, "uploaded": "2013-07-20 17:29"}, {"id": "9167094", "name": "Debian wheezy 7.2.0, 64-bit installer iso for CD or USB flash dr", "info_hash": 536569872754006726446059760945501647386767769027, "leechers": 1, "seeders": 0, "num_files": "1", "size": "222.0 MiB", "username": "rduke15", "added": "1384003532", "status": "member", "category": 303, "imdb": "", "raw_size": 232783872, "magnet": "magnet:?xt=urn:btih:5DFCA00F9C030A0E8404435F6FF3E8CB90EFBDC3&dn=Debian%20wheezy%207.2.0%2C%2064-bit%20installer%20iso%20for%20CD%20or%20USB%20flash%20dr", "raw_uploaded": 1384003532, "uploaded": "2013-11-09 13:25"}, {"id": "10605619", "name": "debian 7.6.0 versão mais recente.iso ", "info_hash": 1084423117304844355133768512253358904316863677568, "leechers": 0, "seeders": 0, "num_files": "1", "size": "648.0 MiB", "username": "Bruno-kun", "added": "1405975347", "status": "member", "category": 399, "imdb": "", "raw_size": 679477248, "magnet": "magnet:?xt=urn:btih:BDF336E0BB7B2EDDC586EECAFB8551B310D78480&dn=debian%207.6.0%20vers%26atilde%3Bo%20mais%20recente.iso%20", "raw_uploaded": 1405975347, "uploaded": "2014-07-21 20:42"}] -------------------------------------------------------------------------------- /pirate/pirate.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import re 3 | import os 4 | import argparse 5 | import subprocess 6 | import configparser 7 | import socket 8 | import urllib.request as request 9 | import urllib.error 10 | import builtins 11 | import json 12 | import webbrowser 13 | 14 | import pirate.data 15 | import pirate.torrent 16 | import pirate.local 17 | 18 | from os.path import expanduser, expandvars 19 | from pirate.print import Printer 20 | 21 | 22 | def parse_config_file(text): 23 | config = configparser.RawConfigParser() 24 | 25 | # default options 26 | config.add_section('Save') 27 | config.set('Save', 'magnets', 'false') 28 | config.set('Save', 'torrents', 'false') 29 | config.set('Save', 'directory', os.getcwd()) 30 | 31 | config.add_section('LocalDB') 32 | config.set('LocalDB', 'enabled', 'false') 33 | config.set('LocalDB', 'path', expanduser('~/downloads/pirate-get/db')) 34 | 35 | config.add_section('Search') 36 | config.set('Search', 'total-results', 50) 37 | 38 | config.add_section('Misc') 39 | # TODO: try to use configparser.BasicInterpolation 40 | # for interpolating in the command 41 | config.set('Misc', 'openCommand', '') 42 | config.set('Misc', 'transmission', 'false') 43 | config.set('Misc', 'transmission-auth', '') 44 | config.set('Misc', 'transmission-endpoint', '') 45 | config.set('Misc', 'transmission-port', '') # for backward compatibility 46 | config.set('Misc', 'colors', 'true') 47 | config.set('Misc', 'mirror', pirate.data.default_mirror) 48 | config.set('Misc', 'timeout', pirate.data.default_timeout) 49 | 50 | config.read_string(text) 51 | 52 | # expand env variables 53 | directory = expanduser(expandvars(config.get('Save', 'Directory'))) 54 | path = expanduser(expandvars(config.get('LocalDB', 'path'))) 55 | 56 | config.set('Save', 'Directory', directory) 57 | config.set('LocalDB', 'path', path) 58 | 59 | return config 60 | 61 | 62 | def load_config(): 63 | # user-defined config files 64 | config_home = os.getenv('XDG_CONFIG_HOME', '~/.config') 65 | config = expanduser(os.path.join(config_home, 'pirate-get')) 66 | 67 | # read config file 68 | if os.path.isfile(config): 69 | with open(config) as f: 70 | return parse_config_file(f.read()) 71 | 72 | return parse_config_file("") 73 | 74 | 75 | def parse_cmd(cmd, url): 76 | cmd_args_regex = r'''(('[^']*'|"[^"]*"|(\\\s|[^\s])+)+ *)''' 77 | ret = re.findall(cmd_args_regex, cmd) 78 | ret = [i[0].strip().replace('%s', url) for i in ret] 79 | ret_no_quotes = [] 80 | for item in ret: 81 | if ((item[0] == "'" and item[-1] == "'") or 82 | (item[0] == '"' and item[-1] == '"')): 83 | ret_no_quotes.append(item[1:-1]) 84 | else: 85 | ret_no_quotes.append(item) 86 | return ret_no_quotes 87 | 88 | 89 | def parse_torrent_command(l): 90 | # Very permissive handling 91 | # Check for any occurances of c, d, f, p, t, m, or q 92 | cmd_code_match = re.search(r'([hdfpmtqc])', l, 93 | flags=re.IGNORECASE) 94 | if cmd_code_match: 95 | code = cmd_code_match.group(0).lower() 96 | else: 97 | code = None 98 | 99 | # Clean up command codes 100 | # Substitute multiple consecutive spaces/commas for single 101 | # comma remove anything that isn't an integer or comma. 102 | # Turn into list 103 | l = re.sub(r'^[hdfp, ]*|[hdfp, ]*$', '', l) 104 | l = re.sub('[ ,]+', ',', l) 105 | l = re.sub('[^0-9,-]', '', l) 106 | parsed_input = l.split(',') 107 | 108 | # expand ranges 109 | choices = [] 110 | # loop will generate a list of lists 111 | for elem in parsed_input: 112 | left, sep, right = elem.partition('-') 113 | if right: 114 | choices.append(list(range(int(left), int(right) + 1))) 115 | elif left != '': 116 | choices.append([int(left)]) 117 | 118 | # flatten list 119 | choices = sum(choices, []) 120 | # the current code stores the choices as strings 121 | # instead of ints. not sure if necessary 122 | choices = [elem for elem in choices] 123 | return code, choices 124 | 125 | 126 | def parse_args(args_in): 127 | parser = argparse.ArgumentParser( 128 | description='finds and downloads torrents from the Pirate Bay') 129 | parser.add_argument('-b', '--browse', 130 | action='store_true', 131 | help='display in Browse mode') 132 | parser.add_argument('search', 133 | nargs='*', help='term to search for') 134 | parser.add_argument('-c', '--category', 135 | help='specify a category to search', default='All') 136 | parser.add_argument('-s', '--sort', 137 | help='specify a sort option', default='SeedersDsc') 138 | parser.add_argument('-R', '--recent', 139 | action='store_true', 140 | help='torrents uploaded in the last 48hours. ' 141 | '*ignored in searches*') 142 | parser.add_argument('-l', '--list-categories', 143 | action='store_true', 144 | help='list categories') 145 | parser.add_argument('--list-sorts', '--list_sorts', 146 | action='store_true', 147 | help='list types by which results can be sorted') 148 | parser.add_argument('-p', '--pages', 149 | default=1, type=int, 150 | help='the number of pages to fetch. ' 151 | '(only used with --recent)') 152 | parser.add_argument('-r', '--total-results', 153 | type=int, 154 | help='maximum number of results to show') 155 | parser.add_argument('-L', '--local', dest='database', 156 | help='a csv file containing the Pirate Bay database ' 157 | 'downloaded from ' 158 | 'https://thepiratebay.org/static/dump/csv/') 159 | parser.add_argument('-0', dest='first', 160 | action='store_true', 161 | help='choose the top result') 162 | parser.add_argument('-a', '--download-all', 163 | action='store_true', 164 | help='download all results') 165 | parser.add_argument('-t', '--transmission', 166 | action='store_true', 167 | help='open magnets with transmission-remote') 168 | parser.add_argument('-E', '--transmission-endpoint', '--port', 169 | metavar='HOSTNAME:PORT', dest='endpoint', 170 | help='transmission-remote RPC endpoint. ' 171 | 'default is localhost:9091') 172 | parser.add_argument('-A', '--transmission-auth', '--auth', 173 | metavar='USER:PASSWORD', dest='auth', 174 | help='transmission-remote RPC authentication') 175 | parser.add_argument('-C', '--custom', dest='command', 176 | help='open magnets with a custom command' 177 | ' (%%s will be replaced with the url)') 178 | parser.add_argument('-M', '--save-magnets', 179 | action='store_true', 180 | help='save magnets links as files') 181 | parser.add_argument('-T', '--save-torrents', 182 | action='store_true', 183 | help='save torrent files') 184 | parser.add_argument('-S', '--save-directory', 185 | type=str, metavar='DIRECTORY', 186 | help='directory where to save downloaded files' 187 | ' (if none is given $PWD will be used)') 188 | parser.add_argument('--disable-colors', dest='disable_color', 189 | action='store_true', 190 | help='disable colored output') 191 | parser.add_argument('-m', '--mirror', 192 | type=str, nargs='+', 193 | help='the pirate bay mirror(s) to use') 194 | parser.add_argument('-z', '--timeout', type=int, 195 | help='timeout in seconds for http requests') 196 | parser.add_argument('-v', '--version', 197 | action='store_true', 198 | help='print pirate-get version number') 199 | parser.add_argument('-j', '--json', 200 | action='store_true', 201 | help='print results in JSON format to stdout') 202 | args = parser.parse_args(args_in) 203 | 204 | return args 205 | 206 | 207 | def combine_configs(config, args): 208 | # figure out the action - browse, search, top, etc. 209 | if args.browse: 210 | args.action = 'browse' 211 | elif args.recent: 212 | args.action = 'recent' 213 | elif args.list_categories: 214 | args.action = 'list_categories' 215 | elif args.list_sorts: 216 | args.action = 'list_sorts' 217 | elif len(args.search) == 0: 218 | args.action = 'top' 219 | else: 220 | args.action = 'search' 221 | 222 | args.source = 'tpb' 223 | if args.database or config.getboolean('LocalDB', 'enabled'): 224 | args.source = 'local_tpb' 225 | 226 | if not args.database: 227 | args.database = config.get('LocalDB', 'path') 228 | 229 | if args.disable_color or not config.getboolean('Misc', 'colors'): 230 | args.color = False 231 | else: 232 | args.color = True 233 | 234 | if not args.save_directory: 235 | args.save_directory = config.get('Save', 'directory') 236 | 237 | if not args.mirror: 238 | args.mirror = config.get('Misc', 'mirror').split() 239 | 240 | if not args.timeout: 241 | args.timeout = int(config.get('Misc', 'timeout')) 242 | 243 | config_total_results = int(config.get('Search', 'total-results')) 244 | if not args.total_results and config_total_results: 245 | args.total_results = config_total_results 246 | 247 | args.transmission_command = ['transmission-remote'] 248 | if args.endpoint: 249 | args.transmission_command.append(args.endpoint) 250 | elif config.get('Misc', 'transmission-endpoint'): 251 | args.transmission_command.append( 252 | config.get('Misc', 'transmission-endpoint')) 253 | # for backward compatibility 254 | elif config.get('Misc', 'transmission-port'): 255 | args.transmission_command.append( 256 | config.get('Misc', 'transmission-port')) 257 | if args.auth: 258 | args.transmission_command.append('--auth') 259 | args.transmission_command.append(args.auth) 260 | elif config.get('Misc', 'transmission-auth'): 261 | args.transmission_command.append('--auth') 262 | args.transmission_command.append( 263 | config.get('Misc', 'transmission-auth')) 264 | 265 | args.output = 'browser_open' 266 | if args.transmission or config.getboolean('Misc', 'transmission'): 267 | args.output = 'transmission' 268 | elif args.save_magnets or config.getboolean('Save', 'magnets'): 269 | args.output = 'save_magnet_files' 270 | elif args.save_torrents or config.getboolean('Save', 'torrents'): 271 | args.output = 'save_torrent_files' 272 | elif args.command or config.get('Misc', 'openCommand'): 273 | args.output = 'open_command' 274 | 275 | args.open_command = args.command 276 | if not args.open_command: 277 | args.open_command = config.get('Misc', 'openCommand') 278 | 279 | return args 280 | 281 | 282 | def connect_mirror(mirror, printer, args): 283 | try: 284 | printer.print('Trying', mirror, end='... ') 285 | url = pirate.torrent.find_api(mirror, args.timeout) 286 | results = pirate.torrent.remote( 287 | printer=printer, 288 | pages=args.pages, 289 | category=pirate.torrent.parse_category(printer, args.category), 290 | sort=pirate.torrent.parse_sort(printer, args.sort), 291 | mode=args.action, 292 | terms=args.search, 293 | mirror=url, 294 | timeout=args.timeout) 295 | except (urllib.error.URLError, socket.timeout, IOError, ValueError) as e: 296 | printer.print('Failed', color='WARN', end=' ') 297 | printer.print('(', e, ')', sep='') 298 | return None 299 | else: 300 | printer.print('Ok', color='alt') 301 | return results, mirror 302 | 303 | 304 | def search_mirrors(printer, args): 305 | # try default or user mirrors 306 | for mirror in args.mirror: 307 | result = connect_mirror(mirror, printer, args) 308 | if result is not None: 309 | return result 310 | 311 | # download mirror list 312 | try: 313 | req = request.Request(pirate.data.mirror_list, 314 | headers=pirate.data.default_headers) 315 | f = request.urlopen(req, timeout=args.timeout) 316 | except urllib.error.URLError as e: 317 | raise IOError('Could not fetch mirrors', e.reason) 318 | 319 | if f.getcode() != 200: 320 | raise IOError('The proxy bay responded with an error', 321 | f.read().decode('utf-8')) 322 | 323 | mirrors = [i.decode('utf-8').strip() for i in f.readlines()][3:] 324 | 325 | # try mirrors 326 | for mirror in mirrors: 327 | if mirror in pirate.data.blacklist: 328 | continue 329 | result = connect_mirror(mirror, printer, args) 330 | if result is not None: 331 | return result 332 | else: 333 | raise IOError('No more available mirrors') 334 | 335 | 336 | def pirate_main(args): 337 | printer = Printer(args.color) 338 | 339 | # browse mode needs a specific category 340 | if args.browse: 341 | if args.category == 'All' or args.category == 0: 342 | printer.print('You must select a specific category in browse mode.' 343 | ' ("All" is not valid)', color='ERROR') 344 | sys.exit(1) 345 | 346 | # print version 347 | if args.version: 348 | printer.print('pirate-get, version {}'.format(pirate.data.version)) 349 | sys.exit(0) 350 | 351 | # check it transmission is running 352 | if args.transmission: 353 | ret = subprocess.call(args.transmission_command + ['-l'], 354 | stdout=subprocess.DEVNULL, 355 | stderr=subprocess.DEVNULL) 356 | if ret != 0: 357 | printer.print('Transmission is not running.') 358 | sys.exit(1) 359 | 360 | # non-torrent fetching actions 361 | 362 | if args.action == 'list_categories': 363 | cur_color = 'zebra_0' 364 | for key, value in sorted(pirate.data.categories.items()): 365 | cur_color = 'zebra_0' if cur_color == 'zebra_1' else 'zebra_1' 366 | printer.print(str(value), '\t', key, sep='', color=cur_color) 367 | return 368 | 369 | if args.action == 'list_sorts': 370 | cur_color = 'zebra_0' 371 | for key, value in sorted(pirate.data.sorts.items()): 372 | cur_color = 'zebra_0' if cur_color == 'zebra_1' else 'zebra_1' 373 | printer.print(str(value[0]), '\t', key, sep='', color=cur_color) 374 | return 375 | 376 | # fetch torrents 377 | 378 | if args.source == 'local_tpb': 379 | if os.path.isfile(args.database): 380 | results = pirate.local.search(args.database, args.search) 381 | else: 382 | printer.print("Local pirate bay database doesn't exist.", 383 | '(%s)' % args.database, color='ERROR') 384 | sys.exit(1) 385 | elif args.source == 'tpb': 386 | try: 387 | results, site = search_mirrors(printer, args) 388 | except IOError as e: 389 | printer.print(e.args[0] + ' :( ', color='ERROR') 390 | if len(e.args) > 1: 391 | printer.print(e.args[1]) 392 | sys.exit(1) 393 | 394 | if len(results) == 0: 395 | printer.print('No results') 396 | return 397 | 398 | if args.json: 399 | print(json.dumps(results)) 400 | return 401 | else: 402 | # Results are sorted on the request, so it's safe to remove results here. 403 | if args.total_results: 404 | results = results[0:args.total_results] 405 | printer.search_results(results, local=args.source == 'local_tpb') 406 | 407 | # number of results to pick 408 | if args.first: 409 | printer.print('Choosing first result') 410 | choices = [0] 411 | elif args.download_all: 412 | printer.print('Downloading all results') 413 | choices = range(len(results)) 414 | else: 415 | # interactive loop for per-torrent actions 416 | while True: 417 | printer.print("\nSelect links (Type 'h' for more options" 418 | ", 'q' to quit)", end='\b', color='alt') 419 | try: 420 | cmd = builtins.input(': ') 421 | except (KeyboardInterrupt, EOFError): 422 | printer.print('\nCancelled.') 423 | return 424 | 425 | try: 426 | code, choices = parse_torrent_command(cmd) 427 | # Act on option, if supplied 428 | printer.print('') 429 | if code == 'h': 430 | printer.print('Options:', 431 | ': Download selected torrents', 432 | '[m]: Save magnets as files', 433 | '[c]: Copy magnets to clipboard', 434 | '[t]: Save .torrent files', 435 | '[d]: Get descriptions', 436 | '[f]: Get files', 437 | '[p] Print search results', 438 | '[q] Quit', sep='\n') 439 | elif code == 'q': 440 | printer.print('Bye.', color='alt') 441 | return 442 | elif code == 'd': 443 | printer.descriptions(choices, results, site, args.timeout) 444 | elif code == 'f': 445 | printer.file_lists(choices, results, site, args.timeout) 446 | elif code == 'p': 447 | printer.search_results(results) 448 | elif code == 'm': 449 | pirate.torrent.save_magnets(printer, choices, results, 450 | args.save_directory) 451 | elif code == 'c': 452 | pirate.torrent.copy_magnets(printer, choices, results) 453 | elif code == 't': 454 | pirate.torrent.save_torrents(printer, choices, results, 455 | args.save_directory, 456 | args.timeout) 457 | elif not cmd: 458 | printer.print('No links entered!', color='WARN') 459 | else: 460 | break 461 | except Exception as e: 462 | printer.print('Exception:', e, color='ERROR') 463 | return 464 | 465 | # output 466 | 467 | if args.output == 'save_magnet_files': 468 | printer.print('Saving selected magnets...') 469 | pirate.torrent.save_magnets(printer, choices, 470 | results, args.save_directory) 471 | return 472 | 473 | if args.output == 'save_torrent_files': 474 | printer.print('Saving selected torrents...') 475 | pirate.torrent.save_torrents(printer, choices, 476 | results, args.save_directory, 477 | args.timeout) 478 | return 479 | 480 | for choice in choices: 481 | url = results[choice]['magnet'] 482 | 483 | if args.output == 'transmission': 484 | subprocess.call(args.transmission_command + ['--add', url]) 485 | elif args.output == 'open_command': 486 | cmd = parse_cmd(args.open_command, url) 487 | printer.print(" ".join(cmd)) 488 | subprocess.call(cmd) 489 | elif args.output == 'browser_open': 490 | webbrowser.open(url) 491 | 492 | if args.output == 'transmission': 493 | subprocess.call(args.transmission_command + ['-l']) 494 | 495 | 496 | def main(): 497 | args = combine_configs(load_config(), parse_args(sys.argv[1:])) 498 | pirate_main(args) 499 | 500 | 501 | if __name__ == '__main__': 502 | main() 503 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------