From 4d385fda60028343be816eb7c4f7bc613a9d555d Mon Sep 17 00:00:00 2001 From: Ali Date: Fri, 22 Feb 2019 23:59:03 +0300 Subject: [PATCH 1/4] Fixed v.redd.it links --- src/searcher.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/searcher.py b/src/searcher.py index c4ef223..31ba755 100644 --- a/src/searcher.py +++ b/src/searcher.py @@ -3,6 +3,8 @@ import sys import random import socket import webbrowser +import urllib.request +from urllib.error import HTTPError import praw from prawcore.exceptions import NotFound, ResponseException, Forbidden @@ -422,18 +424,20 @@ def checkIfMatching(submission): eromeCount += 1 return details - elif isDirectLink(submission.url) is not False: - details['postType'] = 'direct' - details['postURL'] = isDirectLink(submission.url) - directCount += 1 - return details - elif submission.is_self: details['postType'] = 'self' details['postContent'] = submission.selftext selfCount += 1 return details + directLink = isDirectLink(submission.url) + + if directLink is not False: + details['postType'] = 'direct' + details['postURL'] = directLink + directCount += 1 + return details + def printSubmission(SUB,validNumber,totalNumber): """Print post's link, title and media link to screen""" @@ -473,7 +477,22 @@ def isDirectLink(URL): return URL elif "v.redd.it" in URL: - return URL+"/DASH_600_K" + bitrates = ["DASH_1080","DASH_720","DASH_600", \ + "DASH_480","DASH_360","DASH_240"] + + for bitrate in bitrates: + videoURL = URL+"/"+bitrate + + try: + responseCode = urllib.request.urlopen(videoURL).getcode() + except urllib.error.HTTPError: + responseCode = 0 + + if responseCode == 200: + return videoURL + + else: + return False for extension in imageTypes: if extension in URL: From 92e47adb43b6ec32ecad979903e99bf123667951 Mon Sep 17 00:00:00 2001 From: Ali Date: Fri, 22 Feb 2019 23:59:57 +0300 Subject: [PATCH 2/4] Update version --- script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.py b/script.py index a8a0568..7b59350 100644 --- a/script.py +++ b/script.py @@ -23,7 +23,7 @@ from src.tools import (GLOBAL, createLogFile, jsonFile, nameCorrector, __author__ = "Ali Parlakci" __license__ = "GPL" -__version__ = "1.6.4.1" +__version__ = "1.6.4.2" __maintainer__ = "Ali Parlakci" __email__ = "parlakciali@gmail.com" From 344201a70d633a080893ebc7727769b33e4be82b Mon Sep 17 00:00:00 2001 From: Ali Date: Sat, 23 Feb 2019 00:01:39 +0300 Subject: [PATCH 3/4] Fixed v.redd.it links --- docs/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index afabd2e..98aff4d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,4 +1,7 @@ # Changes on *master* +##[23/02/2019](https://github.com/aliparlakci/bulk-downloader-for-reddit/tree/4d385fda60028343be816eb7c4f7bc613a9d555d) +- Fixed v.redd.it links + ## [27/01/2019](https://github.com/aliparlakci/bulk-downloader-for-reddit/tree/b7baf07fb5998368d87e3c4c36aed40daf820609) - Clarified the instructions From 15a91e578496e1c07b5302606fab6061733eb1a1 Mon Sep 17 00:00:00 2001 From: Ali Date: Sun, 24 Feb 2019 12:28:40 +0300 Subject: [PATCH 4/4] Fixed saving auth info problem --- script.py | 7 +++++-- src/searcher.py | 4 ++-- src/tools.py | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/script.py b/script.py index 7b59350..6fea859 100644 --- a/script.py +++ b/script.py @@ -674,8 +674,11 @@ def main(): if not Path(GLOBAL.configDirectory).is_dir(): os.makedirs(GLOBAL.configDirectory) - GLOBAL.config = getConfig("config.json") if Path("config.json").exists() \ - else getConfig(GLOBAL.configDirectory / "config.json") + + GLOBAL.configDirectory = Path("config.json") if Path("config.json").exists() \ + else GLOBAL.defaultConfigDirectory / "config.json" + + GLOBAL.config = getConfig(GLOBAL.configDirectory) if GLOBAL.arguments.log is not None: logDir = Path(GLOBAL.arguments.log) diff --git a/src/searcher.py b/src/searcher.py index 31ba755..5fa4626 100644 --- a/src/searcher.py +++ b/src/searcher.py @@ -95,7 +95,7 @@ def beginPraw(config,user_agent = str(socket.gethostname())): authorizedInstance = GetAuth(reddit,port).getRefreshToken(*scopes) reddit = authorizedInstance[0] refresh_token = authorizedInstance[1] - jsonFile(GLOBAL.configDirectory / "config.json").add({ + jsonFile(GLOBAL.configDirectory).add({ "reddit_username":str(reddit.user.me()), "reddit_refresh_token":refresh_token }) @@ -105,7 +105,7 @@ def beginPraw(config,user_agent = str(socket.gethostname())): authorizedInstance = GetAuth(reddit,port).getRefreshToken(*scopes) reddit = authorizedInstance[0] refresh_token = authorizedInstance[1] - jsonFile(GLOBAL.configDirectory / "config.json").add({ + jsonFile(GLOBAL.configDirectory).add({ "reddit_username":str(reddit.user.me()), "reddit_refresh_token":refresh_token }) diff --git a/src/tools.py b/src/tools.py index 88d6d89..7299f0f 100644 --- a/src/tools.py +++ b/src/tools.py @@ -14,7 +14,8 @@ class GLOBAL: config = None arguments = None directory = None - configDirectory = Path.home() / "Bulk Downloader for Reddit" + defaultConfigDirectory = Path.home() / "Bulk Downloader for Reddit" + configDirectory = "" reddit_client_id = "BSyphDdxYZAgVQ" reddit_client_secret = "bfqNJaRh8NMh-9eAr-t4TRz-Blk" printVanilla = print