From 1728196f23c660a07ddfd497297814cafb1ccc1b Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 3 Sep 2020 19:33:00 +0200 Subject: [PATCH] Don't curl if no url for image. Allow crawl url directly --- crawl.py | 20 ++++++++++++-------- lib/scrabash.sh | 5 ++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crawl.py b/crawl.py index 767cbda..11ffd04 100755 --- a/crawl.py +++ b/crawl.py @@ -23,6 +23,7 @@ import time import re from termcolor import colored from optparse import OptionParser +from urllib.parse import unquote # Load options parser = OptionParser() @@ -40,18 +41,21 @@ 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() +if ("https://" not in name): + name = re.sub(r'\w*-\w*', '', name) + research = os.popen('./lib/scrabash.sh search --best=true ' + name).read() -try: - research.index("No torrent found") -except ValueError: - True + try: + research.index("No torrent found") + except ValueError: + True + else: + print(colored('No torrent named "' + name + '" on YggTorrent', 'blue')) + sys.exit(1) else: - print(colored('No torrent named "' + name + '" on YggTorrent', 'blue')) - sys.exit(1) + research = unquote(name, errors='strict') # Allow only one torrent downling in same time, and remove oldest torrent if disk size is full. def rollingFiles(): diff --git a/lib/scrabash.sh b/lib/scrabash.sh index d2dbb2e..f83c242 100755 --- a/lib/scrabash.sh +++ b/lib/scrabash.sh @@ -51,8 +51,7 @@ get_details() { # Get image [[ ! -d img ]] && mkdir img && cd img url=$(wget -qO- -np -nd $name | awk -v RS=' ' '/.jpg/' | awk -F '"' '{ print $2 }' | head -n1) - curl -s -O $url - + [[ $url ]] && curl -s -O $url fi } @@ -65,6 +64,6 @@ vpn() { nordvpn c $vpn_citie } -$1 +$cmd [[ $err == 1 ]] && exit 1 || exit 0