2

So I'm trying to figure out how I could make a program that could see if a YouTube account uploads a new video.

I was thinking about having a virtual PC doing it in PHP and refresh the page automatically every 2 minutes and if the title has changed then it saves the data inside a database and sends an email.

If anyone has a solution or a better way of doing this please share.

IamGretar
  • 173
  • 2
  • 13
  • 1
    Um... why are you trying to reinvent the wheel? Youtube has its own subscription functionality for each channel – Filippos Karapetis Jun 18 '13 at 15:34
  • It's because I'm making a Youtube app and I want to send Push Notifications. I'm not sure why I said email, haha – IamGretar Jun 18 '13 at 15:35
  • You can [Subscribe to Push Notifications](https://developers.google.com/youtube/v3/guides/push_notifications) via YouTube Data API (v3) – showdev Apr 27 '21 at 23:54

3 Answers3

1

In addition to using the API method, you could parse the RSS feed for the channel using PHP. I did something similar with RSS feeds, using wget to retrieve the feed, XLST to format the results and ran it via cron.

jksloan
  • 184
  • 1
  • 4
0

Subscribe to the channel, and in subscription settings click "Email with new uploads". Have that e-mail sent to a script on your server that could notify you in whatever way you wish.

or

Use this API method https://developers.google.com/youtube/v3/docs/activities/list and parse the results for new uploads.

givemesnacks
  • 336
  • 4
  • 12
  • I thought about that but wouldn't I need to do that in PHP and let the page refresh and check if there's a new upload right ? – IamGretar Jun 18 '13 at 15:39
0

I believe you can access it via the Youtube API, for example you should be able to access the most recent upload a user has done by:

http://gdata.youtube.com/feeds/api/users/[USER-ID]/uploads?max-results=1

so for example

http://gdata.youtube.com/feeds/api/users/askhodgetwins/uploads?max-results=1

retrieves the most recent upload by that user. Parse for the video ID & compare to other IDs you have already logged.

Edited in response to comment

@IamGretar I'd recommend reading about the PHP DOMDocument -> loadXML/loadHTML class to go about this in a decent way, here's a rough and fairly nasty way to do it. This should give you an idea of what you're trying to accomplish, I'm using it demonstrate the principle however, and wouldn't recommend using it for anything else:

$youtube_user_URL = 'http://gdata.youtube.com/feeds/api/users/askhodgetwins/uploads?max-results=1';
$html = file_get_contents($youtube_user_URL);

$pattern = "/<title ?.*>(.*)<\/title>/";
preg_match($pattern, $html, $matches);

print_r($matches[1]);
SubjectCurio
  • 4,702
  • 3
  • 32
  • 46