YouTube Subscriber Count Display

This is a really simple project - using an imp to display the number of YouTube subscribers (in thousands) we have on one of our YouTube channels… Last step is to button this display up and put the imp inside. It’ll be a pretty cool piece to hang on the wall of our office.

I would love to do a tutorial on this and post the video to YouTube. Does anyone know if this is a violation of the electric imp terms of service to post video tutorials of projects like this? I have a feeling that this project in particular (being so simple) would get a lot of attention from other YouTube creators and would likely introduce them to the imp platform…

I would love to have more tutorial writers and video creators here

I would love to bring them to you! I would like to hear from someone at electric imp - if they don’t have an issue with people creating them, I’ll start posting. I create YouTube (cooking) videos for a living - I run the most subscribed cooking channel on YouTube, and I use my electrical engineering degree for my projects on the side…

We already have a lot of YouTube posters and Instructables creators and while
almost anything is open source, I can’t imagine the Imp guys would mind. But they are in the neighborhood

and about cooking, a sous-vide PID controller is on my To-Do list…

I’m really interested in seeing this as the image seems to indicate you are connecting via serial which I think is something that the imp should be awesome for.

I’m using RS-232 to talk to the display. I have a cron job that runs on our webserver every hour - it triggers a php script which reads the current subscriber count (using the YouTube API), passes the data to the imp via an agent, that data is transmitted to the display by rs-232. It only took about an hour to get it to work, half that time was spent looking for my rs-232 -> TTL adapter.

Looking good, only thing I think should be changed is how you get the viewer count. Instead of using a php file to do it, you can do it all inside the agent.

I kicked something together pretty fast, but it seems to work, just remember to change the user name.

Agent code:
`device.on(“getYoutubeFollowers”, function(msg)
{
local url = “http://gdata.youtube.com/feeds/api/users/blddk”;

http.get(url).sendasync(function(resp)
{
if (resp.statuscode = 200)
{
local findBegin = “subscriberCount=’”;
local findEnd = “’”;
local string = resp.body;
local begin = string.find(findBegin) + findBegin.len();
string = string.slice(begin,begin+10);
local end = string.find(findEnd) + findEnd.len() -1;
string = string.slice(0,end);

  server.log(string); //Return the number of followers
}
else
{
  server.log("Could not get youtube followers: " + format("%i: %s", resp.statuscode, resp.body));
}

})
});`

Device code:
getSubscribers() { agent.send("getYoutubeFollowers", 0); imp.wakeup(60*60, getStats); //Check again in one hour } getSubscribers();

No more need for the cron job or the php, everything runs with just the Imp :slight_smile:

I have YouTube videos, apps and a tutorial on the Electric Imp, and some of those have been mentioned in the Electric Imp blog. The Electric Imp team has been very supportive of those endeavors.

Some months ago, I also started a Google+ group with the idea of having developer Hangouts and sharing projects. It was clearly too early then, but I think that there are enough active forum members now that it might be something to try again. Getting a reasonable time is the hard part…

@MikeyDK thanks for that! I wasn’t really happy with the cron job, just threw it together quickly. I’ll give this code a go!

@jwehr that sounds like exactly what I was looking for, I think I’ll start posting some videos. If you start doing G+ hangouts I would love to be involved. I also have a full blown live broadcasting station (with multiple camera angles, TV switcher etc) that we use for live streaming on youtube as well as G+ hangouts on air. I use it to broadcast live cooking demos, but it would be great for tech, so you can switch between the demonstrator and the project.

Some of us have utilized Instructables for presenting our home-made projects.

It’s really interesting to see how far the Imp has gone since one-year ago. The amazing support, examples, sharing of ideas, etc. on this forum has really opened-up the Imp to some amazing projects. Most importantly, the Imp, because of the low cost, has brought in more young people, and hobbyists that would not have gotten into electronics otherwise.

I would have to think that the exposure we’re giving the Imp through our posted projects is increasing the sales exponentially. It’s a win-win situation for all of us users and the company owners.

Almost as if we’d planned it that way from the outset :wink:

Peter

@MikeyDK - The code works great and it’s nice to do this without needing a server somewhere, the only concern I would have is if lots of people started using this (or just a few people that refresh too quickly) the imp server may hit the YouTube API quota limits and the API may become non-responsive to requests. The cron job method gives me a little more control over that scenario - but this could also be solved by using a google developer key with each request… Anyhow, thanks again for the code and suggestion - I’ll be using your method!

You can also still use the php file to return the number if there are any problems, then have the imp pull that instead of the cron job

Joe, the agent only checks every hour, so the API is accessed 24 times each day no matter how many subscribers you get.

@joevitali What Ttl to rs232 did you use, I would love for there to be a standardised board for this (that also exposed the unused pins somehow).

OT if you are interested in web broadcasting leo laporte’s twit.tv is worth a look

@mlseim If other people are accessing the YouTube API with imps, the API could reach its limits (the quotas are set on a per-server baisis - so the imp server would be making too many requests if all imps use the same server) depending on how many other people and what frequency they are accessing it. @MileyDK’s suggestion using a php page that I host which does the API connecting would be a good fix, because I’m the only one on my server accessing the API.

@back_ache I was just using one that I had laying around, turned out I didn’t need it when I added the imp inside the display housing because there was a DS14C232CN level shifter IC inside the unit, I just removed and bypassed it. The board I used is by Pololu http://www.pololu.com/product/126 I usually use the DS275 IC it works in many applications where MAX232 would normally be used but it’s smaller and doesn’t require the caps so it’s a quick solution for a lot of these projects.

I look forward to seeing the video. We love seeing customer videos!

A.

Minor change… This can now run in just the agent alone.

Agent:
`function youtubeSubscribers()
{
local url = “http://gdata.youtube.com/feeds/api/users/blddk”;

http.get(url).sendasync(function(resp)
{
if (resp.statuscode = 200)
{
local findBegin = “subscriberCount=’”;
local findEnd = “’”;
local string = resp.body;
local begin = string.find(findBegin) + findBegin.len();
string = string.slice(begin,begin+10);
local end = string.find(findEnd) + findEnd.len() -1;
string = string.slice(0,end);

  server.log(string); //Return the number of followers
}
else
{
  server.log("Could not get youtube followers: " + format("%i: %s", resp.statuscode, resp.body));
}

});

imp.wakeup(60*60, youtubeSubscribers);
}
youtubeSubscribers();`

And just in case anyone would like yo use their own server instead, here is some php that can do the trick:
`<?php
echo youtube_subscribers(“blddk”);

function youtube_subscribers($user)
{
$xml = file_get_contents(‘http://gdata.youtube.com/feeds/api/users/’ . strtolower($user));
$xml = str_replace(‘yt:’, ‘yt’, $xml);
$xml = new SimpleXMLElement($xml);
$subs = $xml->ytstatistics[‘subscriberCount’];
return(trim($subs));
}
?>`

Still waiting for that tutorial… :stuck_out_tongue:

@GobiDoo,
What tutorial exactly?
Describe what you wish to do.