mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-29 08:20:30 +05:30
add playlists and small changes.
This commit is contained in:
parent
4986fe864c
commit
208deffbd1
@ -6,7 +6,7 @@ plugins {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://repo.spring.io/milestone' }
|
maven { url 'https://repo.spring.io/milestone' }
|
||||||
jcenter()
|
jcenter()
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,9 +17,9 @@ dependencies {
|
|||||||
implementation 'it.unimi.dsi:fastutil:8.4.2'
|
implementation 'it.unimi.dsi:fastutil:8.4.2'
|
||||||
implementation 'commons-codec:commons-codec:1.15'
|
implementation 'commons-codec:commons-codec:1.15'
|
||||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.66'
|
implementation 'org.bouncycastle:bcprov-jdk15on:1.66'
|
||||||
implementation 'org.mongodb:mongo-java-driver:3.12.7'
|
implementation 'org.mongodb:mongodb-driver-sync:4.1.1'
|
||||||
implementation 'io.projectreactor.netty:reactor-netty:1.0.1'
|
implementation 'io.projectreactor.netty:reactor-netty:1.0.1'
|
||||||
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.20.2'
|
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.20.8'
|
||||||
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
|
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-core:2.6.3'
|
implementation 'com.fasterxml.jackson.core:jackson-core:2.6.3'
|
||||||
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.6.3'
|
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.6.3'
|
||||||
|
@ -109,6 +109,32 @@ public class Main {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
routes.get("/playlists/{playlistId}", (req, res) -> {
|
||||||
|
|
||||||
|
try {
|
||||||
|
return writeResponse(res, ResponseHelper.playlistResponse(req.param("playlistId")), 200,
|
||||||
|
"public, max-age=600");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
routes.get("/nextpage/playlists/{playlistId}", (req, res) -> {
|
||||||
|
|
||||||
|
QueryStringDecoder query = new QueryStringDecoder(req.uri());
|
||||||
|
|
||||||
|
try {
|
||||||
|
return writeResponse(res, ResponseHelper.playlistPageResponse(req.param("playlistId"),
|
||||||
|
query.parameters().get("url").get(0)), 200, "public, max-age=3600");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return writeResponse(res, ExceptionUtils.getStackTrace(e), 500, "private");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
routes.get("/suggestions", (req, res) -> {
|
routes.get("/suggestions", (req, res) -> {
|
||||||
|
|
||||||
QueryStringDecoder query = new QueryStringDecoder(req.uri());
|
QueryStringDecoder query = new QueryStringDecoder(req.uri());
|
||||||
|
@ -22,6 +22,7 @@ import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
|
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
|
||||||
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
||||||
import org.schabi.newpipe.extractor.search.SearchInfo;
|
import org.schabi.newpipe.extractor.search.SearchInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.Stream;
|
import org.schabi.newpipe.extractor.stream.Stream;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
@ -34,11 +35,12 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
|
|||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.obj.Channel;
|
import me.kavin.piped.utils.obj.Channel;
|
||||||
import me.kavin.piped.utils.obj.ChannelPage;
|
|
||||||
import me.kavin.piped.utils.obj.PipedStream;
|
import me.kavin.piped.utils.obj.PipedStream;
|
||||||
|
import me.kavin.piped.utils.obj.Playlist;
|
||||||
import me.kavin.piped.utils.obj.SearchResults;
|
import me.kavin.piped.utils.obj.SearchResults;
|
||||||
import me.kavin.piped.utils.obj.StreamItem;
|
import me.kavin.piped.utils.obj.StreamItem;
|
||||||
import me.kavin.piped.utils.obj.Streams;
|
import me.kavin.piped.utils.obj.Streams;
|
||||||
|
import me.kavin.piped.utils.obj.StreamsPage;
|
||||||
import me.kavin.piped.utils.obj.Subtitle;
|
import me.kavin.piped.utils.obj.Subtitle;
|
||||||
import me.kavin.piped.utils.obj.search.SearchItem;
|
import me.kavin.piped.utils.obj.search.SearchItem;
|
||||||
import me.kavin.piped.utils.obj.search.SearchStream;
|
import me.kavin.piped.utils.obj.search.SearchStream;
|
||||||
@ -82,7 +84,7 @@ public class ResponseHelper {
|
|||||||
final String lbryURL = futureLBRY.get();
|
final String lbryURL = futureLBRY.get();
|
||||||
|
|
||||||
if (lbryURL != null)
|
if (lbryURL != null)
|
||||||
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4"));
|
videoStreams.add(new PipedStream(lbryURL, "MP4", "LBRY", "video/mp4", false));
|
||||||
|
|
||||||
String hls = null;
|
String hls = null;
|
||||||
boolean livestream = false;
|
boolean livestream = false;
|
||||||
@ -108,14 +110,14 @@ public class ResponseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
|
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
|
||||||
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType())));
|
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true)));
|
||||||
info.getVideoStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
|
info.getVideoStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
|
||||||
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType())));
|
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), false)));
|
||||||
|
|
||||||
info.getAudioStreams()
|
info.getAudioStreams()
|
||||||
.forEach(stream -> audioStreams
|
.forEach(stream -> audioStreams
|
||||||
.add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
|
.add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
|
||||||
stream.getAverageBitrate() + " kbps", stream.getFormat().getMimeType())));
|
stream.getAverageBitrate() + " kbps", stream.getFormat().getMimeType(), false)));
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
@ -123,7 +125,7 @@ public class ResponseHelper {
|
|||||||
StreamInfoItem item = (StreamInfoItem) o;
|
StreamInfoItem item = (StreamInfoItem) o;
|
||||||
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
||||||
item.getDuration(), item.getViewCount()));
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
});
|
});
|
||||||
|
|
||||||
final Streams streams = new Streams(info.getName(), info.getDescription().getContent(),
|
final Streams streams = new Streams(info.getName(), info.getDescription().getContent(),
|
||||||
@ -147,7 +149,7 @@ public class ResponseHelper {
|
|||||||
StreamInfoItem item = o;
|
StreamInfoItem item = o;
|
||||||
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
||||||
item.getDuration(), item.getViewCount()));
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
});
|
});
|
||||||
|
|
||||||
String nextpage = info.hasNextPage() ? info.getNextPage().getUrl() : null;
|
String nextpage = info.hasNextPage() ? info.getNextPage().getUrl() : null;
|
||||||
@ -171,14 +173,14 @@ public class ResponseHelper {
|
|||||||
StreamInfoItem item = o;
|
StreamInfoItem item = o;
|
||||||
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
||||||
item.getDuration(), item.getViewCount()));
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
});
|
});
|
||||||
|
|
||||||
String nextpage = page.hasNextPage() ? page.getNextPage().getUrl() : null;
|
String nextpage = page.hasNextPage() ? page.getNextPage().getUrl() : null;
|
||||||
|
|
||||||
final ChannelPage channelpage = new ChannelPage(nextpage, relatedStreams);
|
final StreamsPage streamspage = new StreamsPage(nextpage, relatedStreams);
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsString(channelpage);
|
return Constants.mapper.writeValueAsString(streamspage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,12 +198,59 @@ public class ResponseHelper {
|
|||||||
StreamInfoItem item = o;
|
StreamInfoItem item = o;
|
||||||
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
||||||
item.getDuration(), item.getViewCount()));
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
});
|
});
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsString(relatedStreams);
|
return Constants.mapper.writeValueAsString(relatedStreams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String playlistResponse(String playlistId)
|
||||||
|
throws IOException, ExtractionException, InterruptedException {
|
||||||
|
|
||||||
|
final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
|
||||||
|
|
||||||
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
info.getRelatedItems().forEach(o -> {
|
||||||
|
StreamInfoItem item = o;
|
||||||
|
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
||||||
|
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
||||||
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
|
});
|
||||||
|
|
||||||
|
String nextpage = info.hasNextPage() ? info.getNextPage().getUrl() : null;
|
||||||
|
|
||||||
|
final Playlist playlist = new Playlist(info.getName(), rewriteURL(info.getThumbnailUrl()),
|
||||||
|
rewriteURL(info.getBannerUrl()), nextpage, info.getUploaderName(), info.getUploaderUrl().substring(23),
|
||||||
|
rewriteURL(info.getUploaderAvatarUrl()), (int) info.getStreamCount(), relatedStreams);
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsString(playlist);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String playlistPageResponse(String playlistId, String url)
|
||||||
|
throws IOException, ExtractionException, InterruptedException {
|
||||||
|
|
||||||
|
InfoItemsPage<StreamInfoItem> page = PlaylistInfo.getMoreItems(Constants.YOUTUBE_SERVICE,
|
||||||
|
"https://www.youtube.com/playlist?list=" + playlistId, new Page(url));
|
||||||
|
|
||||||
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
page.getItems().forEach(o -> {
|
||||||
|
StreamInfoItem item = o;
|
||||||
|
relatedStreams.add(new StreamItem(item.getUrl().substring(23), item.getName(),
|
||||||
|
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), item.getUploaderUrl().substring(23),
|
||||||
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
|
});
|
||||||
|
|
||||||
|
String nextpage = page.hasNextPage() ? page.getNextPage().getUrl() : null;
|
||||||
|
|
||||||
|
final StreamsPage streamspage = new StreamsPage(nextpage, relatedStreams);
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsString(streamspage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static final String suggestionsResponse(String query)
|
public static final String suggestionsResponse(String query)
|
||||||
throws JsonProcessingException, IOException, ExtractionException {
|
throws JsonProcessingException, IOException, ExtractionException {
|
||||||
|
|
||||||
@ -273,6 +322,12 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String registerResponse(String user, String pass) throws IOException {
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsString(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static final String getLBRYStreamURL(String videoId) throws IOException, InterruptedException {
|
private static final String getLBRYStreamURL(String videoId) throws IOException, InterruptedException {
|
||||||
|
|
||||||
String lbryId = new JSONObject(Constants.h2client.send(HttpRequest
|
String lbryId = new JSONObject(Constants.h2client.send(HttpRequest
|
||||||
|
@ -3,11 +3,13 @@ package me.kavin.piped.utils.obj;
|
|||||||
public class PipedStream {
|
public class PipedStream {
|
||||||
|
|
||||||
public String url, format, quality, mimeType;
|
public String url, format, quality, mimeType;
|
||||||
|
public boolean videoOnly;
|
||||||
|
|
||||||
public PipedStream(String url, String format, String quality, String mimeType) {
|
public PipedStream(String url, String format, String quality, String mimeType, boolean videoOnly) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
|
this.videoOnly = videoOnly;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
src/main/java/me/kavin/piped/utils/obj/Playlist.java
Normal file
23
src/main/java/me/kavin/piped/utils/obj/Playlist.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package me.kavin.piped.utils.obj;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Playlist {
|
||||||
|
|
||||||
|
public String name, thumbnailUrl, bannerUrl, nextpage, uploader, uploaderUrl, uploaderAvatar;
|
||||||
|
public int videos;
|
||||||
|
public List<StreamItem> relatedStreams;
|
||||||
|
|
||||||
|
public Playlist(String name, String thumbnailUrl, String bannerUrl, String nextpage, String uploader,
|
||||||
|
String uploaderUrl, String uploaderAvatar, int videos, List<StreamItem> relatedStreams) {
|
||||||
|
this.name = name;
|
||||||
|
this.thumbnailUrl = thumbnailUrl;
|
||||||
|
this.bannerUrl = bannerUrl;
|
||||||
|
this.nextpage = nextpage;
|
||||||
|
this.videos = videos;
|
||||||
|
this.uploader = uploader;
|
||||||
|
this.uploaderUrl = uploaderUrl;
|
||||||
|
this.uploaderAvatar = uploaderAvatar;
|
||||||
|
this.relatedStreams = relatedStreams;
|
||||||
|
}
|
||||||
|
}
|
@ -2,16 +2,17 @@ package me.kavin.piped.utils.obj;
|
|||||||
|
|
||||||
public class StreamItem {
|
public class StreamItem {
|
||||||
|
|
||||||
public String url, title, thumbnail, uploaderName, uploaderUrl;
|
public String url, title, thumbnail, uploaderName, uploaderUrl, uploadedDate;
|
||||||
public long duration, views;
|
public long duration, views;
|
||||||
|
|
||||||
public StreamItem(String url, String title, String thumbnail, String uploaderName, String uploaderUrl,
|
public StreamItem(String url, String title, String thumbnail, String uploaderName, String uploaderUrl,
|
||||||
long duration, long views) {
|
String uploadedDate, long duration, long views) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.thumbnail = thumbnail;
|
this.thumbnail = thumbnail;
|
||||||
this.uploaderName = uploaderName;
|
this.uploaderName = uploaderName;
|
||||||
this.uploaderUrl = uploaderUrl;
|
this.uploaderUrl = uploaderUrl;
|
||||||
|
this.uploadedDate = uploadedDate;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.views = views;
|
this.views = views;
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package me.kavin.piped.utils.obj;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChannelPage {
|
public class StreamsPage {
|
||||||
|
|
||||||
public String nextpage;
|
public String nextpage;
|
||||||
public List<StreamItem> relatedStreams;
|
public List<StreamItem> relatedStreams;
|
||||||
|
|
||||||
public ChannelPage(String nextpage, List<StreamItem> relatedStreams) {
|
public StreamsPage(String nextpage, List<StreamItem> relatedStreams) {
|
||||||
this.nextpage = nextpage;
|
this.nextpage = nextpage;
|
||||||
this.relatedStreams = relatedStreams;
|
this.relatedStreams = relatedStreams;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user