Answer the question
In order to leave comments, you need to log in
Youtube new video notifications
Hello.
So, I describe the situation.
I lead a VKontakte group dedicated to one young, but rapidly gaining popularity, musical group. In addition to any news, this team shoots a video and uploads it to their YouTube channel, about once a month. I need to be promptly notified of such updates. There is a way to receive notifications by mail, using YouTube itself, but they come very often in an hour, or even more - this is a very long time.
Actually the question is: how to implement receiving notifications about updates on YouTube with a sms like: "Tadam, new video"?
There is a small, but plus - the team usually informs in advance on what day the clip will be released -> you can poll Yotube for N time and not run the script in vain 24/7.
I have my own small site on hosting, I found a script, it will be two years old soon. In this script, sending SMS works fine, but checking for new videos no longer works.
If everything works out, then it remains to run the script using Cron and let it check itself every N minutes. :)
I would be very grateful for your help.
<?php
function send_sms($to, $msg, $login, $password){
$u = 'http://www.websms.ru/http_in5.asp';
$ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'Http_username='.urlencode($login). '&Http_password='.urlencode($password). '&Phone_list='.$to.'&Message='.urlencode($msg));
curl_setopt($ch, CURLOPT_URL, $u);
$u = trim(curl_exec($ch));
curl_close($ch);
preg_match("/message_id\s*=\s*[0-9]+/i", $u, $arr_id );
$id = preg_replace("/message_id\s*=\s*/i", "", @strval($arr_id[0]) );
return $id;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11');
$url = 'http://www.youtube.com/user/PTXofficial/feed'; //ссылка на канал
$compare = 'Run to You - Pentatonix'; //название текущего видео
$mob = ''; //мобильный в формате 79251234678
$login = ''; //логин на сайте для отправки смс
$pass = '';//пароль на сайте для отправки смс
curl_setopt($ch, CURLOPT_URL, $url);
$page = curl_exec($ch);
$page = iconv('utf-8', 'windows-1251', $page);
if ($page != false){
$page = trim(substr($page, strpos($page, 'yt-uix-sessionlink'), 800));
$page = trim(substr($page, strpos($page, 'ltr')+5, 110));
$page = trim(substr($page, 0, 100));
$page = substr($page, 0, 6);
$compare = substr($compare, 0, 6);
$msg = $page;
if ($page != $compare && !empty($page) && $page != 'xmlns:' && $page != 'TYPE H'){
$compare = iconv('utf-8', 'windows-1251', $compare);
send_sms($mob, $msg, $login, $pass);
echo $msg;
}else{
if (empty($page)) echo '[ ERROR: empty page loaded ]';
}
} else { echo 'Невозможно загрузить страницу'; die; }
curl_close($ch);
?>
Answer the question
In order to leave comments, you need to log in
You can check new videos through the rss channel, the script can be redone in 10 minutes. http://gdata.youtube.com/feeds/base/users/pol... rss feed example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question