问题
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.
回答1:
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]);
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/17172930/notification-when-someone-uploads-a-video