mirror of
https://github.com/KevinMidboe/bulk-downloader-for-reddit.git
synced 2026-01-11 11:45:36 +00:00
Compare commits
5 Commits
moreUseful
...
removeLink
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3d3d5fcd4 | ||
|
|
3a07c38f08 | ||
|
|
35e551f20c | ||
|
|
0f2bda9c34 | ||
|
|
8ab694bcc1 |
@@ -2,6 +2,8 @@
|
||||
|
||||
Downloads media from reddit posts. Made by [u/aliparlakci](https://reddit.com/u/aliparlakci)
|
||||
|
||||
## [Download the latest release here](https://github.com/aliparlakci/bulk-downloader-for-reddit/releases/latest)
|
||||
|
||||
## 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
|
||||
@@ -19,7 +21,7 @@ You can use it either as a `bulk-downloader-for-reddit.exe` executable file for
|
||||
|
||||
### Executables
|
||||
|
||||
For Windows and Linux, [download the latest release, here](https://github.com/aliparlakci/bulk-downloader-for-reddit/releases/latest).
|
||||
For Windows and Linux, [download the latest executables, here](https://github.com/aliparlakci/bulk-downloader-for-reddit/releases/latest).
|
||||
|
||||
### Python script
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Changes on *master*
|
||||
##[23/02/2019](https://github.com/aliparlakci/bulk-downloader-for-reddit/tree/4d385fda60028343be816eb7c4f7bc613a9d555d)
|
||||
## [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)
|
||||
@@ -83,4 +83,4 @@
|
||||
|
||||
## [10/07/2018](https://github.com/aliparlakci/bulk-downloader-for-reddit/tree/ffe3839aee6dc1a552d95154d817aefc2b66af81)
|
||||
- Added support for *self* post
|
||||
- Now getting posts is quicker
|
||||
- Now getting posts is quicker
|
||||
|
||||
20
script.py
20
script.py
@@ -16,7 +16,6 @@ from pathlib import Path, PurePath
|
||||
|
||||
from src.downloader import Direct, Erome, Gfycat, Imgur, Self
|
||||
from src.errors import *
|
||||
from src.parser import LinkDesigner
|
||||
from src.searcher import getPosts
|
||||
from src.tools import (GLOBAL, createLogFile, jsonFile, nameCorrector,
|
||||
printToFile)
|
||||
@@ -98,10 +97,6 @@ def parseArguments(arguments=[]):
|
||||
action="store_true",
|
||||
default=False)
|
||||
|
||||
parser.add_argument("--link","-l",
|
||||
help="Get posts from link",
|
||||
metavar="link")
|
||||
|
||||
parser.add_argument("--saved",
|
||||
action="store_true",
|
||||
help="Triggers saved mode")
|
||||
@@ -389,21 +384,6 @@ def prepareAttributes():
|
||||
else:
|
||||
ATTRIBUTES["time"] = "all"
|
||||
|
||||
if GLOBAL.arguments.link is not None:
|
||||
|
||||
GLOBAL.arguments.link = GLOBAL.arguments.link.strip("\"")
|
||||
|
||||
ATTRIBUTES = LinkDesigner(GLOBAL.arguments.link)
|
||||
|
||||
if GLOBAL.arguments.search is not None:
|
||||
ATTRIBUTES["search"] = GLOBAL.arguments.search
|
||||
|
||||
if GLOBAL.arguments.sort is not None:
|
||||
ATTRIBUTES["sort"] = GLOBAL.arguments.sort
|
||||
|
||||
if GLOBAL.arguments.time is not None:
|
||||
ATTRIBUTES["time"] = GLOBAL.arguments.time
|
||||
|
||||
elif GLOBAL.arguments.subreddit is not None:
|
||||
if type(GLOBAL.arguments.subreddit) == list:
|
||||
GLOBAL.arguments.subreddit = "+".join(GLOBAL.arguments.subreddit)
|
||||
|
||||
240
src/parser.py
240
src/parser.py
@@ -1,240 +0,0 @@
|
||||
from pprint import pprint
|
||||
|
||||
try:
|
||||
from src.errors import InvalidRedditLink
|
||||
except ModuleNotFoundError:
|
||||
from errors import InvalidRedditLink
|
||||
|
||||
def QueryParser(PassedQueries,index):
|
||||
ExtractedQueries = {}
|
||||
|
||||
QuestionMarkIndex = PassedQueries.index("?")
|
||||
Header = PassedQueries[:QuestionMarkIndex]
|
||||
ExtractedQueries["HEADER"] = Header
|
||||
Queries = PassedQueries[QuestionMarkIndex+1:]
|
||||
|
||||
ParsedQueries = Queries.split("&")
|
||||
|
||||
for Query in ParsedQueries:
|
||||
Query = Query.split("=")
|
||||
ExtractedQueries[Query[0]] = Query[1]
|
||||
|
||||
if ExtractedQueries["HEADER"] == "search":
|
||||
ExtractedQueries["q"] = ExtractedQueries["q"].replace("%20"," ")
|
||||
|
||||
return ExtractedQueries
|
||||
|
||||
def LinkParser(LINK):
|
||||
RESULT = {}
|
||||
ShortLink = False
|
||||
|
||||
if not "reddit.com" in LINK:
|
||||
raise InvalidRedditLink("Invalid reddit link")
|
||||
|
||||
SplittedLink = LINK.split("/")
|
||||
|
||||
if SplittedLink[0] == "https:" or SplittedLink[0] == "http:":
|
||||
SplittedLink = SplittedLink[2:]
|
||||
|
||||
try:
|
||||
if (SplittedLink[-2].endswith("reddit.com") and \
|
||||
SplittedLink[-1] == "") or \
|
||||
SplittedLink[-1].endswith("reddit.com"):
|
||||
|
||||
RESULT["sort"] = "best"
|
||||
return RESULT
|
||||
except IndexError:
|
||||
if SplittedLink[0].endswith("reddit.com"):
|
||||
RESULT["sort"] = "best"
|
||||
return RESULT
|
||||
|
||||
if "redd.it" in SplittedLink:
|
||||
ShortLink = True
|
||||
|
||||
if SplittedLink[0].endswith("reddit.com"):
|
||||
SplittedLink = SplittedLink[1:]
|
||||
|
||||
if "comments" in SplittedLink:
|
||||
RESULT = {"post":LINK}
|
||||
return RESULT
|
||||
|
||||
elif "me" in SplittedLink or \
|
||||
"u" in SplittedLink or \
|
||||
"user" in SplittedLink or \
|
||||
"r" in SplittedLink or \
|
||||
"m" in SplittedLink:
|
||||
|
||||
if "r" in SplittedLink:
|
||||
RESULT["subreddit"] = SplittedLink[SplittedLink.index("r") + 1]
|
||||
|
||||
elif "m" in SplittedLink:
|
||||
RESULT["multireddit"] = SplittedLink[SplittedLink.index("m") + 1]
|
||||
RESULT["user"] = SplittedLink[SplittedLink.index("m") - 1]
|
||||
|
||||
else:
|
||||
for index in range(len(SplittedLink)):
|
||||
if SplittedLink[index] == "u" or \
|
||||
SplittedLink[index] == "user":
|
||||
|
||||
RESULT["user"] = SplittedLink[index+1]
|
||||
|
||||
elif SplittedLink[index] == "me":
|
||||
RESULT["user"] = "me"
|
||||
|
||||
|
||||
for index in range(len(SplittedLink)):
|
||||
if SplittedLink[index] in [
|
||||
"hot","top","new","controversial","rising"
|
||||
]:
|
||||
|
||||
RESULT["sort"] = SplittedLink[index]
|
||||
|
||||
if index == 0:
|
||||
RESULT["subreddit"] = "frontpage"
|
||||
|
||||
elif SplittedLink[index] in ["submitted","saved","posts","upvoted"]:
|
||||
if SplittedLink[index] == "submitted" or \
|
||||
SplittedLink[index] == "posts":
|
||||
RESULT["submitted"] = {}
|
||||
|
||||
elif SplittedLink[index] == "saved":
|
||||
RESULT["saved"] = True
|
||||
|
||||
elif SplittedLink[index] == "upvoted":
|
||||
RESULT["upvoted"] = True
|
||||
|
||||
elif "?" in SplittedLink[index]:
|
||||
ParsedQuery = QueryParser(SplittedLink[index],index)
|
||||
if ParsedQuery["HEADER"] == "search":
|
||||
del ParsedQuery["HEADER"]
|
||||
RESULT["search"] = ParsedQuery
|
||||
|
||||
elif ParsedQuery["HEADER"] == "submitted" or \
|
||||
ParsedQuery["HEADER"] == "posts":
|
||||
del ParsedQuery["HEADER"]
|
||||
RESULT["submitted"] = ParsedQuery
|
||||
|
||||
else:
|
||||
del ParsedQuery["HEADER"]
|
||||
RESULT["queries"] = ParsedQuery
|
||||
|
||||
if not ("upvoted" in RESULT or \
|
||||
"saved" in RESULT or \
|
||||
"submitted" in RESULT or \
|
||||
"multireddit" in RESULT) and \
|
||||
"user" in RESULT:
|
||||
RESULT["submitted"] = {}
|
||||
|
||||
return RESULT
|
||||
|
||||
def LinkDesigner(LINK):
|
||||
|
||||
attributes = LinkParser(LINK)
|
||||
MODE = {}
|
||||
|
||||
if "post" in attributes:
|
||||
MODE["post"] = attributes["post"]
|
||||
MODE["sort"] = ""
|
||||
MODE["time"] = ""
|
||||
return MODE
|
||||
|
||||
elif "search" in attributes:
|
||||
MODE["search"] = attributes["search"]["q"]
|
||||
|
||||
if "restrict_sr" in attributes["search"]:
|
||||
|
||||
if not (attributes["search"]["restrict_sr"] == 0 or \
|
||||
attributes["search"]["restrict_sr"] == "off" or \
|
||||
attributes["search"]["restrict_sr"] == ""):
|
||||
|
||||
if "subreddit" in attributes:
|
||||
MODE["subreddit"] = attributes["subreddit"]
|
||||
elif "multireddit" in attributes:
|
||||
MODE["multreddit"] = attributes["multireddit"]
|
||||
MODE["user"] = attributes["user"]
|
||||
else:
|
||||
MODE["subreddit"] = "all"
|
||||
else:
|
||||
MODE["subreddit"] = "all"
|
||||
|
||||
if "t" in attributes["search"]:
|
||||
MODE["time"] = attributes["search"]["t"]
|
||||
else:
|
||||
MODE["time"] = "all"
|
||||
|
||||
if "sort" in attributes["search"]:
|
||||
MODE["sort"] = attributes["search"]["sort"]
|
||||
else:
|
||||
MODE["sort"] = "relevance"
|
||||
|
||||
if "include_over_18" in attributes["search"]:
|
||||
if attributes["search"]["include_over_18"] == 1 or \
|
||||
attributes["search"]["include_over_18"] == "on":
|
||||
MODE["nsfw"] = True
|
||||
else:
|
||||
MODE["nsfw"] = False
|
||||
|
||||
else:
|
||||
if "queries" in attributes:
|
||||
if not ("submitted" in attributes or \
|
||||
"posts" in attributes):
|
||||
|
||||
if "t" in attributes["queries"]:
|
||||
MODE["time"] = attributes["queries"]["t"]
|
||||
else:
|
||||
MODE["time"] = "day"
|
||||
else:
|
||||
if "t" in attributes["queries"]:
|
||||
MODE["time"] = attributes["queries"]["t"]
|
||||
else:
|
||||
MODE["time"] = "all"
|
||||
|
||||
if "sort" in attributes["queries"]:
|
||||
MODE["sort"] = attributes["queries"]["sort"]
|
||||
else:
|
||||
MODE["sort"] = "new"
|
||||
else:
|
||||
MODE["time"] = "day"
|
||||
|
||||
if "subreddit" in attributes and not "search" in attributes:
|
||||
MODE["subreddit"] = attributes["subreddit"]
|
||||
|
||||
elif "user" in attributes and not "search" in attributes:
|
||||
MODE["user"] = attributes["user"]
|
||||
|
||||
if "submitted" in attributes:
|
||||
MODE["submitted"] = True
|
||||
if "sort" in attributes["submitted"]:
|
||||
MODE["sort"] = attributes["submitted"]["sort"]
|
||||
elif "sort" in MODE:
|
||||
pass
|
||||
else:
|
||||
MODE["sort"] = "new"
|
||||
|
||||
if "t" in attributes["submitted"]:
|
||||
MODE["time"] = attributes["submitted"]["t"]
|
||||
else:
|
||||
MODE["time"] = "all"
|
||||
|
||||
elif "saved" in attributes:
|
||||
MODE["saved"] = True
|
||||
|
||||
elif "upvoted" in attributes:
|
||||
MODE["upvoted"] = True
|
||||
|
||||
elif "multireddit" in attributes:
|
||||
MODE["multireddit"] = attributes["multireddit"]
|
||||
|
||||
if "sort" in attributes:
|
||||
MODE["sort"] = attributes["sort"]
|
||||
elif "sort" in MODE:
|
||||
pass
|
||||
else:
|
||||
MODE["sort"] = "hot"
|
||||
|
||||
return MODE
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
link = input("> ")
|
||||
pprint(LinkDesigner(link))
|
||||
Reference in New Issue
Block a user