Add options mechanic, with option -s to keep tracker
This commit is contained in:
parent
d775952547
commit
adc8d8a2ec
33
crawl.py
33
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,8 +116,6 @@ 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")
|
||||
|
@ -112,10 +123,6 @@ def downloadTorrent():
|
|||
# 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)
|
||||
|
||||
# Remove tracker
|
||||
def removeTracker():
|
||||
print(colored("Start to remove tracker ...", 'yellow'))
|
||||
|
@ -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'))
|
||||
|
|
Loading…
Reference in New Issue