Tiny Tiny RSS: Community

Youtube feed description plugin


#1

For youtube channel feed, ttrss can’t parse its description. I made a plugin to add thumbnail and video description as feed’s description.

In order to use this plugin, you should update ttrss newer than commit 40f4a7aa.

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

	function about() {
		return array(1.0,
			"Add youtube feed description",
			"hyg");
	}

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

		$host->add_hook($host::HOOK_FEED_PARSED, $this);
	}

	function hook_feed_parsed($rss) {
        if ($this->is_youtube_feed($rss)) {
            $items = $rss->get_items();
            foreach ($items as $item) {
                $this->addSummaryNode($item);
            }
        }
	}

	function api_version() {
		return 2;
	}

    private function is_youtube_feed($rss): bool {
        return strpos($rss->get_link(), 'www.youtube.com/channel') !== false;
    }

    private function addSummaryNode($item) {
        $elem = $item->get_element();
        $thumbnail_url = $elem->getElementsByTagName("thumbnail")->item(0)->getAttribute("url");
        $description = str_replace("\n", "<br>"
            , $elem->getElementsByTagName("description")->item(0)->nodeValue);
        $summary_value = "<img src=\"$thumbnail_url\"/><br>$description";
        $summary_node = $elem->ownerDocument->createElement("summary", str_replace("&", "&amp;", $summary_value));
        $elem->appendChild($summary_node);
    }

}

#2

I already get descriptions and full videos in my youtube feeds…? maybe I’m thinking of titles.


#3

You should probably point out that your code contains a scalar type hint and will require PHP7.