Add options mechanic, with option -s to keep tracker
This commit is contained in:
parent
d775952547
commit
adc8d8a2ec
43
crawl.py
43
crawl.py
|
@ -22,6 +22,17 @@ import login
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
from termcolor import colored
|
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
|
# Load scraper
|
||||||
from yggcrawl import YggTorrentScraper
|
from yggcrawl import YggTorrentScraper
|
||||||
|
@ -29,6 +40,7 @@ scraper = YggTorrentScraper(requests.session())
|
||||||
from yggtorrentscraper import set_yggtorrent_tld
|
from yggtorrentscraper import set_yggtorrent_tld
|
||||||
set_yggtorrent_tld("si")
|
set_yggtorrent_tld("si")
|
||||||
name = ' '.join(sys.argv[1:])
|
name = ' '.join(sys.argv[1:])
|
||||||
|
name = re.sub(r'\w*-\w*', '', name)
|
||||||
|
|
||||||
# Search torrent name
|
# Search torrent name
|
||||||
research = os.popen('./lib/scrabash.sh search --best=true ' + name).read()
|
research = os.popen('./lib/scrabash.sh search --best=true ' + name).read()
|
||||||
|
@ -38,6 +50,7 @@ try:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
True
|
True
|
||||||
else:
|
else:
|
||||||
|
print(colored('No torrent named "' + name + '" on YggTorrent', 'blue'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Allow only one torrent downling in same time, and remove oldest torrent if disk size is full.
|
# 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
|
# Download Torrent
|
||||||
def downloadTorrent():
|
def downloadTorrent():
|
||||||
# Download torrent file
|
# Download torrent file
|
||||||
if(scraper.login(login.user, login.passwd)):
|
if len(os.listdir('data/tmp/torrents') ) != 0:
|
||||||
print(colored("Login success", 'green'))
|
shutil.rmtree('data/tmp/torrents', ignore_errors=True)
|
||||||
if len(os.listdir('data/tmp/torrents') ) != 0:
|
os.mkdir("data/tmp/torrents")
|
||||||
shutil.rmtree('data/tmp/torrents', ignore_errors=True)
|
scraper.download_from_torrent_url(research)
|
||||||
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}.torrent && mv *.torrent ../../torrents/')
|
||||||
os.popen(f'cd data/tmp/torrents/ && mv *.torrent {idTorrent.strip()}.torrent && mv {idTorrent.strip()}.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
|
# Remove tracker
|
||||||
def removeTracker():
|
def removeTracker():
|
||||||
|
@ -125,10 +132,18 @@ def removeTracker():
|
||||||
time.sleep(tkdelay)
|
time.sleep(tkdelay)
|
||||||
os.popen('./trans-ctl.sh rmtracker ' + name)
|
os.popen('./trans-ctl.sh rmtracker ' + name)
|
||||||
os.popen('./trans-ctl.sh rmtracker ' + higherid)
|
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
|
# End
|
||||||
print(colored("Done", 'green'))
|
print(colored("Done", 'green'))
|
||||||
|
|
Loading…
Reference in New Issue