mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-29 08:20:30 +05:30
Add lbryId to streams response.
This commit is contained in:
parent
7cd01807fd
commit
0c4856933b
@ -18,6 +18,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
@ -109,9 +110,18 @@ public class ResponseHelper {
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CompletableFuture<String> futureLbryId = CompletableFuture.supplyAsync(() -> {
|
||||||
|
try {
|
||||||
|
return getLBRYId(videoId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ExceptionUtils.rethrow(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return getLBRYStreamURL(videoId);
|
return getLBRYStreamURL(futureLbryId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExceptionUtils.rethrow(e);
|
ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
@ -183,7 +193,7 @@ public class ResponseHelper {
|
|||||||
info.getTextualUploadDate(), info.getUploaderName(), info.getUploaderUrl().substring(23),
|
info.getTextualUploadDate(), info.getUploaderName(), info.getUploaderUrl().substring(23),
|
||||||
rewriteURL(info.getUploaderAvatarUrl()), rewriteURL(info.getThumbnailUrl()), info.getDuration(),
|
rewriteURL(info.getUploaderAvatarUrl()), rewriteURL(info.getThumbnailUrl()), info.getDuration(),
|
||||||
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), audioStreams, videoStreams,
|
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), audioStreams, videoStreams,
|
||||||
relatedStreams, subtitles, livestream, hls);
|
relatedStreams, subtitles, livestream, hls, futureLbryId.get());
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(streams);
|
return Constants.mapper.writeValueAsBytes(streams);
|
||||||
|
|
||||||
@ -904,12 +914,17 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String getLBRYStreamURL(String videoId) throws IOException, InterruptedException {
|
private static final String getLBRYId(String videoId) throws IOException, InterruptedException {
|
||||||
|
return new JSONObject(Constants.h2client.send(HttpRequest
|
||||||
String lbryId = new JSONObject(Constants.h2client.send(HttpRequest
|
|
||||||
.newBuilder(URI.create("https://api.lbry.com/yt/resolve?video_ids=" + URLUtils.silentEncode(videoId)))
|
.newBuilder(URI.create("https://api.lbry.com/yt/resolve?video_ids=" + URLUtils.silentEncode(videoId)))
|
||||||
.setHeader("User-Agent", Constants.USER_AGENT).build(), BodyHandlers.ofString()).body())
|
.setHeader("User-Agent", Constants.USER_AGENT).build(), BodyHandlers.ofString()).body())
|
||||||
.getJSONObject("data").getJSONObject("videos").optString(videoId);
|
.getJSONObject("data").getJSONObject("videos").optString(videoId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String getLBRYStreamURL(CompletableFuture<String> futureLbryId)
|
||||||
|
throws IOException, InterruptedException, ExecutionException {
|
||||||
|
|
||||||
|
String lbryId = futureLbryId.get();
|
||||||
|
|
||||||
if (!lbryId.isEmpty())
|
if (!lbryId.isEmpty())
|
||||||
return new JSONObject(Constants.h2client.send(HttpRequest
|
return new JSONObject(Constants.h2client.send(HttpRequest
|
||||||
|
@ -6,7 +6,7 @@ import me.kavin.piped.consts.Constants;
|
|||||||
|
|
||||||
public class Streams {
|
public class Streams {
|
||||||
|
|
||||||
public String title, description, uploadDate, uploader, uploaderUrl, uploaderAvatar, thumbnailUrl, hls;
|
public String title, description, uploadDate, uploader, uploaderUrl, uploaderAvatar, thumbnailUrl, hls, lbryId;
|
||||||
|
|
||||||
public long duration, views, likes, dislikes;
|
public long duration, views, likes, dislikes;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public class Streams {
|
|||||||
public Streams(String title, String description, String uploadDate, String uploader, String uploaderUrl,
|
public Streams(String title, String description, String uploadDate, String uploader, String uploaderUrl,
|
||||||
String uploaderAvatar, String thumbnailUrl, long duration, long views, long likes, long dislikes,
|
String uploaderAvatar, String thumbnailUrl, long duration, long views, long likes, long dislikes,
|
||||||
List<PipedStream> audioStreams, List<PipedStream> videoStreams, List<StreamItem> relatedStreams,
|
List<PipedStream> audioStreams, List<PipedStream> videoStreams, List<StreamItem> relatedStreams,
|
||||||
List<Subtitle> subtitles, boolean livestream, String hls) {
|
List<Subtitle> subtitles, boolean livestream, String hls, String lbryId) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.uploadDate = uploadDate;
|
this.uploadDate = uploadDate;
|
||||||
@ -41,5 +41,6 @@ public class Streams {
|
|||||||
this.subtitles = subtitles;
|
this.subtitles = subtitles;
|
||||||
this.livestream = livestream;
|
this.livestream = livestream;
|
||||||
this.hls = hls;
|
this.hls = hls;
|
||||||
|
this.lbryId = lbryId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user