Giter VIP home page Giter VIP logo

reddit-anti-gif-bot's Introduction

reddit-anti-gif-bot

The source of u/anti-gif-bot, a bot which provides an mp4 link/mirror for gif submissions.

You can find an FAQ here: https://reddit.com/r/anti_gif_bot/wiki/index ย 

How it works

Some technical stuff; this bot is written in JavaScript and runs on Node.js. It uses the library snoowrap for every interaction with Reddit and the official gfycat-sdk to upload to gfycat. Every 15 seconds the bot fetches /r/all/new to get the newest submissions and filters all gif submissions. If the gif domain is known for providing an mp4 version the gif url gets converted to an mp4 link, otherwise a request to gfycat is made containing the gif url. After an mp4 link is generated (or gfycat is done converting the gif) a reply containing that link gets posted. That's it basically. There are a few more things such as a domain blacklist (the gifv-bot already covers gifs from imgur) and an internal stats counter that keeps track of the amount of submissions the bot scraped, the amount of gifs, domains that host gifs etc. Maybe I'll eventually create a website where I make these stats available. Until then I'll keep them private (well, I accidentally committed a dev version once but whatever, it's no secret) to enhance the bot and for my own curiosity.

Contribution

If you find any bugs or want to submit an enhancement feel free to open an issue or submit a pull request and I'll look into it!

reddit-anti-gif-bot's People

Contributors

jwilk avatar wasdennnoch 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reddit-anti-gif-bot's Issues

Good robots should have good grammar

The bot doesn't seem to have learned human phrasing as of yet.

Example: This mp4 version is 1.96 times smaller than the gif (25.54 MB vs 13.06 MB).

While this is nice in that it has no corner cases, a human would likely phrase this as 'This mp4 is 1/2 the size of the gif (25.54 MB vs 13.06 MB).

(Consider rounding to the nearest integer divisor and rephrasing the reply text)

Unnecessarily re-encode on a giphy gifv link that ends in gif.

How much gif would a gifv host if a giphy could host gif

nobutreally though, this post's gifv was unnecessarily re-encoded, going from a 1.1MiB file to a 2.3MiB file.

I see there's a very recent commit that addresses giphy, but I figured I'd bring this up anyway since the post in question happened afterward. Maybe the new version just wasn't deployed yet though, I haven't followed this bot enough.

Skip GIF images that are not animations.

As it stands, your bot is unable to tell GIF images from GIF animations. This unnecessarily creates single-frame mp4 files from static images.

The following Javascript code accepts a binary string as an argument. It returns true if it's a multi-frame GIF, false on a single-frame GIF, undefined if there's an error. Yes, this is the skeleton of a GIF block decoder, straight from the spec.

Of course, it requires your bot to actually fetch the images from remote servers. I have no experience with Node.js, so I don't know if this is practical, but you may want to make an HTTP HEAD request before fetching the image, in order to avoid 404 errors and also because GIFs larger than 1 MB are most likely animations anyway.

function isAnimatedGIF(binaryData)
{
    var offset = 13;
    var layerCount = 0;
    function readblocks()
    {
        var bs = binaryData.charCodeAt(offset) & 0xff;
        while(bs != 0) {
            offset += bs + 1;
            bs = binaryData.charCodeAt(offset) & 0xff;
        }
        offset++;
    }
    if(binaryData.substring(0, 3) != 'GIF') {
        return undefined;
    }
    var lsd = binaryData.charCodeAt(10) & 0xff;
    if(lsd & 128) {
        // Global palette
        offset += 3 * ( 1 << ( ( lsd & 7 ) + 1 ) );
    }
    while(offset < binaryData.length) {
        var blockType = binaryData.charCodeAt(offset) & 0xff;
        if(blockType == 0x3b) {
            // End of stream
            break;
        }
        if(blockType == 0x21) {
            // Extension block
            offset += 2;
            readblocks();
            continue;
        }
        if(blockType == 0x2C) {
            // Image description block
            layerCount++;
            var lsd = binaryData.charCodeAt(offset + 9) & 0xff;
            offset += 11;
            if(lsd & 128) {
                // Local palette
                offset += 3 * ( 1 << ( ( lsd & 7 ) + 1 ) );
            }
            readblocks();
            continue;
        }
        return undefined;
    }
    return layerCount > 1;
}

Please add license

There is no license included with the source, so it's licensing status is unknown. Please add some sort of license :)

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.