Skip to content

Added first user-fetch approach, https instead of http #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ See `./redditdl.py --help` for uptodate details.
ordering = ('key', )

redditdl.py [-h] [--multireddit] [--last l] [--score s] [--num n]
[--update] [--sfw] [--nsfw]
[--user] [--update] [--sfw] [--nsfw]
[--filename-format FILENAME_FORMAT] [--title-contain TEXT]
[--regex REGEX] [--verbose] [--skipAlbums]
[--mirror-gfycat] [--sort-type SORT_TYPE]
Expand All @@ -43,6 +43,8 @@ optional arguments:
-h, --help show this help message and exit
--multireddit Take multirredit instead of subreddit as input. If so,
provide /user/m/multireddit-name as argument
--user Take user instead of subreddit as input.
Please note that filters don't work with users yet.
--last l ID of the last downloaded file.
--score s Minimum score of images to download.
--num n Number of images to download.
Expand Down
17 changes: 10 additions & 7 deletions redditdownload/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from json import JSONDecoder


def getitems(subreddit, multireddit=False, previd='', reddit_sort=None):
def getitems(subreddit, multireddit=False, user=False, previd='', reddit_sort=None):
"""Return list of items from a subreddit.

:param subreddit: subreddit to load the post
Expand All @@ -16,14 +16,17 @@ def getitems(subreddit, multireddit=False, previd='', reddit_sort=None):
:returns: list -- list of post url
"""

if user:
url = 'https://www.reddit.com/user/%s/submitted.json' % subreddit

if multireddit:
if '/m/' not in subreddit:
warning = ('That doesn\'t look like a multireddit. Are you sure'
'you need that multireddit flag?')
print warning
sys.exit(1)
url = 'http://www.reddit.com/user/%s.json' % subreddit
if not multireddit:
url = 'https://www.reddit.com/user/%s.json' % subreddit
if not (multireddit or user):
if '/m/' in subreddit:
warning = ('It looks like you are trying to fetch a multireddit. \n'
'Check the multireddit flag. '
Expand All @@ -32,15 +35,15 @@ def getitems(subreddit, multireddit=False, previd='', reddit_sort=None):
sys.exit(1)
# no sorting needed
if reddit_sort is None:
url = 'http://www.reddit.com/r/{}.json'.format(subreddit)
url = 'https://www.reddit.com/r/{}.json'.format(subreddit)
# if sort is top or controversial, may include advanced sort (ie week, all etc)
elif 'top' in reddit_sort:
url = 'http://www.reddit.com/r/{}/{}.json'.format(subreddit, 'top')
url = 'https://www.reddit.com/r/{}/{}.json'.format(subreddit, 'top')
elif 'controversial' in reddit_sort:
url = 'http://www.reddit.com/r/{}/{}.json'.format(subreddit, 'controversial')
url = 'https://www.reddit.com/r/{}/{}.json'.format(subreddit, 'controversial')
# use default
else:
url = 'http://www.reddit.com/r/{}/{}.json'.format(subreddit, reddit_sort)
url = 'https://www.reddit.com/r/{}/{}.json'.format(subreddit, reddit_sort)

# Get items after item with 'id' of previd.

Expand Down
7 changes: 5 additions & 2 deletions redditdownload/redditdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,11 @@ def parse_args(args):
default=getcwd(), help='Dir to put downloaded files in.')
PARSER.add_argument('--multireddit', default=False, action='store_true',
required=False,
help='Take multirredit instead of subreddit as input.'
help='Take multireddit instead of subreddit as input.'
'If so, provide /user/m/multireddit-name as argument')
PARSER.add_argument('--user', default=False, action='store_true', required=False,
help='Take user instead of subreddit as input. '
'Please note that filters don\'t work with users yet.')
PARSER.add_argument('--last', metavar='l', default='', required=False,
help='ID of the last downloaded file.')
PARSER.add_argument('--score', metavar='s', default=0, type=int, required=False,
Expand Down Expand Up @@ -389,7 +392,7 @@ def main():

while not FINISHED:
ITEMS = getitems(
ARGS.reddit, multireddit=ARGS.multireddit, previd=LAST,
ARGS.reddit, multireddit=ARGS.multireddit, user=ARGS.user, previd=LAST,
reddit_sort=ARGS.sort_type)

# measure time and set the program to wait 4 second between request
Expand Down