84 lines
1.9 KiB
Python
Executable File
84 lines
1.9 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# coding: utf-8
|
|
|
|
import requests
|
|
import json
|
|
import sys
|
|
import subprocess
|
|
import login
|
|
import time
|
|
import re
|
|
#import pyped
|
|
|
|
# Load scraper
|
|
try:
|
|
scraper
|
|
except NameError:
|
|
from yggcrawl import YggTorrentScraper
|
|
scraper = YggTorrentScraper(requests.session())
|
|
from yggcrawl import set_yggtorrent_tld
|
|
set_yggtorrent_tld("se")
|
|
|
|
cmd = sys.argv[1]
|
|
name = ' '.join(sys.argv[2:])
|
|
subcat = ""
|
|
|
|
def args():
|
|
parameter_dict = {}
|
|
for user_input in sys.argv[1:]:
|
|
if "=" not in user_input:
|
|
continue
|
|
else:
|
|
global name
|
|
name = name.replace(user_input, '')
|
|
|
|
varname = user_input.split("=")[0]
|
|
varvalue = user_input.split("=")[1]
|
|
parameter_dict[varname] = varvalue
|
|
|
|
if "--subcat" in parameter_dict:
|
|
global subcat
|
|
subcat = parameter_dict["--subcat"]
|
|
|
|
args()
|
|
|
|
# Search a torrent
|
|
def search(name=name):
|
|
# Give paramaters to scraper
|
|
parameters = {
|
|
"name": name,
|
|
"category": "films_&_videos",
|
|
"subcategory": subcat,
|
|
"sort": "seed",
|
|
"order": "desc"
|
|
}
|
|
|
|
# Execute scrapping
|
|
research = scraper.search(parameters)
|
|
|
|
# Check if not found
|
|
if research == []:
|
|
print("No torrent found with name: " + name)
|
|
sys.exit()
|
|
else:
|
|
print(json.dumps(research, indent=2))
|
|
|
|
# Get details of torrent
|
|
def get_details():
|
|
if(scraper.login(login.user, login.passwd)):
|
|
print("Login success")
|
|
# first_torrent = research[0]
|
|
first_torrent = name
|
|
details = scraper.extract_details(first_torrent)
|
|
print(details.__str__(files=True))
|
|
# re.findall('merci', details)
|
|
# subprocess.call(['/bin/grep', 'merci', ])
|
|
# print(details.__str__(files=True, comments=True))
|
|
else:
|
|
print("Login failed")
|
|
|
|
if cmd == "search":
|
|
search()
|
|
elif cmd == "get_details":
|
|
get_details()
|