From e19bfaad9101e52bafb8fda8582ca9376f3d0f1d Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 9 Jan 2023 18:58:48 +0100 Subject: [PATCH] Show all available info as feed content --- .../server/handlers/auth/FeedHandlers.java | 27 ++-------------- .../me/kavin/piped/utils/ChannelHelpers.java | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java b/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java index 4ddda1e..bb29a73 100644 --- a/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java @@ -179,19 +179,7 @@ public class FeedHandlers { .stream() .map(video -> { var channel = video.getChannel(); - SyndEntry entry = new SyndEntryImpl(); - - SyndPerson person = new SyndPersonImpl(); - person.setName(channel.getUploader()); - person.setUri(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId()); - - 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())); - + SyndEntry entry = ChannelHelpers.createEntry(video, channel); return entry; }).toList(); @@ -286,18 +274,7 @@ public class FeedHandlers { for (Video video : videos) { var channel = video.getChannel(); - SyndEntry entry = new SyndEntryImpl(); - - SyndPerson person = new SyndPersonImpl(); - person.setName(channel.getUploader()); - person.setUri(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId()); - - 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())); + SyndEntry entry = ChannelHelpers.createEntry(video, channel); entries.add(entry); if (filtered.size() == 1) { diff --git a/src/main/java/me/kavin/piped/utils/ChannelHelpers.java b/src/main/java/me/kavin/piped/utils/ChannelHelpers.java index a8cbbb3..f513caa 100644 --- a/src/main/java/me/kavin/piped/utils/ChannelHelpers.java +++ b/src/main/java/me/kavin/piped/utils/ChannelHelpers.java @@ -2,13 +2,25 @@ package me.kavin.piped.utils; import me.kavin.piped.consts.Constants; import me.kavin.piped.utils.obj.db.Channel; +import me.kavin.piped.utils.obj.db.Video; import okhttp3.Request; import org.apache.commons.lang3.StringUtils; import org.hibernate.StatelessSession; +import com.rometools.rome.feed.synd.SyndContent; +import com.rometools.rome.feed.synd.SyndContentImpl; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndEntryImpl; +import com.rometools.rome.feed.synd.SyndPerson; +import com.rometools.rome.feed.synd.SyndPersonImpl; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; public class ChannelHelpers { @@ -59,4 +71,24 @@ public class ChannelHelpers { } } + public static SyndEntry createEntry(Video video, Channel channel) { + SyndEntry entry = new SyndEntryImpl(); + SyndPerson person = new SyndPersonImpl(); + SyndContent content = new SyndContentImpl(); + + person.setName(channel.getUploader()); + person.setUri(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId()); + 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())); + + String contentText = String.format("Title: %s\nViews: %d\nId: %s\nDuration: %d\nIs YT Shorts: %b\nThumbnail: %s", video.getTitle(), video.getViews(), video.getId(), video.getDuration(), video.isShort(), video.getThumbnail()); + content.setValue(contentText); + + entry.setContents(List.of(content)); + + return entry; + } }