Skip to content

Instantly share code, notes, and snippets.

@ArjixWasTaken
Last active February 4, 2021 10:40
Show Gist options
  • Save ArjixWasTaken/09a0cda12e9773b71d8ecaaf46f068ea to your computer and use it in GitHub Desktop.
Save ArjixWasTaken/09a0cda12e9773b71d8ecaaf46f068ea to your computer and use it in GitHub Desktop.
This is an example usage of https://github.com/ArjixGamer/YifyAPI
# This is a wrapper for my API that scrapes Yify (yts.mx)
# Import the API
from YifyAPI.yify import search_yify as search # pip install YifyAPI
# Import the table
from tabulate import tabulate # pip install tabulate
# Import other utilities
import click, os # pip install click
get_results = search(input('Please enter a movie name: '))
get_results = sorted(get_results, key=lambda a_entry: a_entry['year'])
count = -1
table = []
for a in get_results:
count += 1
entry = [count, a['title'], a['year']]
table.append(entry)
click.clear()
headers = ['SlNo', "Title", "Year"]
table = tabulate(table, headers, tablefmt='psql')
table = '\n'.join(table.split('\n')[::-1])
click.echo(table)
val = click.prompt('Choose a movie: ', default=0, type=int)
choice = get_results[val]
qualities = choice['qualities']
for a in qualities:
if 'GB' in a[1]:
a[1] = str(int(round(float(a[1].replace('GB', '').strip()) * 1000))) + 'GB'
elif 'MB' in a[1]:
a[1] = str(round(float(a[1].replace('MB', '').strip()))) + 'MB'
qualities = sorted(qualities, key=lambda a_entry: int(a_entry[1].replace('MB', '').replace('GB', '').strip()))
title = choice['title']
click.clear()
click.echo(f'Chosen {title}!')
magnets = [x[2] for x in qualities]
table = []
count = -1
for a in qualities:
count += 1
quality = a[0].split('.')[0]
type_ = a[0].split('.')[1]
entry = [count, quality, a[1] + ' | ' + type_ if not 'GB' in a[1] else str(float(a[1].replace('GB', '').strip())/1000) + 'GB' + ' | ' + type_ ]
table.append(entry)
headers = ['SlNo', 'Quality', 'Metadata']
table = tabulate(table, headers, tablefmt='psql')
table = '\n'.join(table.split('\n')[::-1])
click.echo(table)
val = click.prompt('Choose a quality: ', default=0, type=int)
choice = magnets[val]
os.startfile(choice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment