Skip to content

Commit

Permalink
Merge pull request #706 from Bnyro/rss-embed
Browse files Browse the repository at this point in the history
feat: support for embeds in the feed rss endpoints
  • Loading branch information
Bnyro authored Sep 19, 2023
2 parents 629a6ce + 0d6feff commit ae7684f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/me/kavin/piped/utils/ChannelHelpers.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +13,7 @@

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -79,6 +82,7 @@ public static SyndEntry createEntry(Video video, Channel channel) {
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()));

Expand All @@ -95,6 +99,23 @@ public static SyndEntry createEntry(Video video, Channel channel) {

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

0 comments on commit ae7684f

Please sign in to comment.