Stephen Harrison
Published © CC BY

Scanlime-in-Progress Indicator (aka YouTube Live Indicator)

Never miss your favourite YouTube channel going live with this Particle Photon based indicator.

BeginnerFull instructions provided1 hour1,124
Scanlime-in-Progress Indicator (aka YouTube Live Indicator)

Things used in this project

Hardware components

LED (generic)
LED (generic)
×6
Wide ThingySticks Prototype PCB
×1
Photon
Particle Photon
×1
Resistor 1k ohm
Resistor 1k ohm
×6

Software apps and online services

Google YouTube Data API (V3)
YouTube
You need the channel id from the YouTube channel you wish for the notification from. i.e. scanlime-in-progress is UC8G48_G7suQlScUudVXyGkg

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Code

Particle Webhook Template

JSON
{
    "event": "youtubelive",
    "responseTopic": "youtubelive",
    "errorResponseTopic": "youtubeliveerror",
    "url": "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC8G48_G7suQlScUudVXyGkg&type=video&eventType=live&key=<Insert your Google YouTube Key Here>",
    "requestType": "GET",
    "noDefaults": true,
    "rejectUnauthorized": true,
    "responseTemplate": "{{pageInfo.totalResults}}"
}

Scanlime Live

Arduino
YouTube Live indicator for a specific channel
// Detect if the channel has a live stream going
// See: https://stackoverflow.com/questions/32454238/how-to-check-if-youtube-channel-is-streaming-live
//
// Uses: https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCaEgw3321ct_PE4PJvdhXEQ&type=video&eventType=live&key=[API_KEY]
// in a webhook (replace [API_KEY])

bool isLive = false;

void setup() {
    pinMode(D7, OUTPUT);
    
    // LED drives
    pinMode(D2, OUTPUT);
    pinMode(D3, OUTPUT);
    pinMode(D4, OUTPUT);
    pinMode(D5, OUTPUT);
    pinMode(D6, OUTPUT);
    pinMode(D7, OUTPUT);
    
    // Optional external functions to allow the LEDs to be "manually" controlled
    Particle.function("on", ledsOn);
    Particle.function("off", ledsOff);
    
    Particle.subscribe("youtubelive/0", youTubeLiveHandler, MY_DEVICES);
    Particle.publish("Scanlime live V0.3");
    
    // Take control of the onboard LED
    RGB.control(true);
    // Blue - don't know - no response.
    RGB.color(0, 0, 255);
}

void loop() {
    
    digitalWrite(D7, HIGH);
    
    // Request Webhook query YouTube API for Scanlime channel.
    Particle.publish("scanlimelive");
    digitalWrite(D7, LOW);
    
    // give it n seconds before we try and check again.
    delay(60000);
}

void youTubeLiveHandler(const char *event, const char *data) {
    
    // "responseTemplate": "{{pageInfo.totalResults}}"
    // data contains the number of results
    // this should be 1 if a live stream in in progress.
    int resultCount = atoi(data);
    
    // Set the LEDs to on if their are results.
    setLEDs(resultCount > 0);
  
    // Publish a status message so this can also 
    // be picked up by Tinamous or another platform (e.g. IFTTT)
    if (resultCount > 0) {
        if (!isLive) {
            Particle.publish("status", "Scanlime live stream started. count: " + String(resultCount));        
        }
        isLive = true;
    } else {
        if (isLive) {
            Particle.publish("status", "Scanlime not live!");        
        }
        isLive = false; // :-(
    }
}

void setLEDs(bool state) {
    // LEDs are active low.
    digitalWrite(D2, !state);
    digitalWrite(D3, !state);
    digitalWrite(D4, !state);
    digitalWrite(D5, !state);
    digitalWrite(D6, !state);
    digitalWrite(D7, !state);
    
    if (state) {
        RGB.color(50, 205, 50); // Lime Green
    } else {
        RGB.color(0, 0, 0);
    }
}

int ledsOn(String args) {
    setLEDs(true);
    return 1;
}

int ledsOff(String args) {
    setLEDs(false);
    return 0;
}

Credits

Stephen Harrison

Stephen Harrison

18 projects • 51 followers
Founder of Tinamous.com, software developer, hardware tinkerer, dyslexic. @TinamousSteve
Thanks to Sparkfun.

Comments