Giter Club home page Giter Club logo

reddit-image-fetcher's Introduction

Reddit Image Fetcher

Reddit Image Fetcher

A JavaScript package for fetching reddit images, memes, wallpapers and more.


Preview
Shadow

Reddit Image Fetcher is a JavaScript package that can fetch bulk images, memes or wallpapers. Supports node, react and other any JavaScript language.

  • Bulk images
  • Bulk memes
  • Bulk wallpapers
  • Customizable
  • Lightweight <20KB

PHP version: Reddit Image Fetcher

Resources

Installation

Install via NPM

npm install reddit-image-fetcher

Install via Yarn

yarn add reddit-image-fetcher

Usage

const RedditImageFetcher = require('reddit-image-fetcher');

// fetch 1 meme
RedditImageFetcher.fetch({
  type: 'meme',
}).then((result) => {
  console.log(result);
});

// fetch 1 wallpaper
RedditImageFetcher.fetch({
  type: 'wallpaper',
}).then((result) => {
  console.log(result);
});

// fetch 50 wallpapers
RedditImageFetcher.fetch({
  type: 'wallpaper',
  total: 50,
}).then((result) => {
  console.log(result);
});

// fetch 50 cat images from custom subreddit library
RedditImageFetcher.fetch({
  type: 'custom',
  total: 50,
  subreddit: ['cats', 'Catswhoyell', 'sleepingcats'],
}).then((result) => {
  console.log(result);
});

// fetch 50 memes by adding two subreddits and removing 1 subreddit from default subreddit library
RedditImageFetcher.fetch({
  type: 'custom',
  total: 50,
  addSubreddit: ['memes', 'funny'],
  removeSubreddit: ['dankmemes'],
}).then((result) => {
  console.log(result);
});

Sample Response

[
  {
    id: 'hfh51v',
    type: 'wallpaper',
    title: 'Illuminated City at Night [1920 x 1200]',
    postLink: 'https://redd.it/hfh51v',
    image: 'https://i.redd.it/b6x9i2n830751.jpg',
    thumbnail:
      'https://b.thumbs.redditmedia.com/mLCk8Bh0N4M8hZafHsbAmw8rM7JEEznsT2nRZSo3GsU.jpg',
    subreddit: 'wallpaper',
    NSFW: false,
    spoiler: false,
    createdUtc: 1593066557,
    upvotes: 1899,
    upvoteRatio: 1.0,
  },
  {
    id: 'h9glhi',
    type: 'wallpaper',
    title: 'Missing Home by Just Jaker',
    postLink: 'https://redd.it/h9glhi',
    image:
      'https://cdnb.artstation.com/p/assets/images/images/027/020/665/large/just-jaker-galax-noise.jpg',
    thumbnail:
      'https://b.thumbs.redditmedia.com/4utBLNbsIDDLl46z494PCRkDhmAnapQq9FL7l-07aJo.jpg',
    subreddit: 'ImaginaryFuturism',
    NSFW: false,
    spoiler: false,
    createdUtc: 1592228591,
    upvotes: 462,
    upvoteRatio: 1.0,
  },
];

Options

Property Type Description Default
type string 'meme' | 'wallpaper' | 'custom' 'meme'
total number How many images to get. Max is 50 1
subreddit [string] Custom subreddit library [ ]
addSubreddit [string] Add subreddits to subreddit library [ ]
removeSubreddit [string] Remove subreddits from subreddit library [ ]
allowNSFW boolean Allow NSFW results true

Support

You can show your support by starring this project.

Github Star

Contribute

To contribute, see the contributing guide.

License

MIT License

reddit-image-fetcher's People

Contributors

arifszn avatar eccclesiastes avatar meltymoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

reddit-image-fetcher's Issues

Image field returns blank

Hi, i'm currently running this code:

const id = () => {
            ping.then((a) => {
            reddit.FetchPostbyID(a).then((data) => {
            console.log('FetchPostbyID Example: ');
            console.log(data);
            })
            });
        }

        id();

Where (a) is the reddit post ID. However, when the data is printed, the image field returns blank.

0|tiggerBot  | FetchPostbyID Example:
0|tiggerBot  | {
0|tiggerBot  |   id: 'siyx6z',
0|tiggerBot  |   type: '',
0|tiggerBot  |   title: 'Joy',
0|tiggerBot  |   author: 'PiccoloGlum3115',
0|tiggerBot  |   postLink: 'https://redd.it/siyx6z',
0|tiggerBot  |   image: '',
0|tiggerBot  |   gallery: false,
0|tiggerBot  |   text: '',
0|tiggerBot  |   thumbnail: 'https://b.thumbs.redditmedia.com/BP6ZoT3_Ot8RcCultc5qvm6mq4DGBLuV6916-DFA2sA.jpg',
0|tiggerBot  |   subreddit: 'kpics',
0|tiggerBot  |   NSFW: false,
0|tiggerBot  |   spoiler: false,
0|tiggerBot  |   createdUtc: 1643833549,
0|tiggerBot  |   upvotes: 168,
0|tiggerBot  |   downvotes: 0,
0|tiggerBot  |   upvoteRatio: 0.99
0|tiggerBot  | }

Sorry if i'm missing something obvious, I'm a bit new to JavaScript.

need one more option.

saw that package retries if failed finding post/reddit and have some retry limit..

image

would be nice to have customizable or at least way to disabled retrying if once failed because it takes few seconds to throw error message, instead of wait i would like to tell users to just redo the command right away.

Configure retry strategy or max retries

This library may be useful for fetching images from a single subreddit, in which case it isn't necessary to retry 50 times if that subreddit doesn't return enough images.

Two feature requests.

A filter for NSFW images in the next version, as well as the functionality to search the whole of Reddit for images related to a search term, without specifying a subreddit.

Feature Request - Choose sorting

It would be great if you could choose the sort type in the request like so

RedditImageFetcher.fetch({
    type: 'wallpaper',
    sort: 'top',
    total: 50
}).then(result => {
    console.log(result);
});

Error on subreddit

const RedditImageFetcher = require("reddit-image-fetcher");

// fetch 1 meme
RedditImageFetcher.fetch({
  subreddit: ["videos"], type: 'custom', total: 1 
}).then((result) => {
  console.log(result);
});

when i use this the i got an limit error.

grafik

Feature Request - Allow NSFW

I am not very familiar with the reddit API, but I am guessing that there is no way to filter NSFW just by default. I was thinking of having an allowNsfw option, which would be a boolean, which would filter out any NSFW results. Sort of like this:

RedditImageFetcher.fetch({
   type: 'memes',
   allowNsfw: false,
   total: 25
}).then((result) => console.log(result));

If this is something that seems appealing I don't mind Forking the repo and doing it myself, I imagine it would only be a relatively easy change to make. :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.