mirror of
https://github.com/KevinMidboe/bulk-downloader-for-reddit.git
synced 2025-10-29 17:40:15 +00:00
Exclude post types (#38)
* Added argument for excluded links * Added exclude in PromptUser() * Added functionality for exclude and bug fix
This commit is contained in:
42
script.py
42
script.py
@@ -143,6 +143,12 @@ def parseArguments(arguments=[]):
|
|||||||
" for downloading later",
|
" for downloading later",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False)
|
default=False)
|
||||||
|
|
||||||
|
parser.add_argument("--exclude",
|
||||||
|
nargs="+",
|
||||||
|
help="Do not download specified links",
|
||||||
|
choices=["imgur","gfycat","direct","self"],
|
||||||
|
type=str)
|
||||||
|
|
||||||
if arguments == []:
|
if arguments == []:
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
@@ -318,6 +324,32 @@ class PromptUser:
|
|||||||
if Path(GLOBAL.arguments.log ).is_file():
|
if Path(GLOBAL.arguments.log ).is_file():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
GLOBAL.arguments.exclude = []
|
||||||
|
|
||||||
|
sites = ["imgur","gfycat","direct","self"]
|
||||||
|
|
||||||
|
excludeInput = input("exclude: ").lower()
|
||||||
|
if excludeInput in sites and excludeInput != "":
|
||||||
|
GLOBAL.arguments.exclude = [excludeInput]
|
||||||
|
|
||||||
|
while not excludeInput == "":
|
||||||
|
while True:
|
||||||
|
excludeInput = input("exclude: ").lower()
|
||||||
|
if not excludeInput in sites or excludeInput in GLOBAL.arguments.exclude:
|
||||||
|
break
|
||||||
|
elif excludeInput == "":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
GLOBAL.arguments.exclude.append(excludeInput)
|
||||||
|
|
||||||
|
for i in range(len(GLOBAL.arguments.exclude)):
|
||||||
|
if " " in GLOBAL.arguments.exclude[i]:
|
||||||
|
inputWithWhitespace = GLOBAL.arguments.exclude[i]
|
||||||
|
del GLOBAL.arguments.exclude[i]
|
||||||
|
for siteInput in inputWithWhitespace.split():
|
||||||
|
if siteInput in sites and siteInput not in GLOBAL.arguments.exclude:
|
||||||
|
GLOBAL.arguments.exclude.append(siteInput)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
GLOBAL.arguments.limit = int(input("\nlimit (0 for none): "))
|
GLOBAL.arguments.limit = int(input("\nlimit (0 for none): "))
|
||||||
@@ -444,7 +476,7 @@ def download(submissions):
|
|||||||
downloadedCount = subsLenght
|
downloadedCount = subsLenght
|
||||||
duplicates = 0
|
duplicates = 0
|
||||||
BACKUP = {}
|
BACKUP = {}
|
||||||
|
ToBeDownloaded = GLOBAL.arguments.exclude
|
||||||
FAILED_FILE = createLogFile("FAILED")
|
FAILED_FILE = createLogFile("FAILED")
|
||||||
|
|
||||||
for i in range(subsLenght):
|
for i in range(subsLenght):
|
||||||
@@ -466,7 +498,7 @@ def download(submissions):
|
|||||||
|
|
||||||
directory = GLOBAL.directory / submissions[i]['postSubreddit']
|
directory = GLOBAL.directory / submissions[i]['postSubreddit']
|
||||||
|
|
||||||
if submissions[i]['postType'] == 'imgur':
|
if submissions[i]['postType'] == 'imgur' and not 'imgur' in ToBeDownloaded:
|
||||||
print("IMGUR",end="")
|
print("IMGUR",end="")
|
||||||
|
|
||||||
while int(time.time() - lastRequestTime) <= 2:
|
while int(time.time() - lastRequestTime) <= 2:
|
||||||
@@ -529,7 +561,7 @@ def download(submissions):
|
|||||||
)
|
)
|
||||||
downloadedCount -= 1
|
downloadedCount -= 1
|
||||||
|
|
||||||
elif submissions[i]['postType'] == 'gfycat':
|
elif submissions[i]['postType'] == 'gfycat' and not 'gfycat' in ToBeDownloaded:
|
||||||
print("GFYCAT")
|
print("GFYCAT")
|
||||||
try:
|
try:
|
||||||
Gfycat(directory,submissions[i])
|
Gfycat(directory,submissions[i])
|
||||||
@@ -549,7 +581,7 @@ def download(submissions):
|
|||||||
FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
|
FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
|
||||||
downloadedCount -= 1
|
downloadedCount -= 1
|
||||||
|
|
||||||
elif submissions[i]['postType'] == 'direct':
|
elif submissions[i]['postType'] == 'direct' and not 'direct' in ToBeDownloaded:
|
||||||
print("DIRECT")
|
print("DIRECT")
|
||||||
try:
|
try:
|
||||||
Direct(directory,submissions[i])
|
Direct(directory,submissions[i])
|
||||||
@@ -564,7 +596,7 @@ def download(submissions):
|
|||||||
FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
|
FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]})
|
||||||
downloadedCount -= 1
|
downloadedCount -= 1
|
||||||
|
|
||||||
elif submissions[i]['postType'] == 'self':
|
elif submissions[i]['postType'] == 'self' and not 'self' in ToBeDownloaded:
|
||||||
print("SELF")
|
print("SELF")
|
||||||
try:
|
try:
|
||||||
Self(directory,submissions[i])
|
Self(directory,submissions[i])
|
||||||
|
|||||||
Reference in New Issue
Block a user