feat: support for embeds in the feed rss endpoints

This commit is contained in:
Bnyro 2023-09-17 16:51:29 +02:00
parent bcfad9988d
commit 0d6feff34d
2 changed files with 22 additions and 0 deletions

View File

@ -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'

View File

@ -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;
}
}