TIMOTHY MWALA
Published © GPL3+

Build Your Own YouTube Channel Statistics Meter with C3-Mini

Monitor your YouTube channel's growth in real time with our compact OLED display powered by ESP32-C3 Mini. See stats at a glance!

BeginnerFull instructions provided1 hour235
Build Your Own YouTube Channel Statistics Meter with C3-Mini

Story

Read more

Code

Youtube_Meter

C/C++
Remember to install all the additional libraries , under library manager
/*******************************************************************
  Read YouTube Channel statistics from the YouTube API
  and print them to the serial monitor and OLED display

  Compatible Boards:
  * Any ESP8266 board
  * Any ESP32 board

// ----------------------------
// Standard Libraries
// ----------------------------

#if defined(ESP8266)
  #include <ESP8266WiFi.h>
#elif defined(ESP32)
  #include <WiFi.h>
#endif

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFiClientSecure.h>

// ----------------------------
// Additional Libraries - each of these will need to be installed
// ----------------------------

// Library for connecting to the YouTube API
// https://github.com/witnessmenow/arduino-youtube-api
#include <YoutubeApi.h>

// Library used for parsing Json from the API responses
// https://github.com/bblanchon/ArduinoJson
#include <ArduinoJson.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

//------- Replace the following! ------
const char ssid[] = ".............";       // your network SSID (name)
const char password[] = "...........";  // your network key
#define API_KEY ".............."           // your Google API key
#define CHANNEL_ID "................." // part of the channel url
//------- ---------------------- ------

WiFiClientSecure client;
YoutubeApi api(API_KEY, client);

unsigned long timeBetweenRequests = 60 * 1000;  // 60 seconds, in milliseconds

void setup() {
  Serial.begin(115200);
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);
  display.clearDisplay();

  // Set WiFi to 'station' mode and disconnect
  // from the AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  // Connect to the WiFi network
  Serial.print("\nConnecting to WiFi: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("\nWiFi connected!");
  Serial.print("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);

  // Required for secure client connection
  client.setInsecure();

  // Uncomment for extra debugging info
  // api._debug = true;
}

void loop() {
  if(api.getChannelStatistics(CHANNEL_ID)) {
    Serial.println("\n---------Stats---------");

    Serial.print("Subscriber Count: ");
    Serial.println(api.channelStats.subscriberCount);

    Serial.print("View Count: ");
    Serial.println(api.channelStats.viewCount);

    Serial.print("Video Count: ");
    Serial.println(api.channelStats.videoCount);

    // Probably not needed :)
    //Serial.print("hiddenSubscriberCount: ");
    //Serial.println(api.channelStats.hiddenSubscriberCount);

    Serial.println("------------------------");
    display.clearDisplay();
    display.setTextSize(1.5);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(5, 0);
    display.print("My YouTube Channel ");
    display.setCursor(4, 2);
    display.print("___________________ ");
    display.setCursor(0, 17);
    display.print("Subscribers: ");
    display.println(api.channelStats.subscriberCount);
    display.setCursor(0, 31);
    display.print("Total Views: ");
    display.println(api.channelStats.viewCount);
    display.setCursor(0, 45);
    display.print("Total Videos: ");
    display.println(api.channelStats.videoCount);
    display.display();
  }
  delay(timeBetweenRequests);
}

Credits

TIMOTHY MWALA
29 projects • 17 followers
I am an Embedded engineer who like prototyping
Contact

Comments

Please log in or sign up to comment.