mirelconstantin / reddit-downloader

Download videos and images from a list of subreddit names using praw and reddit api.

Home Page:https://github.com/mirelconstantin/reddit-downloader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reddit Video and Image Downloader

This script uses the praw library to access the Reddit API and download videos and images from a list of subreddit names.

Python

LinkedIn Freelancer Upwork

βž• Dependencies

The following libraries are required to run this script:

  • praw: Used to access the Reddit API and retrieve posts from subreddits.
  • requests: Used to send HTTP requests to the Reddit API and download content from URLs.
  • os: Used to create directories and manipulate file paths.

πŸ“™ Downloading Videos and Images

The script iterates through each subreddit in the subreddit_names list and retrieves the last 25 hot posts from the subreddit. It creates a folder for the subreddit if it doesn't already exist, and then downloads and saves the videos and images from the posts.

For each post, the script checks the file extension of the url to determine if it's an image or a video. If it's an image, it downloads the content and saves it to the images folder for the subreddit. If it's a video, it retrieves the fallback_url from the media attribute and downloads the content, saving it to the videos folder for the subreddit. The file names are constructed using the post's upvotes and title, with any invalid characters in the title replaced with an underscore.

βš™οΈ Configuration

To customize the behavior of the script, you can modify the following variables:

  • client_id: The client ID provided to you by Reddit.
  • client_secret: The client secret provided to you by Reddit.
  • subreddit_names: A list of subreddit names that the script should download content from.

Running the Script

To run the script, ensure that the required dependencies are installed and then execute the script using a command line interface or a Python interpreter.

The downloaded videos and images will be saved to the appropriate folders in the current working directory.

pip install -m requirements.txt
python reddit.py

πŸ“ License

The MIT License (MIT)

Copyright Β© 2023 Mirel Constantin

About

Download videos and images from a list of subreddit names using praw and reddit api.

https://github.com/mirelconstantin/reddit-downloader


Languages

Language:Python 100.0%