Gets media URLs from Reddit Submission using Python PRAW
Project description
Reddit Media Getter
Fetches media URLs from Reddit Submission using Python PRAW library and optionally downloads it. Supports video and single or gallery images. Can be used both as standalone package and library for Python scripts.
How to install
To use this package, you first have to install Python 3.7 or higher (versions below 3.7 are not supported). Then open your terminal and type following command to install the package from PyPI repository:
pip install reddit-media
This package uses Reddit API (using PRAW library) to fetch data from Reddit. However, Reddit API requires authentication for scripts that use it, so you will have to do some configuration beforehand. Specifically, it requires app Client ID and Client Secret. You can create both very easily:
- Follow following page: https://reddit.com/prefs/apps
- If you are not logged in into your Reddit account, you will be prompted to do so
- You will see 'authorized applications' page
- Scroll to the very bottom and press 'create another app...' button
- Select application type 'script'
- Enter any name and redirect URL you want (you will be able to change it later)
- Press 'create app' button. You will see your new app created
- Copy Client ID just under 'personal use script' text and name of the app
- Copy Client Secret next to 'secret' field
Note that credentials on the screenshot are only for demostrative purposes, they are invalid. For details about authenticating, check out this page: Authenticating via OAuth
Using as a library
If your Python script needs to get URLs of some Reddit submission, but you don't want to do it yourself, you can use this package to do it for you. Once you installed the package, you can just import it and use as any other library:
from praw import Reddit
from redditmedia import get_media, MediaType
submissions = Reddit(...).subreddit('aww').hot(limit=10) # First 10 submissions on r/aww
submissions_media = [get_media(submission) for submission in submissions]
for media_list in submissions_media:
for media in media_list:
if media.type in [MediaType.jpg, MediaType.png]: # Print only URLs of images
print(media.uri)
Using as standalone program
If you want to download bunch of media files from some reddit submissions, you can do this by using this package as standalone CLI program. You can do that typing something like this into terminal:
python -m redditmedia [IDS OF SUBMISSIONS SEPARATED WITH SPACE] -c [Client ID] [Client Secret]
This will download all media files from specified submissions into reddit-media-downloads
folder in current working directory. If you wish to change path of the folder where media should be downloaded to, you can specify it adding -p [PATH TO FOLDER]
at the end of the command above, or if you want submissions to have separate folders with their files, you can add -s
flag at the end of the command.
As you can see, this requires you to explicitly provide credentials as arguments every time you run the program. This is inconvenient if you use the program often. Instead you can create praw.ini
file inside your current working directory and paste this:
[redditmedia]
client_id=<Paste Client ID here>
client_secret=<Paste Client Secret here>
Now you can just provide IDs of submissions, and credidentials will be automatically picked up from the file:
python -m redditmedia [IDS OF SUBMISSIONS SEPARATED WITH SPACE]
You can do more things using this file, which are outside of the topic of this page. For details about
praw.ini
file, check out this page: praw.ini Files
Upcoming features
- Loading submissions from a file
- Easier credentials entering
- Add file size limit
- Save URLs into file
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for reddit_media-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f2faf844c87dc150276d77c77f0aba5c7c414c42ca48e80c73ad65c764cae8d |
|
MD5 | 771ddbdb394a8edb04cf2625b6edc784 |
|
BLAKE2b-256 | f103b5df8633b7e86ebcc3d53084b9e490eecbc018bdd9d3d9c6987fa4a94397 |