astroport-iptubes/crawl.py

80 lines
2.0 KiB
Python
Executable File

#!/usr/bin/python3
################################################################################
# Author: Poka (poka@p2p.legal)
# Version: 0.0.2
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# Git: https://git.p2p.legal/axiom-team/astroport
################################################################################
# Config
tkdelay = 3
displayDetails = "true"
import requests
import json
import sys
import os
import subprocess
import login
import time
import re
# Load scraper
from yggcrawl import YggTorrentScraper
scraper = YggTorrentScraper(requests.session())
from yggtorrentscraper import set_yggtorrent_tld
set_yggtorrent_tld("se")
name = ' '.join(sys.argv[1:])
#research = os.system("./lib/scrabash.sh search --best=true " + name)
research = os.popen('./lib/scrabash.sh search --best=true ' + name).read()
#research = run(["./lib/scrabash.sh", "search", "--best-true"])
print(research)
try:
research.index("No torrent found")
except ValueError:
True
else:
sys.exit(1)
idTorrent = os.popen('./lib/scrabash.sh get_details ' + research).read()
dbPath = "./data/nfo/{}/db.py".format(idTorrent.rstrip())
torrentDB = os.popen('cat ' + dbPath).read()
print(torrentDB)
print("---")
torrentDBFile = open(dbPath, "r")
for line in torrentDBFile:
if re.search("Size", line):
fields = line.strip().split()
torrentSize = float(fields[2]) #kopa
diskSize = os.popen('./trans-ctl.sh checkdisk').read()
#print(diskSize)
diskEnd = float(diskSize) + torrentSize
if diskEnd >= 15:
print("You have filled the entire space allocated to torrents: " + diskSize)
sys.exit("Disk full")
# Download torrent file
if(scraper.login(login.user, login.passwd)):
print("Login success")
scraper.download_from_torrent_url(research)
else:
print("Login failed")
# Remove tracker
print("Start to remove tracker ...")
time.sleep(1)
print("Wait " + str(tkdelay) + " seconds to get peers before remove tracker...")
time.sleep(tkdelay)
subprocess.call(["./trans-ctl.sh", "rmtracker", name])
print("Done")