Add lbryId to streams response.

This commit is contained in:
FireMasterK 2021-08-08 16:47:58 +05:30
parent 7cd01807fd
commit 0c4856933b
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 23 additions and 7 deletions

View file

@ -18,6 +18,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.persistence.criteria.CriteriaBuilder;
@ -109,9 +110,18 @@ public class ResponseHelper {
return null;
});
CompletableFuture<String> futureLbryId = CompletableFuture.supplyAsync(() -> {
try {
return getLBRYId(videoId);
} catch (Exception e) {
ExceptionUtils.rethrow(e);
}
return null;
});
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
try {
return getLBRYStreamURL(videoId);
return getLBRYStreamURL(futureLbryId);
} catch (Exception e) {
ExceptionUtils.rethrow(e);
}
@ -183,7 +193,7 @@ public class ResponseHelper {
info.getTextualUploadDate(), info.getUploaderName(), info.getUploaderUrl().substring(23),
rewriteURL(info.getUploaderAvatarUrl()), rewriteURL(info.getThumbnailUrl()), info.getDuration(),
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), audioStreams, videoStreams,
relatedStreams, subtitles, livestream, hls);
relatedStreams, subtitles, livestream, hls, futureLbryId.get());
return Constants.mapper.writeValueAsBytes(streams);
@ -904,12 +914,17 @@ public class ResponseHelper {
}
private static final String getLBRYStreamURL(String videoId) throws IOException, InterruptedException {
String lbryId = new JSONObject(Constants.h2client.send(HttpRequest
private static final String getLBRYId(String videoId) throws IOException, InterruptedException {
return new JSONObject(Constants.h2client.send(HttpRequest
.newBuilder(URI.create("https://api.lbry.com/yt/resolve?video_ids=" + URLUtils.silentEncode(videoId)))
.setHeader("User-Agent", Constants.USER_AGENT).build(), BodyHandlers.ofString()).body())
.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())
return new JSONObject(Constants.h2client.send(HttpRequest

View file

@ -6,7 +6,7 @@ import me.kavin.piped.consts.Constants;
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;
@ -23,7 +23,7 @@ public class Streams {
public Streams(String title, String description, String uploadDate, String uploader, String uploaderUrl,
String uploaderAvatar, String thumbnailUrl, long duration, long views, long likes, long dislikes,
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.description = description;
this.uploadDate = uploadDate;
@ -41,5 +41,6 @@ public class Streams {
this.subtitles = subtitles;
this.livestream = livestream;
this.hls = hls;
this.lbryId = lbryId;
}
}