-
Notifications
You must be signed in to change notification settings - Fork 0
/
Subreddit_Media_Downloader.py
67 lines (56 loc) · 2.22 KB
/
Subreddit_Media_Downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Title: Python - Download media from Subreddit
# Description: Download Media Posted to a Subreddit
# More info: https://alteredadmin.github.io/posts/python-download-media-from-subreddit/
# =====================================================
# Name: Altered Admin
# Website: https://alteredadmin.github.io/
# If you found this helpful Please consider:
# Buymeacoffee: http://buymeacoffee.com/alteredadmin
# BTC: bc1qhkw7kv9dtdk8xwvetreya2evjqtxn06cghyxt7
# LTC: ltc1q2mrh9s8sgmh8h5jtra3gqxuhvy04vuagpm3dk9
# ETH: 0xef053b0d936746Df00C9CCe0454b7b8afb1497ac
import praw
import datetime
import os.path
import subprocess
# Make sure to Fill in below API info
reddit = praw.Reddit(client_id='',
client_secret='',
user_agent='my user agent')
now = datetime.datetime.now()
subs = [""]
# here can you set what domains you want to download from.
# This list is short because there is not many external domains that get posted to reddit
imgs = ('https://i.redd.it', 'https://i.imgur.com')
vids = ('https://gfycat.com')
wd = os.path.join(os.environ.get("HOME"), "Downloads", "stuffs", '')
print()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)
print()
def img_getter(all):
try:
os.mkdir(path)
except OSError:
print("Creation of the directory %s failed or already exists" % path)
else:
print("Successfully created the directory %s" % path)
for post in all:
print(post.url)
if str(post.url).startswith(imgs):
try:
subprocess.run(["wget", "-nc", "-P", path, post.url])
except:
break
elif str(post.url).startswith(vids):
print("Found a Vid")
# subprocess.run(["youtube-dl", "-i", "-o", ytdl, post.url])
subprocess.run(["youtube-dl", "-i", "--playlist-end", "1", "-o", ytdl, post.url])
for sub in subs:
path = os.path.join(wd, sub, '')
ytdl = path + "%(title)s-%(id)s.%(ext)s"
print(sub)
print('Getting new')
img_getter(reddit.subreddit(sub).hot(limit=None))
img_getter(reddit.subreddit(sub).new(limit=None))
img_getter(reddit.subreddit(sub).top(limit=None))
img_getter(reddit.subreddit(sub).controversial(limit=None))