diff options
author | msglm <msglm@techchud.xyz> | 2023-01-11 20:51:07 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-11 20:51:07 -0600 |
commit | 6e82297298f08d332c8ce267533c8a30f8efc66b (patch) | |
tree | cef56f44913fcac2af8938c0b61f9a89a8a5dc3b | |
parent | b3f9a2d5fb59b9ef45f9d94b16b816e56dcb7a7d (diff) | |
download | comedyGenerator-6e82297298f08d332c8ce267533c8a30f8efc66b.tar.gz comedyGenerator-6e82297298f08d332c8ce267533c8a30f8efc66b.tar.bz2 comedyGenerator-6e82297298f08d332c8ce267533c8a30f8efc66b.zip |
naming process is no longer cancer
-rwxr-xr-x | comedyGenerator | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/comedyGenerator b/comedyGenerator index c64044e..54924e5 100755 --- a/comedyGenerator +++ b/comedyGenerator @@ -6,6 +6,9 @@ import sys import os import argparse import time +import hashlib + + parser = argparse.ArgumentParser(add_help=True) @@ -39,13 +42,12 @@ if not args.usingJavascript: URL = requests.get('https://ifunny.co/tags/' + tags + '?filter=video') webpage = BeautifulSoup(URL.content, 'html.parser') videos = webpage.findAll('video') - epoch = len([item for item in os.listdir('/home/'+ os.environ['USER'] + '/Videos/unsorted/')]) if args.amount > 0: videos = video[:arg.amount] for video in videos: - epoch = epoch + 1 - print("saving " + video['data-src'] + " as " + str(epoch) + '.mp4') - urllib.request.urlretrieve(video['data-src'], '/home/' + os.environ['USER'] + '/Videos/unsorted/' + str(epoch) + '.mp4') + name = tags + "-" + hashlib.md5(video.encode('utf-8')).hexdigest() + ".mp4" + print("saving " + video['data-src'] + " as " + name) + urllib.request.urlretrieve(video['data-src'], '/home/' + os.environ['USER'] + '/Videos/unsorted/' + name) elif args.usingJavascript: from selenium import webdriver print("using JS mode...") @@ -100,13 +102,12 @@ elif args.usingJavascript: videos = driver.find_elements_by_tag_name("video") if args.amount > 0: videos = videos[:args.amount] - epoch = len([item for item in os.listdir('/home/'+ os.environ['USER'] + '/Videos/unsorted/')]) for video in videos: - epoch = epoch + 1 - print("saving " + video.get_attribute("data-src") + " as " + str(epoch) + '.mp4') + name = tags + "-" + hashlib.md5(video.encode('utf-8')).hexdigest() + ".mp4" + print("saving " + video['data-src'] + " as " + name) for tries in range(100): try: - urllib.request.urlretrieve(video.get_attribute("data-src"), '/home/' + os.environ['USER'] + '/Videos/unsorted/' + str(epoch) + '.mp4') + urllib.request.urlretrieve(video.get_attribute("data-src"), '/home/' + os.environ['USER'] + '/Videos/unsorted/' + name) except: if tries < 100 - 1: print("Rate Limited! Sleeping for " + str(tries*1.5) + " seconds!") |