Skip to content

Commit 7b9e0ac

Browse files
committed
feat: add channel info to rss feed if no videos found
1 parent c746794 commit 7b9e0ac

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.lang3.StringUtils;
2323
import org.hibernate.Session;
2424
import org.hibernate.StatelessSession;
25+
import org.schabi.newpipe.extractor.channel.ChannelInfo;
2526

2627
import java.io.IOException;
2728
import java.util.*;
@@ -236,11 +237,11 @@ public static byte[] unauthenticatedFeedResponse(String[] channelIds) throws Exc
236237

237238
public static byte[] unauthenticatedFeedResponseRSS(String[] channelIds) throws Exception {
238239

239-
Set<String> filtered = Arrays.stream(channelIds)
240+
Set<String> filteredChannels = Arrays.stream(channelIds)
240241
.filter(ChannelHelpers::isValidId)
241242
.collect(Collectors.toUnmodifiableSet());
242243

243-
if (filtered.isEmpty())
244+
if (filteredChannels.isEmpty())
244245
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("No valid channel IDs provided"));
245246

246247
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
@@ -254,7 +255,7 @@ public static byte[] unauthenticatedFeedResponseRSS(String[] channelIds) throws
254255

255256
criteria.select(root)
256257
.where(cb.and(
257-
root.get("channel").get("id").in(filtered)
258+
root.get("channel").get("id").in(filteredChannels)
258259
))
259260
.orderBy(cb.desc(root.get("uploaded")));
260261

@@ -276,22 +277,28 @@ public static byte[] unauthenticatedFeedResponseRSS(String[] channelIds) throws
276277
var channel = video.getChannel();
277278
SyndEntry entry = ChannelHelpers.createEntry(video, channel);
278279
entries.add(entry);
280+
}
281+
282+
if (filteredChannels.size() == 1) {
283+
if (!videos.isEmpty()) {
284+
ChannelHelpers.addChannelInformation(feed, videos.get(0).getChannel());
285+
} else {
286+
String channelId = filteredChannels.stream().findFirst().get();
287+
final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);
288+
var channel = DatabaseHelper.getChannelFromId(channelId);
279289

280-
if (filtered.size() == 1) {
281-
feed.setTitle("Piped - " + channel.getUploader());
282-
SyndImage channelIcon = new SyndImageImpl();
283-
channelIcon.setLink(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId());
284-
channelIcon.setTitle(channel.getUploader());
285-
channelIcon.setUrl(rewriteURL(channel.getUploaderAvatar()));
286-
feed.setIcon(channelIcon);
287-
feed.setImage(channelIcon);
290+
if (channel == null) channel = new Channel();
291+
292+
ChannelHelpers.updateChannel(s, channel, StringUtils.abbreviate(info.getName(), 100), info.getAvatars().isEmpty() ? null : info.getAvatars().getLast().getUrl(), info.isVerified());
293+
294+
ChannelHelpers.addChannelInformation(feed, channel);
288295
}
289296
}
290297

291298
feed.setEntries(entries);
292299

293-
updateSubscribedTime(filtered);
294-
addMissingChannels(filtered);
300+
updateSubscribedTime(filteredChannels);
301+
addMissingChannels(filteredChannels);
295302

296303
return new SyndFeedOutput().outputString(feed).getBytes(UTF_8);
297304
}

src/main/java/me/kavin/piped/utils/ChannelHelpers.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,14 @@ public static SyndEntry createEntry(Video video, Channel channel) {
118118

119119
return entry;
120120
}
121+
122+
public static void addChannelInformation(SyndFeed feed, Channel channel) {
123+
feed.setTitle("Piped - " + channel.getUploader());
124+
SyndImage channelIcon = new SyndImageImpl();
125+
channelIcon.setLink(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId());
126+
channelIcon.setTitle(channel.getUploader());
127+
channelIcon.setUrl(rewriteURL(channel.getUploaderAvatar()));
128+
feed.setIcon(channelIcon);
129+
feed.setImage(channelIcon);
130+
}
121131
}

0 commit comments

Comments
 (0)