diff options
-rwxr-xr-x | comedyGenerator | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/comedyGenerator b/comedyGenerator index 76bacb1..d9ae99d 100755 --- a/comedyGenerator +++ b/comedyGenerator @@ -11,6 +11,11 @@ import xdg import configparser import os +class Video: + def __init__(self, url, name): + self.url = url + self.name = name + config = configparser.ConfigParser() configdir = str(xdg.XDG_CONFIG_HOME) config.read(configdir + "/comedyGenerator") @@ -177,7 +182,7 @@ for tags in args.tags: while len(videos) < args.amount and len(JSONDump['items']) > 0: print("Currently have " + str(len(videos)) + " " + contentFilter + " out of " + str(args.amount) + " (" + str((len(videos)/args.amount)*100) + "%)") for item in range(len(JSONDump['items'])): - videos.append(JSONDump['items'][item]['url']) + videos.append( Video(JSONDump['items'][item]['url'], JSONDump['items'][item]['title']) ) for tries in range(100): try: tagPage = requests.get("https://ifunny.co/api/v1/feeds?filter=" + contentFilter + "&tag=" + tags + "&next=" + JSONDump['pagination']['next'], headers=requestHeader, cookies=requestCookies) @@ -195,13 +200,12 @@ for tags in args.tags: if args.verbose: print("Videos list truncated! Its now: " + str(len(videos)) + " units long") - def download(video): + def download(video, name): if args.verbose: print("Now running for " + str(video)) urlsplit = video.split('.') - name = tags + "-" + hashlib.md5(video.encode('utf-8')).hexdigest() + "." + urlsplit[len(urlsplit)-1] - outputPath = args.output + name + outputPath = args.output + tags + " - " + name + "." + urlsplit[len(urlsplit)-1] if args.verbose: print("name read as: " + name) if os.path.exists(outputPath): @@ -220,12 +224,12 @@ for tags in args.tags: if args.jobs > 1: pool = Pool(args.jobs) for video in videos: - pool.apply_async(download, (video,)) + pool.apply_async(download, (video.url, video.name,)) pool.close() pool.join() if logging: for video in videos: - logName = tags + "-" + hashlib.md5(video.encode('utf-8')).hexdigest() + ".mp4" + logName = video.url logPath = args.output + logName if args.verbose: print("Writing " + logPath + " to log file") @@ -233,7 +237,7 @@ for tags in args.tags: logFile.close() else: for video in videos: - download(video) + download(video.url, video.name) #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU Affero General Public License version 3 as published by #the Free Software Foundation. |