#!/usr/bin/env python3 __usage__ = """ usage: torrenttags [-h] [--html] hash positional arguments: hash Torrent hash to look up optional arguments: -h, --help show this help message and exit --html Prints html response to stdout, includes Chilling Effects reports if available """ from requests import get from random import choice from bs4 import BeautifulSoup as Soup from argparse import ArgumentParser from sys import exit, stderr urls = ["http://api1.torrenttags.com/v1/", "http://api2.torrenttags.com/v1/", "http://api3.torrenttags.com/v1/"] def get_api_url(method=None): return choice(urls) + method def get_ticket(): data = get(get_api_url("get-ticket")).json() return data["status"], data["ticket"] def get_result(hash, ticket=None): if not ticket: ticket = get_ticket() if len(hash) != 40: return False data = Soup(get(get_api_url("get-tags-html"), params={'ticket': ticket, 'torrent': hash}).json()["html"], "html.parser") if "no_claims" in data.find('img')["src"]: return True return False def main(): parser = ArgumentParser() parser.add_argument("hash", help="Torrent hash to look up") args = parser.parse_args() if get_result(args.hash): return "No claims (yet!)", 0 else: return "Claims found", 2 if __name__ == "__main__": outp, ret = main() print(outp, file=stderr) exit(ret)