有人上传视频时的通知

问题描述:

因此,我试图弄清楚如何制作一个程序,该程序可以查看YouTube帐户是否上传了新视频.

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

我当时正在考虑让一台虚拟PC用PHP执行此操作,并每2分钟自动刷新一次页面,如果标题已更改,则它将数据保存在数据库中并发送电子邮件.

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.

我相信您可以通过Youtube API进行访问,例如,您应该能够访问用户通过以下方式完成的最新上传:

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

例如

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

检索该用户的最新上传.解析视频ID&与您已经登录的其他ID进行比较.

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

根据评论进行了编辑

@IamGretar我建议阅读有关PHP DOMDocument的文章-> loadXML / loadHTML 类以一种体面的方式进行处理,这是一个粗略而公正的方法令人讨厌的方式.这应该使您了解要完成的工作,但是我正在使用它来演示该原理,并且不建议将其用于其他任何事情:

@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]);