summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcomedyGenerator17
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!")