Example #1
0
 /**
  * Main function to execute when listen occurs
  */
 public function execute($data)
 {
     $args = $this->getArguments($data);
     // Check we're in a channel
     if ($args[2][0] !== '#') {
         return;
     }
     $args_string = implode(' ', array_slice($args, 3));
     $urls = find_urls_in_string($args_string);
     if ($urls === FALSE) {
         return;
     }
     $titles = '';
     $parsed_url = parse_url($urls[0]);
     // if (imgur && not gifv/webm)...
     if (!strstr($parsed_url['host'], 'imgur.com') && !strcmp(substr($urls[0], -4), '.gif')) {
         echo 'url passed imgur/gif test: ' . $url[0], PHP_EOL;
         $gfy_url = 'http://upload.gfycat.com/transcode?fetchUrl=';
         $url = $gfy_url . $urls[0];
         $curl = curl_init();
         curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url));
         $result = curl_exec($curl);
         curl_close($curl);
         $result = json_decode($result, true);
         if (isset($result['webmUrl'])) {
             $this->say('3,0Gfy1,0cat ' . $result['webmUrl'], $args[2]);
         }
     } else {
         echo 'url[0]: ' . $urls[0], PHP_EOL;
         echo '$parsed_url[\'host\']: ' . $parsed_url['host'], PHP_EOL;
     }
 }
Example #2
0
 /**
  * Main function to execute when listen occurs
  */
 public function execute($data)
 {
     $args = $this->getArguments($data);
     // Check we're in a channel
     if ($args[2][0] !== '#') {
         return;
     }
     $args_string = implode(' ', array_slice($args, 3));
     //		preg_match_all( '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $args_string, $match );
     $urls = find_urls_in_string($args_string);
     if ($urls === FALSE) {
         return;
     }
     $titles = '';
     foreach ($urls as $url) {
         $title = '';
         if (strstr($url, 'reddit.com') || strstr($url, 'youtu.be') || strstr($url, 'youtube.com') || strstr($url, 'imgur.com') || strstr($url, 'imdb.com') || strstr($url, 'instagr.am') || strstr($url, 'instagram.com') || strstr($url, 'dailymotion.com') || strstr($url, 'vimeo.com') || strstr($url, 'instagram.com') || strstr($url, 'gfycat.com')) {
             return;
         }
         // let the other listeners handle it, we dont want multiple outputs per input
         // Download linked webpage
         $html = file_get_contents($url);
         if (FALSE === $html) {
             echo "\tWarning: file_get_contents fail ({$url})\n";
             return;
         }
         $start = substr(strstr($html, '<title>'), strlen('<title>'));
         $title = substr($start, 0, stripos($start, '</title>'));
         if (!empty($title)) {
             if (strlen($titles)) {
                 $titles .= ', ';
             }
             $title = trim(html_entity_decode($title, ENT_QUOTES));
             $titles .= "{$title}";
         }
     }
     echo "Outputting title: {$titles}\n";
     if (!empty($titles)) {
         $this->say($titles, $args[2]);
     }
 }
Example #3
0
 /**
  * Main function to execute when listen occurs
  */
 public function execute($data)
 {
     $args = $this->getArguments($data);
     echo "hello from youtube";
     $title = null;
     // array_slice = Skip over host, channel, msgtype
     $message_string = implode(' ', array_slice($args, 3));
     // find all urls in each 'word'
     $urls = find_urls_in_string($message_string);
     if ($urls === FALSE) {
         echo 'didnt find any urls in string', PHP_EOL;
         return;
     }
     $youtube_video_id = null;
     foreach ($urls as $url) {
         $url_parsed = parse_url($url);
         if ($url_parsed !== FALSE && isset($url_parsed['host'])) {
             if (strstr($url_parsed['host'], 'youtube.com') || strstr($url_parsed['host'], 'youtu.be')) {
                 $youtube_video_id = $url;
                 break;
             }
         }
     }
     if ($youtube_video_id === null) {
         echo 'youtube_video_id was null', PHP_EOL;
         return;
     }
     echo $youtube_video_id, PHP_EOL;
     echo urlencode($youtube_video_id), PHP_EOL;
     $url_parsed = parse_url($youtube_video_id);
     parse_str($url_parsed['query'], $query_parsed);
     $youtube_video_id = $url_parsed['scheme'] . '://' . $url_parsed['host'] . $url_parsed['path'] . '?v=' . $query_parsed['v'];
     if ($ret_json = file_get_contents('https://noembed.com/embed?url=' . $youtube_video_id)) {
         $ret_json_decoded = json_decode($ret_json, true);
         echo $ret_json_decoded, PHP_EOL, PHP_EOL;
         $title = $ret_json_decoded['title'];
         $url = $ret_json_decoded['url'];
         $this->say("1,0You0,4Tube {$title}", $args[2]);
     }
 }