diff --git a/README.md b/README.md index 3d057ca..992dfd4 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,12 @@ This program downloads imgur, gfycat and direct image and video links of saved p ## What it can do - Can get posts from: frontpage, subreddits, multireddits, redditor's submissions, upvoted and saved posts; search results or just plain reddit links - Sorts posts by hot, top, new and so on -- Downloads imgur albums, gfycat links, [self posts](#how-do-i-open-self-post-files) and any link to a direct image +- Downloads **REDDIT** images and videos, **IMGUR** images and albums, **GFYCAT** links, **EROME** images and albums, **SELF POSTS** and any link to a direct image - Skips the existing ones - Puts post titles to file's name - Puts every post to its subreddit's folder - Saves a reusable copy of posts' details that are found so that they can be re-downloaded again - Logs failed ones in a file to so that you can try to download them later -- Can run with double-clicking on Windows ## [Download the latest release](https://github.com/aliparlakci/bulk-downloader-for-reddit/releases/latest) diff --git a/script.py b/script.py index fd97735..9749a26 100644 --- a/script.py +++ b/script.py @@ -427,17 +427,30 @@ def postExists(POST): """Figure out a file's name and checks if the file already exists""" title = nameCorrector(POST['postTitle']) - FILENAME = title + "_" + POST['postId'] + FILENAME = title + "_" + POST['postId'] + "_" + POST["postSubmitter"] PATH = GLOBAL.directory / POST["postSubreddit"] + possibleExtensions = [".jpg",".png",".mp4",".gif",".webm",".md"] - for i in range(2): - for extension in possibleExtensions: - FILE_PATH = PATH / (FILENAME+extension) - if FILE_PATH.exists(): - return True - else: - FILENAME = POST['postId'] + for extension in possibleExtensions: + + OLD_FILE_PATH = PATH / ( + title + + "_" + POST['postId'] + + extension + ) + FILE_PATH = PATH / ( + title + + "_" + POST['postId'] + + "_" + POST["postSubmitter"] + + extension + ) + + SHORT_FILE_PATH = PATH / (POST['postId']+extension) + + if OLD_FILE_PATH.exists() FILE_PATH.exists() or SHORT_FILE_PATH.exists(): + return True + else: return False diff --git a/src/downloader.py b/src/downloader.py index 705e259..da8d5b3 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -89,11 +89,12 @@ class Erome: title = nameCorrector(post['postTitle']) print(title+"_" +post['postId']+extension) - fileDir = title + "_" + post['postId'] + extension - fileDir = directory / fileDir - - tempDir = title + "_" + post['postId'] + '.tmp' - tempDir = directory / tempDir + fileDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+extension + ) + tempDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+".tmp" + ) imageURL = "https:" + IMAGES[0] @@ -108,7 +109,9 @@ class Erome: title = nameCorrector(post['postTitle']) print(title+"_"+post['postId'],end="\n\n") - folderDir = directory / (title+"_"+post['postId']) + folderDir = directory / ( + title + "_" + post["postSubmitter"] + "_" + post['postId'] + ) try: if not os.path.exists(folderDir): @@ -215,11 +218,20 @@ class Imgur: title = nameCorrector(post['postTitle']) print(title+"_" +post['postId']+post['postExt']) - fileDir = title + "_" + post['postId'] + post['postExt'] - fileDir = directory / fileDir + fileDir = directory / ( + title + + "_" + post["postSubmitter"] + + "_" + post['postId'] + + post['postExt'] + ) + + tempDir = directory / ( + title + + "_" + post["postSubmitter"] + + "_" + post['postId'] + + ".tmp" + ) - tempDir = title + "_" + post['postId'] + '.tmp' - tempDir = directory / tempDir try: getFile(fileDir,tempDir,post['mediaURL']) except FileNameTooLong: @@ -237,7 +249,9 @@ class Imgur: title = nameCorrector(post['postTitle']) print(title+"_"+post['postId'],end="\n\n") - folderDir = directory / (title+"_"+post['postId']) + folderDir = directory / ( + title + "_" + post["postSubmitter"] + "_" + post['postId'] + ) try: if not os.path.exists(folderDir): @@ -357,8 +371,13 @@ class Gfycat: title = nameCorrector(POST['postTitle']) print(title+"_"+POST['postId']+POST['postExt']) - fileDir = directory / (title+"_"+POST['postId']+POST['postExt']) - tempDir = directory / (title+"_"+POST['postId']+".tmp") + fileDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+POST['postExt'] + ) + tempDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+".tmp" + ) + try: getFile(fileDir,tempDir,POST['mediaURL']) except FileNameTooLong: @@ -406,11 +425,12 @@ class Direct: title = nameCorrector(POST['postTitle']) print(title+"_"+POST['postId']+POST['postExt']) - fileDir = title+"_"+POST['postId']+POST['postExt'] - fileDir = directory / fileDir - - tempDir = title+"_"+POST['postId']+".tmp" - tempDir = directory / tempDir + fileDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+POST['postExt'] + ) + tempDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+".tmp" + ) try: getFile(fileDir,tempDir,POST['postURL']) @@ -427,8 +447,9 @@ class Self: title = nameCorrector(post['postTitle']) print(title+"_"+post['postId']+".md") - fileDir = title+"_"+post['postId']+".md" - fileDir = directory / fileDir + fileDir = directory / ( + title+"_"+POST["postSubmitter"]+"_"+POST['postId']+".md" + ) if Path.is_file(fileDir): raise FileAlreadyExistsError