From adc8d8a2ec154680e4dc1a048ec1d64b3f0eaf87 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 30 Aug 2020 17:58:50 +0200 Subject: [PATCH] Add options mechanic, with option -s to keep tracker --- crawl.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/crawl.py b/crawl.py index ee0e5f0..767cbda 100755 --- a/crawl.py +++ b/crawl.py @@ -22,6 +22,17 @@ import login import time import re from termcolor import colored +from optparse import OptionParser + +# Load options +parser = OptionParser() +parser.add_option("-s", "--seed", action="store_false", dest="rmTracker", default=True, + help="Keep the tracker for this torrent. So ratio is supported.") +parser.add_option("-q", "--quiet", + action="store_false", dest="verbose", default=True, + help="don't print status messages to stdout") +(options, args) = parser.parse_args() + # Load scraper from yggcrawl import YggTorrentScraper @@ -29,6 +40,7 @@ scraper = YggTorrentScraper(requests.session()) from yggtorrentscraper import set_yggtorrent_tld set_yggtorrent_tld("si") name = ' '.join(sys.argv[1:]) + name = re.sub(r'\w*-\w*', '', name) # Search torrent name research = os.popen('./lib/scrabash.sh search --best=true ' + name).read() @@ -38,6 +50,7 @@ try: except ValueError: True else: + print(colored('No torrent named "' + name + '" on YggTorrent', 'blue')) sys.exit(1) # Allow only one torrent downling in same time, and remove oldest torrent if disk size is full. @@ -103,18 +116,12 @@ def rollingFiles(): # Download Torrent def downloadTorrent(): # Download torrent file - if(scraper.login(login.user, login.passwd)): - print(colored("Login success", 'green')) - if len(os.listdir('data/tmp/torrents') ) != 0: - shutil.rmtree('data/tmp/torrents', ignore_errors=True) - os.mkdir("data/tmp/torrents") - scraper.download_from_torrent_url(research) + if len(os.listdir('data/tmp/torrents') ) != 0: + shutil.rmtree('data/tmp/torrents', ignore_errors=True) + os.mkdir("data/tmp/torrents") + scraper.download_from_torrent_url(research) # os.popen(f'cd data/tmp/torrents/ && mv *.torrent {idTorrent}.torrent && mv *.torrent ../../torrents/') - os.popen(f'cd data/tmp/torrents/ && mv *.torrent {idTorrent.strip()}.torrent && mv {idTorrent.strip()}.torrent ../../torrents/') - - else: - print(colored("Login failed", 'red')) - sys.exit(1) + os.popen(f'cd data/tmp/torrents/ && mv *.torrent {idTorrent.strip()}.torrent && mv {idTorrent.strip()}.torrent ../../torrents/') # Remove tracker def removeTracker(): @@ -125,10 +132,18 @@ def removeTracker(): time.sleep(tkdelay) os.popen('./trans-ctl.sh rmtracker ' + name) os.popen('./trans-ctl.sh rmtracker ' + higherid) + os.replace(f'data/torrents/{idTorrent.strip()}.torrent.added', f'data/meta/{idTorrent.strip()}/{idTorrent.strip()}.torrent') + + +if(scraper.login(login.user, login.passwd)): #Check if user can login + print(colored("Login success", 'green')) + rollingFiles() + downloadTorrent() + removeTracker() if options.rmTracker else None +else: + print(colored("Login failed", 'red')) + sys.exit(1) -rollingFiles() -downloadTorrent() -removeTracker() # End print(colored("Done", 'green'))