Plugin Af_YouTube

Post plugins and custom CSS snippets here
feader
Bear Rating Master
Bear Rating Master
Posts: 160
Joined: 26 Dec 2012, 20:03

Plugin Af_YouTube

Postby feader » 30 Aug 2013, 15:21

Here is a plugin that embeds video iframes into YouTube feed entries. To use it, you have to create a directory af_youtube in the plugins subdirectory of your ttRSS installation, save the code below into a file named init.php and put it into the af_youtube directory. After that, it needs to be activated in Tiny Tiny RSSes Preferences.
You probably need the videoframes plugin to see the video players in Tiny Tiny RSS. Oh, and Google may detect "strange activity" from your network when you are using this, especially in Combined Display mode, and make you solve a few CAPTCHAs. :evil:

Code: Select all

<?php
class Af_YouTube extends Plugin {
   private $host;

   function about() {
      return array(0.9,
         "Adds video iframes to YouTube feeds. You may need to install the 'videoframes' plugin to display them",
         "feader");
   }

   function init($host) {
      $this->host = $host;

      $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
   }   
   
   function hook_article_filter($article) {
      $link = trim($article["link"]);
      if (strpos($link, "youtube.com/watch") !== FALSE) {         
         $query = parse_url($link, PHP_URL_QUERY);
         if($query != FALSE) {
            parse_str($query, $params);
            $embed_link = "https://www.youtube.com/embed/" . $params['v'];
            
            $article["content"] .= '<p><iframe width="560" height="315" src="' . $embed_link . '" frameborder="0"></iframe></p>';
         }
      }
      return $article;
   }

   function api_version() {
      return 2;
   }
}
?>

Return to “Themes and plugins”

Who is online

Users browsing this forum: No registered users and 2 guests