From 0d6feff34d0c40001522906aecf58f64a525a160 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 17 Sep 2023 16:51:29 +0200 Subject: [PATCH] feat: support for embeds in the feed rss endpoints --- build.gradle | 1 + .../me/kavin/piped/utils/ChannelHelpers.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/build.gradle b/build.gradle index 943886c..ea1a8e8 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-annotations:2.15.2' implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' implementation 'com.rometools:rome:2.1.0' + implementation 'com.rometools:rome-modules:2.1.0' implementation 'org.jsoup:jsoup:1.16.1' implementation 'io.activej:activej-common:5.5' implementation 'io.activej:activej-http:5.5' diff --git a/src/main/java/me/kavin/piped/utils/ChannelHelpers.java b/src/main/java/me/kavin/piped/utils/ChannelHelpers.java index 5f0a8e0..a6495f5 100644 --- a/src/main/java/me/kavin/piped/utils/ChannelHelpers.java +++ b/src/main/java/me/kavin/piped/utils/ChannelHelpers.java @@ -1,5 +1,7 @@ package me.kavin.piped.utils; +import com.rometools.modules.mediarss.MediaEntryModuleImpl; +import com.rometools.modules.mediarss.types.*; import com.rometools.rome.feed.synd.*; import me.kavin.piped.consts.Constants; import me.kavin.piped.utils.obj.db.Channel; @@ -11,6 +13,7 @@ import org.hibernate.StatelessSession; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.Collections; import java.util.Date; @@ -79,6 +82,7 @@ public class ChannelHelpers { entry.setAuthors(Collections.singletonList(person)); entry.setLink(Constants.FRONTEND_URL + "/watch?v=" + video.getId()); entry.setUri(Constants.FRONTEND_URL + "/watch?v=" + video.getId()); + entry.setTitle(video.getTitle()); entry.setPublishedDate(new Date(video.getUploaded())); @@ -95,6 +99,23 @@ public class ChannelHelpers { entry.setContents(List.of(thumbnail, content)); + // the Media RSS content for embedding videos starts here + // see https://www.rssboard.org/media-rss#media-content + + String playerUrl = Constants.FRONTEND_URL + "/embed/" + video.getId(); + MediaContent media = new MediaContent(new PlayerReference(URI.create(playerUrl))); + media.setDuration(video.getDuration()); + + Metadata metadata = new Metadata(); + metadata.setTitle(video.getTitle()); + Thumbnail metadataThumbnail = new Thumbnail(URI.create(video.getThumbnail())); + metadata.setThumbnail(new Thumbnail[]{ metadataThumbnail }); + media.setMetadata(metadata); + + MediaEntryModuleImpl mediaModule = new MediaEntryModuleImpl(); + mediaModule.setMediaContents(new MediaContent[]{ media }); + entry.getModules().add(mediaModule); + return entry; } }