Ejemplo n.º 1
0
""" Reuben Thorpe (2016) Example of a simple search using apiTrawler."""

from kickass import api
from kickass import CATEGORY, FIELD, ORDER


"""
    Both methods below are valid ways to edit the defualt settings of an api()
    instance and are identical in there outputs. If no defualts are set,
    kickass will implent there own defualt settings.
"""

# Method 1

api_instance_1 = api("kat.al",
                    category=CATEGORY.APPLICATIONS,
                    field=FIELD.SIZE,
                    order=ORDER.ASC)

# Search instances inherit the settings of there perant api() instance.
ubuntu_search = api_instance_1.search("ubuntu")
debian_search = api_instance_1.search("debian")

# Edit setting for specific search instance
debian_search.field(FIELD.SEED)

for torrent in ubuntu_search.page(1):
    print(torrent["size"])


for torrent in debian_search.multipage(1, 4):
    print(torrent["title"])
Ejemplo n.º 2
0
#!/usr/bin/env python3
""" Reuben Thorpe (2016) Example of an advance search using kickass api."""

from kickass import api
from kickass import CATEGORY, FIELD, ORDER


# Create a new kat instance with a valid kick ass torrent domain.
kat = api("kat.al",
          category=CATEGORY.MOVIES,
          field=FIELD.SIZE,
          order=ORDER.DESC)


# Query "public domain" with user defined defualt settings
pdomain_search = kat.search("public domain")

# Set page request delay to half a second for the pdomain search instance
pdomain_search.delay(0.5)

# Display the title of torrents from page 1 through to 7 of the query "public domain"
for torrent in pdomain_search.multipage(1, 7):
    print(torrent["title"])

Ejemplo n.º 3
0
def list_torrents(media_type, query):
    """
    Parameters: Media type and a query.
    Returns: N/A.
    Desc: Main function that lists torrents matching supplied media type
          and query. User can select from list of torrents, page forward and
          back, or exit.
    """
    torrent_hrefs = []  # List containing urls to torrents.

    # Check for an avilable mirror.
    link = check_kats()
    if not link:
        exit()  # No mirrors available so exit.

    # Generate API object with link returned by check_kats.
    kat = api(link)

    if media_type:
        kat.category(media_type)

    torrent_search = kat.search(query)

    page = 1  # Start at page 1. Page 0 indicates exit.
    while page > 0:

         # Print a heading replacing doubles spaces with single.
        print(' '.join(('Top '
                        + media_type.upper()
                        + ' torrents - Page '
                        + str(page)).split()))
        print('|{0: ^5}|{1: <65}|{2: >9}|{3: >15}|{4: >10}|{5: >10}|'
              .format('No.', 'Name', 'Size', 'Age', 'Seeds', 'Leechers'))
        print('|{0:-<119}|'.format('-'))

        count = 0
        for torrent in torrent_search.page(page):
            torrent_date = datetime.strptime(torrent["pubDate"],
                                             '%A %d %b %Y %H:%M:%S %z')
            now = datetime.now()
            print('|{0: ^5}|{1: <65}|{2: >9}|{3: >15}|{4: >10}|{5: >10}|'
                  .format(count, torrent["title"][:60],
                          pretty_size(torrent["size"]),
                          timeago.format(
                              torrent_date.replace(tzinfo=None), now),
                          torrent["seeds"],
                          torrent["leechs"]))
            torrent_hrefs.append(torrent["link"])
            count += 1

        # Footer
        print('|{0:-<119}|'.format('-'))

        if page > 1:
            req_torrents = input('Enter torrent numbers to download, '
                                 '"e" to exit, "n" for next page, or '
                                 '"p" for previous page: ')
        else:
            req_torrents = input('Enter torrent numbers to download, '
                                 '"e" to exit, or "n" for next page: ')

        if 'e' in req_torrents.lower():  # Exit.
            page = 0
        elif 'n' in req_torrents.lower():  # Next page.
            page += 1
        elif 'p' in req_torrents.lower():  # Previous page.
            page = max(1, page - 1)
        else:  # Download torrents
            page = 0  # Exit after the torrents have been downloaded.
            if ',' in req_torrents:
                for x in req_torrents.split(','):
                    try:
                        i = int(x)
                    except:
                        print(x + " is an invalid torrent number - ignored!")
                        continue
                    if i >= 0 and i < count:
                        download_torrent(torrent_hrefs[i])
                    else:
                        print(x + " is an invalid torrent number - ignored!")
            else:
                try:
                    i = int(req_torrents)
                except:
                    print(req_torrents
                          + " is an invalid torrent number - ignored!")
                    continue
                if i >= 0 and i < count:
                    download_torrent(torrent_hrefs[i])
                else:
                    print(req_torrents
                          + " is an invalid torrent number - ignored!")