2020-06-02 00:05:02 +12:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
2021-02-25 22:32:06 +13:00
|
|
|
|
2020-06-02 00:05:02 +12:00
|
|
|
class Arguments:
|
|
|
|
@staticmethod
|
2021-02-25 22:32:06 +13:00
|
|
|
def parse(arguments=None):
|
2020-06-02 00:05:02 +12:00
|
|
|
"""Initialize argparse and add arguments"""
|
2021-02-25 22:32:06 +13:00
|
|
|
if arguments is None:
|
|
|
|
arguments = []
|
2020-06-02 00:05:02 +12:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(allow_abbrev=False,
|
2021-02-25 22:32:06 +13:00
|
|
|
description="This program downloads "
|
|
|
|
"media from reddit "
|
|
|
|
"posts")
|
|
|
|
parser.add_argument("--directory", "-d",
|
|
|
|
help="Specifies the directory where posts will be "
|
2020-06-02 00:05:02 +12:00
|
|
|
"downloaded to",
|
|
|
|
metavar="DIRECTORY")
|
2021-02-25 22:32:06 +13:00
|
|
|
|
|
|
|
parser.add_argument("--verbose", "-v",
|
2020-06-02 00:05:02 +12:00
|
|
|
help="Verbose Mode",
|
|
|
|
action="store_true",
|
|
|
|
default=False)
|
2021-02-25 22:32:06 +13:00
|
|
|
|
|
|
|
parser.add_argument("--quit", "-q",
|
2020-06-02 00:05:02 +12:00
|
|
|
help="Auto quit afer the process finishes",
|
|
|
|
action="store_true",
|
|
|
|
default=False)
|
|
|
|
|
2021-02-25 22:32:06 +13:00
|
|
|
parser.add_argument("--link", "-l",
|
2020-06-02 00:05:02 +12:00
|
|
|
help="Get posts from link",
|
|
|
|
metavar="link")
|
|
|
|
|
|
|
|
parser.add_argument("--saved",
|
|
|
|
action="store_true",
|
|
|
|
required="--unsave" in sys.argv,
|
|
|
|
help="Triggers saved mode")
|
|
|
|
|
|
|
|
parser.add_argument("--unsave",
|
|
|
|
action="store_true",
|
|
|
|
help="Unsaves downloaded posts")
|
|
|
|
|
|
|
|
parser.add_argument("--submitted",
|
|
|
|
action="store_true",
|
|
|
|
help="Gets posts of --user")
|
|
|
|
|
|
|
|
parser.add_argument("--upvoted",
|
|
|
|
action="store_true",
|
|
|
|
help="Gets upvoted posts of --user")
|
|
|
|
|
|
|
|
parser.add_argument("--log",
|
2021-02-25 22:32:06 +13:00
|
|
|
help="Takes a log file which created by itself "
|
|
|
|
"(json files), reads posts and tries downloadin"
|
|
|
|
"g them again.",
|
2020-06-02 00:05:02 +12:00
|
|
|
# type=argparse.FileType('r'),
|
|
|
|
metavar="LOG FILE")
|
|
|
|
|
2021-02-25 22:32:06 +13:00
|
|
|
parser.add_argument(
|
|
|
|
"--subreddit",
|
|
|
|
nargs="+",
|
|
|
|
help="Triggers subreddit mode and takes subreddit's "
|
|
|
|
"name without r/. use \"frontpage\" for frontpage",
|
|
|
|
metavar="SUBREDDIT",
|
|
|
|
type=str)
|
|
|
|
|
2020-06-02 00:05:02 +12:00
|
|
|
parser.add_argument("--multireddit",
|
2021-02-25 22:32:06 +13:00
|
|
|
help="Triggers multireddit mode and takes "
|
|
|
|
"multireddit's name without m/",
|
2020-06-02 00:05:02 +12:00
|
|
|
metavar="MULTIREDDIT",
|
|
|
|
type=str)
|
|
|
|
|
|
|
|
parser.add_argument("--user",
|
2021-02-25 22:32:06 +13:00
|
|
|
help="reddit username if needed. use \"me\" for "
|
|
|
|
"current user",
|
|
|
|
required="--multireddit" in sys.argv or
|
|
|
|
"--submitted" in sys.argv,
|
2020-06-02 00:05:02 +12:00
|
|
|
metavar="redditor",
|
|
|
|
type=str)
|
|
|
|
|
2021-02-25 22:32:06 +13:00
|
|
|
parser.add_argument(
|
|
|
|
"--search",
|
|
|
|
help="Searches for given query in given subreddits",
|
|
|
|
metavar="query",
|
|
|
|
type=str)
|
2020-06-02 00:05:02 +12:00
|
|
|
|
|
|
|
parser.add_argument("--sort",
|
2021-02-25 22:32:06 +13:00
|
|
|
help="Either hot, top, new, controversial, rising "
|
|
|
|
"or relevance default: hot",
|
2020-06-02 00:05:02 +12:00
|
|
|
choices=[
|
2021-02-25 22:32:06 +13:00
|
|
|
"hot", "top", "new", "controversial", "rising",
|
2020-06-02 00:05:02 +12:00
|
|
|
"relevance"
|
|
|
|
],
|
|
|
|
metavar="SORT TYPE",
|
|
|
|
type=str)
|
|
|
|
|
|
|
|
parser.add_argument("--limit",
|
|
|
|
help="default: unlimited",
|
|
|
|
metavar="Limit",
|
|
|
|
type=int)
|
|
|
|
|
|
|
|
parser.add_argument("--time",
|
2021-02-25 22:32:06 +13:00
|
|
|
help="Either hour, day, week, month, year or all."
|
|
|
|
" default: all",
|
|
|
|
choices=["all", "hour", "day",
|
|
|
|
"week", "month", "year"],
|
2020-06-02 00:05:02 +12:00
|
|
|
metavar="TIME_LIMIT",
|
|
|
|
type=str)
|
|
|
|
|
|
|
|
parser.add_argument("--skip",
|
2020-06-04 03:10:25 +12:00
|
|
|
nargs="+",
|
|
|
|
help="Skip posts with given type",
|
|
|
|
type=str,
|
2021-02-25 22:32:06 +13:00
|
|
|
choices=["images", "videos", "gifs", "self"],
|
|
|
|
default=[])
|
2020-06-04 03:10:25 +12:00
|
|
|
|
|
|
|
parser.add_argument("--skip-domain",
|
2020-06-02 00:05:02 +12:00
|
|
|
nargs="+",
|
|
|
|
help="Skip posts with given domain",
|
|
|
|
type=str,
|
2021-02-25 22:32:06 +13:00
|
|
|
default=[])
|
2020-06-02 00:05:02 +12:00
|
|
|
|
|
|
|
parser.add_argument("--set-folderpath",
|
|
|
|
action="store_true",
|
|
|
|
help="Set custom folderpath"
|
2021-02-25 22:32:06 +13:00
|
|
|
)
|
2020-06-02 00:05:02 +12:00
|
|
|
|
|
|
|
parser.add_argument("--set-filename",
|
|
|
|
action="store_true",
|
|
|
|
help="Set custom filename",
|
|
|
|
)
|
|
|
|
|
2021-02-25 22:32:06 +13:00
|
|
|
parser.add_argument(
|
|
|
|
"--set-default-directory",
|
|
|
|
action="store_true",
|
|
|
|
help="Set a default directory to be used in case no directory is given",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--set-default-options",
|
|
|
|
action="store_true",
|
|
|
|
help="Set default options to use everytime program runs",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--use-local-config",
|
|
|
|
action="store_true",
|
|
|
|
help="Creates a config file in the program's directory and uses it. Useful for having multiple configs",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--no-dupes",
|
|
|
|
action="store_true",
|
|
|
|
help="Do not download duplicate posts on different subreddits",
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--downloaded-posts",
|
|
|
|
help="Use a hash file to keep track of downloaded files",
|
|
|
|
type=str)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"--no-download",
|
|
|
|
action="store_true",
|
|
|
|
help="Just saved posts into a the POSTS.json file without downloading")
|
2020-06-02 00:05:02 +12:00
|
|
|
|
2021-03-26 23:04:22 +13:00
|
|
|
parser.add_argument(
|
|
|
|
"--download-delay",
|
|
|
|
metavar="DELAY",
|
|
|
|
type=int,
|
|
|
|
help="Amount, in seconds, to delay before beginning the next item in the download queue")
|
2021-03-27 22:28:23 +13:00
|
|
|
|
2020-06-02 00:05:02 +12:00
|
|
|
|
|
|
|
if arguments == []:
|
|
|
|
return parser.parse_args()
|
2021-02-25 22:32:06 +13:00
|
|
|
return parser.parse_args(arguments)
|