mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
commit
e8686c3e97
2 changed files with 48 additions and 25 deletions
|
@ -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,19 +274,18 @@ 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) {
|
||||
feed.setTitle(channel.getUploader());
|
||||
SyndImage channelIcon = new SyndImageImpl();
|
||||
channelIcon.setLink(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId());
|
||||
channelIcon.setTitle(channel.getUploader());
|
||||
channelIcon.setUrl(channel.getUploaderAvatar());
|
||||
feed.setIcon(channelIcon);
|
||||
feed.setImage(channelIcon);
|
||||
}
|
||||
}
|
||||
|
||||
feed.setEntries(entries);
|
||||
|
|
|
@ -2,13 +2,24 @@ 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.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class ChannelHelpers {
|
||||
|
||||
|
@ -59,4 +70,29 @@ public class ChannelHelpers {
|
|||
}
|
||||
}
|
||||
|
||||
public static SyndEntry createEntry(Video video, Channel channel) {
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
SyndPerson person = new SyndPersonImpl();
|
||||
SyndContent content = new SyndContentImpl();
|
||||
SyndContent thumbnail = 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", video.getTitle(), video.getViews(), video.getId(), video.getDuration(), video.isShort());
|
||||
content.setValue(contentText);
|
||||
|
||||
String thumbnailContent = String.format("<a href=\"%s\"><img src=\"%s\"/></a>", Constants.FRONTEND_URL + "/watch?v=" + video.getId(), video.getThumbnail());
|
||||
thumbnail.setType("xhtml");
|
||||
thumbnail.setValue(thumbnailContent);
|
||||
|
||||
entry.setContents(List.of(thumbnail, content));
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue