From 306d3cdc608343b5739b98a7d6b1e816416489c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Sun, 16 Feb 2020 14:26:06 +0100 Subject: Basic Media-RSS support (#599) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Éloi Rivard --- appinfo/database.xml | 10 +++++++++ docs/plugins/README.md | 2 ++ lib/Db/Item.php | 28 ++++++++++++++++++++++++++ lib/Fetcher/FeedFetcher.php | 10 ++++++++- templates/part.content.php | 6 ++++++ tests/Integration/Fixtures/ItemFixture.php | 2 ++ tests/Unit/Controller/ExportControllerTest.php | 6 ++++-- tests/Unit/Db/ItemTest.php | 16 +++++++++++++++ 8 files changed, 77 insertions(+), 3 deletions(-) diff --git a/appinfo/database.xml b/appinfo/database.xml index e9c65a947..adc8f197a 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -350,6 +350,16 @@ clob false + + media_thumbnail + clob + false + + + media_description + clob + false + feed_id integer diff --git a/docs/plugins/README.md b/docs/plugins/README.md index 3d7f968cb..97cb792ce 100644 --- a/docs/plugins/README.md +++ b/docs/plugins/README.md @@ -112,6 +112,8 @@ The **addArticleAction** method expects a function with the following parameters * **body**: the html content * **enclosureMime**: if an enclosure is added, this is the mime type * **enclosureLink**: this is the source of the enclosure + * **mediaThumbnail**: if there is a media attached, this is its thumbnail + * **mediaDescription**: if there is a media attached, this is its description * **feedId**: the feed id it belongs to * **unread**: if the article is unread (bool) * **starred**: if the article is starred (bool) diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 5491dff25..e88635435 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -41,6 +41,10 @@ class Item extends Entity implements IAPI, \JsonSerializable protected $enclosureMime; /** @var string|null */ protected $enclosureLink; + /** @var string|null */ + protected $mediaThumbnail; + /** @var string|null */ + protected $mediaDescription; /** @var int */ protected $feedId; /** @var int */ @@ -84,6 +88,8 @@ class Item extends Entity implements IAPI, \JsonSerializable $item->setBody($import['body']); $item->setEnclosureMime($import['enclosureMime']); $item->setEnclosureLink($import['enclosureLink']); + $item->setMediaThumbnail($import['mediaThumbnail']); + $item->setMediaDescription($import['mediaDescription']); $item->setRtl($import['rtl']); $item->setUnread($import['unread']); $item->setStarred($import['starred']); @@ -259,6 +265,8 @@ class Item extends Entity implements IAPI, \JsonSerializable 'body' => $this->getBody(), 'enclosureMime' => $this->getEnclosureMime(), 'enclosureLink' => $this->getEnclosureLink(), + 'mediaThumbnail' => $this->getMediaThumbnail(), + 'mediaDescription' => $this->getMediaDescription(), 'feedId' => $this->getFeedId(), 'unread' => $this->isUnread(), 'starred' => $this->isStarred(), @@ -315,6 +323,22 @@ class Item extends Entity implements IAPI, \JsonSerializable } } + public function setMediaThumbnail(string $mediaThumbnail = null) + { + if ($this->mediaThumbnail !== $mediaThumbnail) { + $this->mediaThumbnail = $mediaThumbnail; + $this->markFieldUpdated('mediaThumbnail'); + } + } + + public function setMediaDescription(string $mediaDescription = null) + { + if ($this->mediaDescription !== $mediaDescription) { + $this->mediaDescription = $mediaDescription; + $this->markFieldUpdated('mediaDescription'); + } + } + public function setFeedId(int $feedId) { if ($this->feedId !== $feedId) { @@ -446,6 +470,8 @@ class Item extends Entity implements IAPI, \JsonSerializable 'body' => $this->getBody(), 'enclosureMime' => $this->getEnclosureMime(), 'enclosureLink' => $this->getEnclosureLink(), + 'mediaThumbnail' => $this->getMediaThumbnail(), + 'mediaDescription' => $this->getMediaDescription(), 'feedId' => $this->getFeedId(), 'unread' => $this->isUnread(), 'starred' => $this->isStarred(), @@ -468,6 +494,8 @@ class Item extends Entity implements IAPI, \JsonSerializable 'body' => $this->getBody(), 'enclosureMime' => $this->getEnclosureMime(), 'enclosureLink' => $this->getEnclosureLink(), + 'mediaThumbnail' => $this->getMediaThumbnail(), + 'mediaDescription' => $this->getMediaDescription(), 'unread' => $this->isUnread(), 'starred' => $this->isStarred(), 'feedLink' => $feeds['feed' . $this->getFeedId()]->getLink(), diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index a1b7e08ec..82ad86352 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -256,11 +256,19 @@ class FeedFetcher implements IFeedFetcher if ($parsedItem->hasMedia()) { // TODO: Fix multiple media support foreach ($parsedItem->getMedias() as $media) { - if (!$item->isSupportedMime($media->getType())) { + if (!$item->isSupportedMime($media->getType()) + && !$media->getThumbnail() + && !$media->getDescription() + ) { continue; } $item->setEnclosureMime($media->getType()); $item->setEnclosureLink($media->getUrl()); + $item->setMediaThumbnail($media->getThumbnail()); + if ($media->getDescription()) { + $description = str_replace("\n", "
", $media->getDescription()); + $item->setMediaDescription($description); + } } } diff --git a/templates/part.content.php b/templates/part.content.php index b7cf52243..67cd8bf50 100644 --- a/templates/part.content.php +++ b/templates/part.content.php @@ -144,6 +144,12 @@ +
+ +
+ +
+
diff --git a/tests/Integration/Fixtures/ItemFixture.php b/tests/Integration/Fixtures/ItemFixture.php index 0d1f3561a..e84b4250b 100644 --- a/tests/Integration/Fixtures/ItemFixture.php +++ b/tests/Integration/Fixtures/ItemFixture.php @@ -30,6 +30,8 @@ class ItemFixture extends Item 'body' => 'this is a body', 'enclosureMime' => 'video/mpeg', 'enclosureLink' => 'http://google.de/web.webm', + 'mediaThumbnail' => 'https://i3.ytimg.com/vi/Zgge1O9wdPY/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'feedId' => 0, 'unread' => true, 'starred' => false, diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php index 9af641c42..84ded5c6f 100644 --- a/tests/Unit/Controller/ExportControllerTest.php +++ b/tests/Unit/Controller/ExportControllerTest.php @@ -131,10 +131,12 @@ class ExportControllerTest extends TestCase $this->assertEquals( '[{"guid":"guid","url":null,"title":null,' . '"author":null,"pubDate":null,"updatedDate":null,"body":null,"enclosureMime":null,' . - '"enclosureLink":null,"unread":false,"starred":false,' . + '"enclosureLink":null,"mediaThumbnail":null,"mediaDescription":null,'. + '"unread":false,"starred":false,' . '"feedLink":"http:\/\/goo","rtl":false},{"guid":"guid","url":null,' . '"title":null,"author":null,"pubDate":null,"updatedDate":null,"body":null,' . - '"enclosureMime":null,"enclosureLink":null,"unread":false,' . + '"enclosureMime":null,"enclosureLink":null,"mediaThumbnail":null,'. + '"mediaDescription":null,"unread":false,' . '"starred":false,"feedLink":"http:\/\/gee","rtl":false}]', $return->render() ); diff --git a/tests/Unit/Db/ItemTest.php b/tests/Unit/Db/ItemTest.php index 4c725b827..65a67733c 100644 --- a/tests/Unit/Db/ItemTest.php +++ b/tests/Unit/Db/ItemTest.php @@ -79,6 +79,8 @@ class ItemTest extends TestCase $item->setBody('body'); $item->setEnclosureMime('audio/ogg'); $item->setEnclosureLink('enclink'); + $item->setMediaThumbnail('https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg'); + $item->setMediaDescription('The best video ever'); $item->setRtl(true); $item->setFeedId(1); $item->setStatus(0); @@ -101,6 +103,8 @@ class ItemTest extends TestCase 'body' => 'body', 'enclosureMime' => 'audio/ogg', 'enclosureLink' => 'enclink', + 'mediaThumbnail' => 'https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'feedId' => 1, 'unread' => true, 'starred' => true, @@ -127,6 +131,8 @@ class ItemTest extends TestCase $item->setBody('
this is a test'); $item->setEnclosureMime('audio/ogg'); $item->setEnclosureLink('enclink'); + $item->setMediaThumbnail('https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg'); + $item->setMediaDescription('The best video ever'); $item->setFeedId(1); $item->setStatus(0); $item->setRtl(true); @@ -148,6 +154,8 @@ class ItemTest extends TestCase 'body' => '
this is a test', 'enclosureMime' => 'audio/ogg', 'enclosureLink' => 'enclink', + 'mediaThumbnail' => 'https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'feedId' => 1, 'unread' => true, 'starred' => true, @@ -173,6 +181,8 @@ class ItemTest extends TestCase $item->setBody('body'); $item->setEnclosureMime('audio/ogg'); $item->setEnclosureLink('enclink'); + $item->setMediaThumbnail('https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg'); + $item->setMediaDescription('The best video ever'); $item->setFeedId(1); $item->setRtl(true); $item->setStatus(0); @@ -195,6 +205,8 @@ class ItemTest extends TestCase 'body' => 'body', 'enclosureMime' => 'audio/ogg', 'enclosureLink' => 'enclink', + 'mediaThumbnail' => 'https://i2.ytimg.com/vi/E6B3uvhrcQk/hqdefault.jpg', + 'mediaDescription' => 'The best video ever', 'unread' => false, 'starred' => true, 'feedLink' => 'http://test', @@ -257,6 +269,8 @@ class ItemTest extends TestCase 'body' => $item->getBody(), 'enclosureMime' => $item->getEnclosureMime(), 'enclosureLink' => $item->getEnclosureLink(), + 'mediaThumbnail' => $item->getMediaThumbnail(), + 'mediaDescription' => $item->getMediaDescription(), 'unread' => $item->isUnread(), 'starred' => $item->isStarred(), 'rtl' => $item->getRtl() @@ -282,6 +296,8 @@ class ItemTest extends TestCase 'body' => $item->getBody(), 'enclosureMime' => $item->getEnclosureMime(), 'enclosureLink' => $item->getEnclosureLink(), + 'mediaThumbnail' => $item->getMediaThumbnail(), + 'mediaDescription' => $item->getMediaDescription(), 'unread' => $item->isUnread(), 'starred' => $item->isStarred(), 'rtl' => $item->getRtl() -- cgit v1.2.3