Skip to content

Commit

Permalink
also handle peertube (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhieF authored and kevinpapst committed Jun 22, 2018
1 parent cce59dd commit 6aeab28
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FreshRSS - YouTube video extension

This FreshRSS extension allows you to directly watch YouTube videos from within subscribed channel feeds.
This FreshRSS extension allows you to directly watch YouTube/PeerTube videos from within subscribed channel feeds.

To use it, upload the ```xExtension-YouTube``` directory to the FreshRSS `./extensions` directory on your server and enable it on the extension panel in FreshRSS.

Expand Down Expand Up @@ -32,6 +32,9 @@ More extensions can be found at [FreshRSS/Extensions](https://github.com/FreshRS

## Changelog

0.7:
* Support for PeerTube feed

0.6:
* Support cookie-less domain www.youtube-nocookie.com for embedding

Expand Down
25 changes: 21 additions & 4 deletions xExtension-YouTube/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function embedYouTubeVideo($entry)
{
$link = $entry->link();

if (stripos($link, 'www.youtube.com/watch?v=') === false) {
if (preg_match('#^https?://www\.youtube\.com/watch\?v=|/videos/watch/[0-9a-f-]{36}$#', $link) !== 1) {
return $entry;
}

Expand All @@ -115,9 +115,12 @@ public function embedYouTubeVideo($entry)
if (stripos($entry->content(), '<iframe class="youtube-plugin-video"') !== false) {
return $entry;
}

$html = $this->getIFrameForLink($link);

if (stripos($link, 'www.youtube.com/watch?v=') !== false) {
$html = $this->getIFrameForLink($link);
}
else{ //peertube
$html = $this->getPeerTubeIFrameForLink($link);
}
if ($this->showContent) {
$html .= $entry->content();
}
Expand Down Expand Up @@ -147,6 +150,20 @@ public function getIFrameForLink($link)
return $html;
}

/**
* Returns an HTML <iframe> for a given PeerTube watch URL
*
* @param string $link
* @return string
*/
public function getPeerTubeIFrameForLink($link)
{
$url = str_replace('/watch', '/embed', $link);
$html = $this->getIFrameHtml($url);

return $html;
}

/**
* Returns an HTML <iframe> for a given URL for the configured width and height.
*
Expand Down
6 changes: 3 additions & 3 deletions xExtension-YouTube/metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "YouTube Video Feed",
"name": "YouTube/PeerTube Video Feed",
"author": "Kevin Papst",
"description": "Embed YouTube feeds inside article content.",
"version": 0.6,
"description": "Embed YouTube/PeerTube feeds inside article content.",
"version": 0.7,
"entrypoint": "YouTube",
"type": "system"
}

0 comments on commit 6aeab28

Please sign in to comment.