From 78259f406ad2b3178f0d707c0f035c2eeec1e9b5 Mon Sep 17 00:00:00 2001 From: msglm Date: Wed, 11 Jan 2023 20:51:07 -0600 Subject: version 1.0 release --- comedyGenerator | 35 ++++++++++++++++++++++++++++++++++- requirements.txt | 4 ++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/comedyGenerator b/comedyGenerator index 410009c..af46cff 100755 --- a/comedyGenerator +++ b/comedyGenerator @@ -12,6 +12,13 @@ import hashlib parser = argparse.ArgumentParser(add_help=True) +parser.add_argument('--debug', + default=False, + action='store_true', + dest='debug', + help='Enables debug output' + ) + parser.add_argument('-js','-JS',"--Javascript",'--javascript', default=False, action='store_true', @@ -53,24 +60,38 @@ elif args.usingJavascript: print("using JS mode...") try: + if args.debug: + print("testing if firefox works...") from selenium.webdriver.firefox.options import Options firefox_options = Options() firefox_options.add_argument("--headless") driver = webdriver.Firefox(options=firefox_options) + if args.debug: + print("Firefox Works!") except: + if args.debug: + print("Firefox didn't work! Trying Chrome!") try: from selenium.webdriver.chrome.options import Options chrome_options = Options() - chrome_options.add_argument("--headless") + #chrome_options.add_argument("--headless") #TODO completely breaks script and screenshot shows a white screen and nothing but. likely got discovered. driver = webdriver.Chrome(options=chrome_options) + if args.debug: + print("Chrome Works!") except: + if args.debug: + print("Chrome Failed! Going to attempt an install of the firefox webdriver") try: from selenium.webdriver.firefox.options import Options firefox_options = Options() firefox_options.add_argument("--headless") driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=firefox_options) + if args.debug: + print("Install successful! using Firefox!") except: + if args.debug: + print("Install Failed! Trying Chrome webdriver install!") try: from selenium.webdriver.chrome.options import Options chrome_options = Options() @@ -82,9 +103,13 @@ elif args.usingJavascript: print("If you are using GNU/Linux, it is likely that you can install from your standard repos. Debian labels their chromium driver chromium-driver. If you wish to use an ungoogled version of chromium (as to reduce possiblity of spying), you can find a link to that here: https://github.com/Eloston/ungoogled-chromium#downloads. On Debian (or debian likes such as Ubuntu or Devuan), you may then run apt install ungoogled-chromium-driver and this will no longer fail.") sys.exit() for tags in args.tags: + if args.debug: + print("Downloading Tag: " + tags) for tries in range(100): try: driver.get('https://ifunny.co/tags/' + tags + '?filter=video') + if args.debug: + print("Got Webpage!") except: if tries < 100 - 1: print("Rate Limited! Sleeping for " + str(tries*1.5) + " seconds!") @@ -93,6 +118,8 @@ elif args.usingJavascript: break if args.amount > 0: + if args.debug: + print("starting to scroll...") isTimesScrolled = 0 oughtTimeScrolled = (args.amount/10) + 1 while isTimesScrolled < int(oughtTimeScrolled): @@ -102,9 +129,15 @@ elif args.usingJavascript: videos = driver.find_elements_by_tag_name("video") if args.amount > 0: videos = videos[:args.amount] + if args.debug: + print("Videos list truncated! Its now: " + str(len(videos)) + " units long") for video in videos: URL = video.get_attribute("data-src") + if args.debug: + print("URL read as: " + URL) name = tags + "-" + hashlib.md5(URL.encode('utf-8')).hexdigest() + ".mp4" + if args.debug: + print("name read as: " + name) print("saving " + video.get_attribute("data-src") + " as " + name) for tries in range(100): try: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6f555f5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +beautifulsoup4 +requests +selenium +urllib3 -- cgit v1.2.3