mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
parent
ac3c43b1ed
commit
5a8f5ec8d5
2 changed files with 43 additions and 0 deletions
|
@ -122,6 +122,13 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
} catch (Exception e) {
|
||||
return getErrorResponse(e);
|
||||
}
|
||||
})).map("/rss/playlists/:playlistId", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(ResponseHelper.playlistRSSResponse(request.getPathParameter("playlistId")),
|
||||
"public, s-maxage=600");
|
||||
} catch (Exception e) {
|
||||
return getErrorResponse(e);
|
||||
}
|
||||
})).map("/suggestions", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(ResponseHelper.suggestionsResponse(request.getQueryParameter("query")),
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.net.URL;
|
|||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpRequest.BodyPublishers;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -36,6 +37,12 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.rometools.rome.feed.synd.SyndEntry;
|
||||
import com.rometools.rome.feed.synd.SyndEntryImpl;
|
||||
import com.rometools.rome.feed.synd.SyndFeed;
|
||||
import com.rometools.rome.feed.synd.SyndFeedImpl;
|
||||
import com.rometools.rome.io.FeedException;
|
||||
import com.rometools.rome.io.SyndFeedOutput;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import me.kavin.piped.consts.Constants;
|
||||
|
@ -284,6 +291,35 @@ public class ResponseHelper {
|
|||
|
||||
}
|
||||
|
||||
public static final byte[] playlistRSSResponse(String playlistId)
|
||||
throws IOException, ExtractionException, InterruptedException, FeedException {
|
||||
|
||||
final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
|
||||
|
||||
final List<SyndEntry> entries = new ObjectArrayList<>();
|
||||
|
||||
SyndFeed feed = new SyndFeedImpl();
|
||||
feed.setFeedType("rss_2.0");
|
||||
feed.setTitle(info.getName());
|
||||
feed.setAuthor(info.getUploaderName());
|
||||
feed.setLink(info.getUrl());
|
||||
feed.setDescription(String.format("%s - Piped", info.getName()));
|
||||
|
||||
info.getRelatedItems().forEach(o -> {
|
||||
StreamInfoItem item = o;
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
entry.setAuthor(item.getUploaderName());
|
||||
entry.setUri(item.getUrl());
|
||||
entry.setTitle(item.getName());
|
||||
entries.add(entry);
|
||||
});
|
||||
|
||||
feed.setEntries(entries);
|
||||
|
||||
return new SyndFeedOutput().outputString(feed).getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
}
|
||||
|
||||
public static final byte[] suggestionsResponse(String query)
|
||||
throws JsonProcessingException, IOException, ExtractionException {
|
||||
|
||||
|
|
Loading…
Reference in a new issue