Merge pull request #706 from Bnyro/rss-embed

feat: support for embeds in the feed rss endpoints
This commit is contained in:
Bnyro 2023-09-19 23:03:38 +02:00 committed by GitHub
commit ae7684fa6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
}
}