mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Apply fixes from Error Prone via https://lift.sonatype.com
This commit is contained in:
parent
7878693bab
commit
8f5208bf34
22 changed files with 198 additions and 195 deletions
|
@ -1,7 +1,18 @@
|
||||||
package me.kavin.piped.server.handlers;
|
package me.kavin.piped.server.handlers;
|
||||||
|
|
||||||
|
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
import static me.kavin.piped.utils.CollectionUtils.collectRelatedItems;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.*;
|
import me.kavin.piped.utils.*;
|
||||||
import me.kavin.piped.utils.obj.*;
|
import me.kavin.piped.utils.obj.*;
|
||||||
|
@ -20,25 +31,14 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
import static me.kavin.piped.utils.CollectionUtils.collectRelatedItems;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
|
||||||
|
|
||||||
public class ChannelHandlers {
|
public class ChannelHandlers {
|
||||||
public static byte[] channelResponse(String channelPath) throws Exception {
|
public static byte[] channelResponse(String channelPath) throws Exception {
|
||||||
|
|
||||||
Sentry.setExtra("channelPath", channelPath);
|
Sentry.setExtra("channelPath", channelPath);
|
||||||
|
|
||||||
final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath);
|
ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath);
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
||||||
|
|
||||||
Multithreading.runAsync(() -> info.getRelatedItems().forEach(infoItem -> {
|
Multithreading.runAsync(() -> info.getRelatedItems().forEach(infoItem -> {
|
||||||
if (
|
if (
|
||||||
|
@ -117,7 +117,7 @@ public class ChannelHandlers {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
|
@ -133,7 +133,7 @@ public class ChannelHandlers {
|
||||||
}
|
}
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final Channel channel = new Channel(info.getId(), info.getName(), rewriteURL(info.getAvatarUrl()),
|
var channel = new Channel(info.getId(), info.getName(), rewriteURL(info.getAvatarUrl()),
|
||||||
rewriteURL(info.getBannerUrl()), info.getDescription(), info.getSubscriberCount(), info.isVerified(),
|
rewriteURL(info.getBannerUrl()), info.getDescription(), info.getSubscriberCount(), info.isVerified(),
|
||||||
nextpage, relatedStreams, tabs);
|
nextpage, relatedStreams, tabs);
|
||||||
|
|
||||||
|
@ -155,15 +155,15 @@ public class ChannelHandlers {
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> info = ChannelInfo.getMoreItems(YOUTUBE_SERVICE,
|
ListExtractor.InfoItemsPage<StreamInfoItem> info = ChannelInfo.getMoreItems(YOUTUBE_SERVICE,
|
||||||
"https://youtube.com/channel/" + channelId, prevpage);
|
"https://youtube.com/channel/" + channelId, prevpage);
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = collectRelatedItems(info.getItems());
|
List<ContentItem> relatedStreams = collectRelatedItems(info.getItems());
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
final StreamsPage streamspage = new StreamsPage(nextpage, relatedStreams);
|
var streamspage = new StreamsPage(nextpage, relatedStreams);
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(streamspage);
|
return mapper.writeValueAsBytes(streamspage);
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ public class ChannelHandlers {
|
||||||
|
|
||||||
List<ContentItem> items = collectRelatedItems(info.getRelatedItems());
|
List<ContentItem> items = collectRelatedItems(info.getRelatedItems());
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
|
@ -204,7 +204,7 @@ public class ChannelHandlers {
|
||||||
|
|
||||||
var info = ChannelTabInfo.getMoreItems(YOUTUBE_SERVICE, tabHandler, prevPage);
|
var info = ChannelTabInfo.getMoreItems(YOUTUBE_SERVICE, tabHandler, prevPage);
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package me.kavin.piped.server.handlers;
|
package me.kavin.piped.server.handlers;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
import static me.kavin.piped.utils.CollectionUtils.collectRelatedItems;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
||||||
|
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import com.rometools.rome.feed.synd.SyndEntry;
|
import com.rometools.rome.feed.synd.SyndEntry;
|
||||||
import com.rometools.rome.feed.synd.SyndEntryImpl;
|
import com.rometools.rome.feed.synd.SyndEntryImpl;
|
||||||
import com.rometools.rome.feed.synd.SyndFeed;
|
import com.rometools.rome.feed.synd.SyndFeed;
|
||||||
|
@ -8,6 +16,9 @@ import com.rometools.rome.io.FeedException;
|
||||||
import com.rometools.rome.io.SyndFeedOutput;
|
import com.rometools.rome.io.SyndFeedOutput;
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.server.handlers.auth.AuthPlaylistHandlers;
|
import me.kavin.piped.server.handlers.auth.AuthPlaylistHandlers;
|
||||||
import me.kavin.piped.utils.ExceptionHandler;
|
import me.kavin.piped.utils.ExceptionHandler;
|
||||||
|
@ -22,17 +33,6 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
import static me.kavin.piped.utils.CollectionUtils.collectRelatedItems;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
|
||||||
|
|
||||||
public class PlaylistHandlers {
|
public class PlaylistHandlers {
|
||||||
public static byte[] playlistResponse(String playlistId) throws Exception {
|
public static byte[] playlistResponse(String playlistId) throws Exception {
|
||||||
|
|
||||||
|
@ -50,17 +50,17 @@ public class PlaylistHandlers {
|
||||||
|
|
||||||
Sentry.setExtra("playlistId", playlistId);
|
Sentry.setExtra("playlistId", playlistId);
|
||||||
|
|
||||||
final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
|
PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Playlist playlist = new Playlist(info.getName(), rewriteURL(info.getThumbnailUrl()),
|
var playlist = new Playlist(info.getName(), rewriteURL(info.getThumbnailUrl()),
|
||||||
rewriteURL(info.getBannerUrl()), nextpage,
|
rewriteURL(info.getBannerUrl()), nextpage,
|
||||||
info.getUploaderName().isEmpty() ? null : info.getUploaderName(),
|
info.getUploaderName().isEmpty() ? null : info.getUploaderName(),
|
||||||
substringYouTube(info.getUploaderUrl()), rewriteURL(info.getUploaderAvatarUrl()),
|
substringYouTube(info.getUploaderUrl()), rewriteURL(info.getUploaderAvatarUrl()),
|
||||||
|
@ -84,15 +84,15 @@ public class PlaylistHandlers {
|
||||||
ListExtractor.InfoItemsPage<StreamInfoItem> info = PlaylistInfo.getMoreItems(YOUTUBE_SERVICE,
|
ListExtractor.InfoItemsPage<StreamInfoItem> info = PlaylistInfo.getMoreItems(YOUTUBE_SERVICE,
|
||||||
"https://www.youtube.com/playlist?list=" + playlistId, prevpage);
|
"https://www.youtube.com/playlist?list=" + playlistId, prevpage);
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = collectRelatedItems(info.getItems());
|
List<ContentItem> relatedStreams = collectRelatedItems(info.getItems());
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
final StreamsPage streamspage = new StreamsPage(nextpage, relatedStreams);
|
var streamspage = new StreamsPage(nextpage, relatedStreams);
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(streamspage);
|
return mapper.writeValueAsBytes(streamspage);
|
||||||
|
|
||||||
|
@ -112,9 +112,9 @@ public class PlaylistHandlers {
|
||||||
private static byte[] playlistYouTubeRSSResponse(String playlistId)
|
private static byte[] playlistYouTubeRSSResponse(String playlistId)
|
||||||
throws IOException, ExtractionException, FeedException {
|
throws IOException, ExtractionException, FeedException {
|
||||||
|
|
||||||
final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
|
PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
|
||||||
|
|
||||||
final List<SyndEntry> entries = new ObjectArrayList<>();
|
List<SyndEntry> entries = new ObjectArrayList<>();
|
||||||
|
|
||||||
SyndFeed feed = new SyndFeedImpl();
|
SyndFeed feed = new SyndFeedImpl();
|
||||||
feed.setFeedType("rss_2.0");
|
feed.setFeedType("rss_2.0");
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class SearchHandlers {
|
||||||
|
|
||||||
Sentry.setExtra("query", q);
|
Sentry.setExtra("query", q);
|
||||||
|
|
||||||
final SearchInfo info = SearchInfo.getInfo(YOUTUBE_SERVICE,
|
SearchInfo info = SearchInfo.getInfo(YOUTUBE_SERVICE,
|
||||||
YOUTUBE_SERVICE.getSearchQHFactory().fromQuery(q, Collections.singletonList(filter), null));
|
YOUTUBE_SERVICE.getSearchQHFactory().fromQuery(q, Collections.singletonList(filter), null));
|
||||||
|
|
||||||
List<ContentItem> items = collectRelatedItems(info.getRelatedItems());
|
List<ContentItem> items = collectRelatedItems(info.getRelatedItems());
|
||||||
|
|
|
@ -1,11 +1,28 @@
|
||||||
package me.kavin.piped.server.handlers;
|
package me.kavin.piped.server.handlers;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
||||||
|
import static org.schabi.newpipe.extractor.NewPipe.getPreferredContentCountry;
|
||||||
|
import static org.schabi.newpipe.extractor.NewPipe.getPreferredLocalization;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonWriter;
|
import com.grack.nanojson.JsonWriter;
|
||||||
import io.sentry.ITransaction;
|
import io.sentry.ITransaction;
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.*;
|
import me.kavin.piped.utils.*;
|
||||||
import me.kavin.piped.utils.obj.*;
|
import me.kavin.piped.utils.obj.*;
|
||||||
|
@ -26,29 +43,12 @@ import org.schabi.newpipe.extractor.stream.Description;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
|
||||||
import static org.schabi.newpipe.extractor.NewPipe.getPreferredContentCountry;
|
|
||||||
import static org.schabi.newpipe.extractor.NewPipe.getPreferredLocalization;
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
|
||||||
|
|
||||||
public class StreamHandlers {
|
public class StreamHandlers {
|
||||||
public static byte[] streamsResponse(String videoId) throws Exception {
|
public static byte[] streamsResponse(String videoId) throws Exception {
|
||||||
|
|
||||||
Sentry.setExtra("videoId", videoId);
|
Sentry.setExtra("videoId", videoId);
|
||||||
|
|
||||||
final var futureStream = Multithreading.supplyAsync(() -> {
|
var futureStream = Multithreading.supplyAsync(() -> {
|
||||||
Sentry.setExtra("videoId", videoId);
|
Sentry.setExtra("videoId", videoId);
|
||||||
ITransaction transaction = Sentry.startTransaction("StreamInfo fetch", "fetch");
|
ITransaction transaction = Sentry.startTransaction("StreamInfo fetch", "fetch");
|
||||||
try {
|
try {
|
||||||
|
@ -65,7 +65,7 @@ public class StreamHandlers {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final var futureLbryId = Multithreading.supplyAsync(() -> {
|
var futureLbryId = Multithreading.supplyAsync(() -> {
|
||||||
Sentry.setExtra("videoId", videoId);
|
Sentry.setExtra("videoId", videoId);
|
||||||
try {
|
try {
|
||||||
return LbryHelper.getLBRYId(videoId);
|
return LbryHelper.getLBRYId(videoId);
|
||||||
|
@ -75,7 +75,7 @@ public class StreamHandlers {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final var futureLBRY = Multithreading.supplyAsync(() -> {
|
var futureLBRY = Multithreading.supplyAsync(() -> {
|
||||||
Sentry.setExtra("videoId", videoId);
|
Sentry.setExtra("videoId", videoId);
|
||||||
ITransaction transaction = Sentry.startTransaction("LBRY Stream fetch", "fetch");
|
ITransaction transaction = Sentry.startTransaction("LBRY Stream fetch", "fetch");
|
||||||
try {
|
try {
|
||||||
|
@ -94,7 +94,7 @@ public class StreamHandlers {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final var futureDislikeRating = Multithreading.supplyAsync(() -> {
|
var futureDislikeRating = Multithreading.supplyAsync(() -> {
|
||||||
Sentry.setExtra("videoId", videoId);
|
Sentry.setExtra("videoId", videoId);
|
||||||
ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch");
|
ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch");
|
||||||
try {
|
try {
|
||||||
|
@ -107,8 +107,8 @@ public class StreamHandlers {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
StreamInfo info = null;
|
@Var StreamInfo info = null;
|
||||||
Throwable exception = null;
|
@Var Throwable exception = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
info = futureStream.get(10, TimeUnit.SECONDS);
|
info = futureStream.get(10, TimeUnit.SECONDS);
|
||||||
|
@ -174,7 +174,7 @@ public class StreamHandlers {
|
||||||
streams.thumbnailUrl = rewriteURL(streams.thumbnailUrl);
|
streams.thumbnailUrl = rewriteURL(streams.thumbnailUrl);
|
||||||
streams.uploaderAvatar = rewriteURL(streams.uploaderAvatar);
|
streams.uploaderAvatar = rewriteURL(streams.uploaderAvatar);
|
||||||
|
|
||||||
String lbryId;
|
@Var String lbryId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
|
lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
|
||||||
|
@ -186,7 +186,7 @@ public class StreamHandlers {
|
||||||
streams.lbryId = lbryId;
|
streams.lbryId = lbryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
String lbryURL;
|
@Var String lbryURL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lbryURL = futureLBRY.get(3, TimeUnit.SECONDS);
|
lbryURL = futureLBRY.get(3, TimeUnit.SECONDS);
|
||||||
|
@ -199,7 +199,7 @@ public class StreamHandlers {
|
||||||
|
|
||||||
// Attempt to get dislikes calculating with the RYD API rating
|
// Attempt to get dislikes calculating with the RYD API rating
|
||||||
if (streams.dislikes < 0 && streams.likes >= 0) {
|
if (streams.dislikes < 0 && streams.likes >= 0) {
|
||||||
double rating;
|
@Var double rating;
|
||||||
try {
|
try {
|
||||||
rating = futureDislikeRating.get(3, TimeUnit.SECONDS);
|
rating = futureDislikeRating.get(3, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -224,7 +224,7 @@ public class StreamHandlers {
|
||||||
|
|
||||||
Streams streams = CollectionUtils.collectStreamInfo(info);
|
Streams streams = CollectionUtils.collectStreamInfo(info);
|
||||||
|
|
||||||
String lbryURL = null;
|
@Var String lbryURL = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lbryURL = futureLBRY.get(3, TimeUnit.SECONDS);
|
lbryURL = futureLBRY.get(3, TimeUnit.SECONDS);
|
||||||
|
@ -254,7 +254,7 @@ public class StreamHandlers {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String lbryId;
|
@Var String lbryId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
|
lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
|
||||||
|
@ -266,7 +266,7 @@ public class StreamHandlers {
|
||||||
|
|
||||||
// Attempt to get dislikes calculating with the RYD API rating
|
// Attempt to get dislikes calculating with the RYD API rating
|
||||||
if (streams.dislikes < 0 && streams.likes >= 0) {
|
if (streams.dislikes < 0 && streams.likes >= 0) {
|
||||||
double rating;
|
@Var double rating;
|
||||||
try {
|
try {
|
||||||
rating = futureDislikeRating.get(3, TimeUnit.SECONDS);
|
rating = futureDislikeRating.get(3, TimeUnit.SECONDS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -284,16 +284,16 @@ public class StreamHandlers {
|
||||||
|
|
||||||
public static byte[] resolveClipId(String clipId) throws Exception {
|
public static byte[] resolveClipId(String clipId) throws Exception {
|
||||||
|
|
||||||
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
||||||
getPreferredLocalization(), getPreferredContentCountry())
|
getPreferredLocalization(), getPreferredContentCountry())
|
||||||
.value("url", "https://www.youtube.com/clip/" + clipId)
|
.value("url", "https://www.youtube.com/clip/" + clipId)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
||||||
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
||||||
body, getPreferredLocalization());
|
body, getPreferredLocalization());
|
||||||
|
|
||||||
final String videoId = JsonUtils.getString(jsonResponse, "endpoint.watchEndpoint.videoId");
|
String videoId = JsonUtils.getString(jsonResponse, "endpoint.watchEndpoint.videoId");
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(new VideoResolvedResponse(videoId));
|
return mapper.writeValueAsBytes(new VideoResolvedResponse(videoId));
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ public class StreamHandlers {
|
||||||
|
|
||||||
info.getRelatedItems().forEach(comment -> {
|
info.getRelatedItems().forEach(comment -> {
|
||||||
try {
|
try {
|
||||||
String repliespage = null;
|
@Var String repliespage = null;
|
||||||
if (comment.getReplies() != null)
|
if (comment.getReplies() != null)
|
||||||
repliespage = mapper.writeValueAsString(comment.getReplies());
|
repliespage = mapper.writeValueAsString(comment.getReplies());
|
||||||
|
|
||||||
|
@ -321,13 +321,13 @@ public class StreamHandlers {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentsPage commentsItem = new CommentsPage(comments, nextpage, info.isCommentsDisabled());
|
var commentsItem = new CommentsPage(comments, nextpage, info.isCommentsDisabled());
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(commentsItem);
|
return mapper.writeValueAsBytes(commentsItem);
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ public class StreamHandlers {
|
||||||
|
|
||||||
info.getItems().forEach(comment -> {
|
info.getItems().forEach(comment -> {
|
||||||
try {
|
try {
|
||||||
String repliespage = null;
|
@Var String repliespage = null;
|
||||||
if (comment.getReplies() != null)
|
if (comment.getReplies() != null)
|
||||||
repliespage = mapper.writeValueAsString(comment.getReplies());
|
repliespage = mapper.writeValueAsString(comment.getReplies());
|
||||||
|
|
||||||
|
@ -359,13 +359,13 @@ public class StreamHandlers {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
String nextpage = null;
|
@Var String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
nextpage = mapper.writeValueAsString(page);
|
nextpage = mapper.writeValueAsString(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentsPage commentsItem = new CommentsPage(comments, nextpage, false);
|
var commentsItem = new CommentsPage(comments, nextpage, false);
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(commentsItem);
|
return mapper.writeValueAsBytes(commentsItem);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class TrendingHandlers {
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
KioskInfo info = KioskInfo.getInfo(extractor);
|
KioskInfo info = KioskInfo.getInfo(extractor);
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(relatedStreams);
|
return mapper.writeValueAsBytes(relatedStreams);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
package me.kavin.piped.server.handlers.auth;
|
package me.kavin.piped.server.handlers.auth;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
||||||
|
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import com.rometools.rome.feed.synd.SyndEntry;
|
import com.rometools.rome.feed.synd.SyndEntry;
|
||||||
import com.rometools.rome.feed.synd.SyndEntryImpl;
|
import com.rometools.rome.feed.synd.SyndEntryImpl;
|
||||||
import com.rometools.rome.feed.synd.SyndFeed;
|
import com.rometools.rome.feed.synd.SyndFeed;
|
||||||
|
@ -10,6 +17,9 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import jakarta.persistence.criteria.JoinType;
|
import jakarta.persistence.criteria.JoinType;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.*;
|
import me.kavin.piped.utils.*;
|
||||||
import me.kavin.piped.utils.obj.ContentItem;
|
import me.kavin.piped.utils.obj.ContentItem;
|
||||||
|
@ -29,16 +39,6 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
|
||||||
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
|
||||||
|
|
||||||
public class AuthPlaylistHandlers {
|
public class AuthPlaylistHandlers {
|
||||||
public static byte[] playlistPipedResponse(String playlistId) throws Exception {
|
public static byte[] playlistPipedResponse(String playlistId) throws Exception {
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class AuthPlaylistHandlers {
|
||||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
.put("error", "Playlist not found"));
|
.put("error", "Playlist not found"));
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = new ObjectArrayList<>();
|
List<ContentItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
var videos = playlistVideosCompletableFuture.get();
|
var videos = playlistVideosCompletableFuture.get();
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class AuthPlaylistHandlers {
|
||||||
video.getDuration(), -1, -1, channel.isVerified(), false));
|
video.getDuration(), -1, -1, channel.isVerified(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Playlist playlist = new Playlist(pl.getName(), rewriteURL(pl.getThumbnail()), null, null, pl.getOwner().getUsername(),
|
var playlist = new Playlist(pl.getName(), rewriteURL(pl.getThumbnail()), null, null, pl.getOwner().getUsername(),
|
||||||
null, null, videos.size(), relatedStreams);
|
null, null, videos.size(), relatedStreams);
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(playlist);
|
return mapper.writeValueAsBytes(playlist);
|
||||||
|
@ -86,7 +86,7 @@ public class AuthPlaylistHandlers {
|
||||||
|
|
||||||
var pl = playlistCompletableFuture.get();
|
var pl = playlistCompletableFuture.get();
|
||||||
|
|
||||||
final List<SyndEntry> entries = new ObjectArrayList<>();
|
List<SyndEntry> entries = new ObjectArrayList<>();
|
||||||
|
|
||||||
SyndFeed feed = new SyndFeedImpl();
|
SyndFeed feed = new SyndFeedImpl();
|
||||||
feed.setFeedType("rss_2.0");
|
feed.setFeedType("rss_2.0");
|
||||||
|
@ -199,7 +199,7 @@ public class AuthPlaylistHandlers {
|
||||||
return mapper.writeValueAsBytes(new AcceptedResponse());
|
return mapper.writeValueAsBytes(new AcceptedResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] addToPlaylistResponse(String session, String playlistId, List<String> videoIds) throws IOException, ExtractionException {
|
public static byte[] addToPlaylistResponse(String session, String playlistId, @Var List<String> videoIds) throws IOException, ExtractionException {
|
||||||
|
|
||||||
videoIds = videoIds.stream()
|
videoIds = videoIds.stream()
|
||||||
.filter(StringUtils::isNotBlank)
|
.filter(StringUtils::isNotBlank)
|
||||||
|
@ -232,12 +232,12 @@ public class AuthPlaylistHandlers {
|
||||||
|
|
||||||
var videos = playlist.getVideos();
|
var videos = playlist.getVideos();
|
||||||
|
|
||||||
boolean added = false;
|
@Var boolean added = false;
|
||||||
|
|
||||||
for (String videoId : videoIds) {
|
for (String videoId : videoIds) {
|
||||||
if (StringUtils.isEmpty(videoId)) continue;
|
if (StringUtils.isEmpty(videoId)) continue;
|
||||||
|
|
||||||
var video = playlistVideos.stream().filter(v -> v.getId().equals(videoId))
|
@Var var video = playlistVideos.stream().filter(v -> v.getId().equals(videoId))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ public class AuthPlaylistHandlers {
|
||||||
|
|
||||||
String channelId = StringUtils.substringAfter(info.getUploaderUrl(), "/channel/");
|
String channelId = StringUtils.substringAfter(info.getUploaderUrl(), "/channel/");
|
||||||
|
|
||||||
var channel = DatabaseHelper.getChannelFromId(s, channelId);
|
@Var var channel = DatabaseHelper.getChannelFromId(s, channelId);
|
||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
channel = DatabaseHelper.saveChannel(channelId);
|
channel = DatabaseHelper.saveChannel(channelId);
|
||||||
|
@ -358,7 +358,7 @@ public class AuthPlaylistHandlers {
|
||||||
if (user == null)
|
if (user == null)
|
||||||
ExceptionHandler.throwErrorResponse(new AuthenticationFailureResponse());
|
ExceptionHandler.throwErrorResponse(new AuthenticationFailureResponse());
|
||||||
|
|
||||||
final String url = "https://www.youtube.com/playlist?list=" + playlistId;
|
String url = "https://www.youtube.com/playlist?list=" + playlistId;
|
||||||
|
|
||||||
PlaylistInfo info = PlaylistInfo.getInfo(url);
|
PlaylistInfo info = PlaylistInfo.getInfo(url);
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ public class AuthPlaylistHandlers {
|
||||||
|
|
||||||
List<StreamInfoItem> videos = new ObjectArrayList<>(info.getRelatedItems());
|
List<StreamInfoItem> videos = new ObjectArrayList<>(info.getRelatedItems());
|
||||||
|
|
||||||
Page nextpage = info.getNextPage();
|
@Var Page nextpage = info.getNextPage();
|
||||||
|
|
||||||
while (nextpage != null) {
|
while (nextpage != null) {
|
||||||
var page = PlaylistInfo.getMoreItems(YOUTUBE_SERVICE, url, nextpage);
|
var page = PlaylistInfo.getMoreItems(YOUTUBE_SERVICE, url, nextpage);
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class FeedHandlers {
|
||||||
)
|
)
|
||||||
.orderBy(cb.desc(root.get("uploaded")));
|
.orderBy(cb.desc(root.get("uploaded")));
|
||||||
|
|
||||||
final List<SyndEntry> entries = s.createQuery(criteria)
|
List<SyndEntry> entries = s.createQuery(criteria)
|
||||||
.setTimeout(20)
|
.setTimeout(20)
|
||||||
.setMaxResults(100)
|
.setMaxResults(100)
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -270,7 +270,7 @@ public class FeedHandlers {
|
||||||
feed.setUri(Constants.FRONTEND_URL + "/feed");
|
feed.setUri(Constants.FRONTEND_URL + "/feed");
|
||||||
feed.setPublishedDate(new Date());
|
feed.setPublishedDate(new Date());
|
||||||
|
|
||||||
final List<SyndEntry> entries = new ObjectArrayList<>();
|
List<SyndEntry> entries = new ObjectArrayList<>();
|
||||||
|
|
||||||
for (Video video : videos) {
|
for (Video video : videos) {
|
||||||
var channel = video.getChannel();
|
var channel = video.getChannel();
|
||||||
|
@ -342,7 +342,7 @@ public class FeedHandlers {
|
||||||
|
|
||||||
{
|
{
|
||||||
var query = cb.createQuery();
|
var query = cb.createQuery();
|
||||||
var root = query.from(me.kavin.piped.utils.obj.db.Channel.class);
|
var root = query.from(Channel.class);
|
||||||
query.select(root.get("id"))
|
query.select(root.get("id"))
|
||||||
.where(root.get("id").in(channelIds));
|
.where(root.get("id").in(channelIds));
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
package me.kavin.piped.server.handlers.auth;
|
package me.kavin.piped.server.handlers.auth;
|
||||||
|
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
import jakarta.persistence.criteria.CriteriaQuery;
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
import jakarta.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.DatabaseHelper;
|
import me.kavin.piped.utils.DatabaseHelper;
|
||||||
import me.kavin.piped.utils.DatabaseSessionFactory;
|
import me.kavin.piped.utils.DatabaseSessionFactory;
|
||||||
|
@ -18,17 +25,11 @@ import org.hibernate.StatelessSession;
|
||||||
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
|
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
|
|
||||||
public class UserHandlers {
|
public class UserHandlers {
|
||||||
private static final Argon2PasswordEncoder argon2PasswordEncoder = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
|
private static final Argon2PasswordEncoder argon2PasswordEncoder = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
|
||||||
private static final BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder();
|
private static final BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||||
|
|
||||||
public static byte[] registerResponse(String user, String pass) throws IOException {
|
public static byte[] registerResponse(@Var String user, String pass) throws IOException {
|
||||||
|
|
||||||
if (Constants.DISABLE_REGISTRATION)
|
if (Constants.DISABLE_REGISTRATION)
|
||||||
ExceptionHandler.throwErrorResponse(new DisabledRegistrationResponse());
|
ExceptionHandler.throwErrorResponse(new DisabledRegistrationResponse());
|
||||||
|
@ -55,15 +56,14 @@ public class UserHandlers {
|
||||||
String sha1Hash = DigestUtils.sha1Hex(pass).toUpperCase();
|
String sha1Hash = DigestUtils.sha1Hex(pass).toUpperCase();
|
||||||
String prefix = sha1Hash.substring(0, 5);
|
String prefix = sha1Hash.substring(0, 5);
|
||||||
String suffix = sha1Hash.substring(5);
|
String suffix = sha1Hash.substring(5);
|
||||||
String[] entries = RequestUtils
|
Iterable<String> entries = Splitter.on('\n').split(RequestUtils
|
||||||
.sendGet("https://api.pwnedpasswords.com/range/" + prefix, "github.com/TeamPiped/Piped-Backend")
|
.sendGet("https://api.pwnedpasswords.com/range/" + prefix, "github.com/TeamPiped/Piped-Backend"));
|
||||||
.split("\n");
|
|
||||||
for (String entry : entries)
|
for (String entry : entries)
|
||||||
if (StringUtils.substringBefore(entry, ":").equals(suffix))
|
if (StringUtils.substringBefore(entry, ":").equals(suffix))
|
||||||
ExceptionHandler.throwErrorResponse(new CompromisedPasswordResponse());
|
ExceptionHandler.throwErrorResponse(new CompromisedPasswordResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
User newuser = new User(user, argon2PasswordEncoder.encode(pass), Set.of());
|
var newuser = new User(user, argon2PasswordEncoder.encode(pass), Set.of());
|
||||||
|
|
||||||
var tr = s.beginTransaction();
|
var tr = s.beginTransaction();
|
||||||
s.persist(newuser);
|
s.persist(newuser);
|
||||||
|
@ -80,7 +80,7 @@ public class UserHandlers {
|
||||||
bcryptPasswordEncoder.matches(pass, hash);
|
bcryptPasswordEncoder.matches(pass, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] loginResponse(String user, String pass)
|
public static byte[] loginResponse(@Var String user, String pass)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
if (user == null || pass == null)
|
if (user == null || pass == null)
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
|
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
||||||
|
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import com.rometools.rome.feed.synd.*;
|
import com.rometools.rome.feed.synd.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.obj.db.Channel;
|
import me.kavin.piped.utils.obj.db.Channel;
|
||||||
import me.kavin.piped.utils.obj.db.Video;
|
import me.kavin.piped.utils.obj.db.Video;
|
||||||
|
@ -9,15 +18,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.text.StringEscapeUtils;
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
|
||||||
|
|
||||||
public class ChannelHelpers {
|
public class ChannelHelpers {
|
||||||
|
|
||||||
public static boolean isValidId(String id) {
|
public static boolean isValidId(String id) {
|
||||||
|
@ -26,7 +26,7 @@ public class ChannelHelpers {
|
||||||
|
|
||||||
public static void updateChannel(StatelessSession s, Channel channel, String name, String avatarUrl, boolean uploaderVerified) {
|
public static void updateChannel(StatelessSession s, Channel channel, String name, String avatarUrl, boolean uploaderVerified) {
|
||||||
|
|
||||||
boolean changed = false;
|
@Var boolean changed = false;
|
||||||
|
|
||||||
if (name != null && !name.equals(channel.getUploader())) {
|
if (name != null && !name.equals(channel.getUploader())) {
|
||||||
channel.setUploader(name);
|
channel.setUploader(name);
|
||||||
|
|
|
@ -16,13 +16,13 @@ import static me.kavin.piped.utils.URLUtils.*;
|
||||||
public class CollectionUtils {
|
public class CollectionUtils {
|
||||||
|
|
||||||
public static Streams collectStreamInfo(StreamInfo info) {
|
public static Streams collectStreamInfo(StreamInfo info) {
|
||||||
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
List<Subtitle> subtitles = new ObjectArrayList<>();
|
||||||
final List<ChapterSegment> chapters = new ObjectArrayList<>();
|
List<ChapterSegment> chapters = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getStreamSegments().forEach(segment -> chapters.add(new ChapterSegment(segment.getTitle(), rewriteURL(segment.getPreviewUrl()),
|
info.getStreamSegments().forEach(segment -> chapters.add(new ChapterSegment(segment.getTitle(), rewriteURL(segment.getPreviewUrl()),
|
||||||
segment.getStartTimeSeconds())));
|
segment.getStartTimeSeconds())));
|
||||||
|
|
||||||
final List<PreviewFrames> previewFrames = new ObjectArrayList<>();
|
List<PreviewFrames> previewFrames = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getPreviewFrames().forEach(frame -> previewFrames.add(new PreviewFrames(frame.getUrls().stream().map(URLUtils::rewriteURL).toList(), frame.getFrameWidth(),
|
info.getPreviewFrames().forEach(frame -> previewFrames.add(new PreviewFrames(frame.getUrls().stream().map(URLUtils::rewriteURL).toList(), frame.getFrameWidth(),
|
||||||
frame.getFrameHeight(), frame.getTotalCount(), frame.getDurationPerFrame(), frame.getFramesPerPageX(),
|
frame.getFrameHeight(), frame.getTotalCount(), frame.getDurationPerFrame(), frame.getFramesPerPageX(),
|
||||||
|
@ -33,8 +33,8 @@ public class CollectionUtils {
|
||||||
subtitle.getFormat().getMimeType(), subtitle.getDisplayLanguageName(),
|
subtitle.getFormat().getMimeType(), subtitle.getDisplayLanguageName(),
|
||||||
subtitle.getLanguageTag(), subtitle.isAutoGenerated())));
|
subtitle.getLanguageTag(), subtitle.isAutoGenerated())));
|
||||||
|
|
||||||
final List<PipedStream> videoStreams = new ObjectArrayList<>();
|
List<PipedStream> videoStreams = new ObjectArrayList<>();
|
||||||
final List<PipedStream> audioStreams = new ObjectArrayList<>();
|
List<PipedStream> audioStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class CollectionUtils {
|
||||||
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getCodec(), stream.getAudioTrackId(), stream.getAudioTrackName())));
|
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getCodec(), stream.getAudioTrackId(), stream.getAudioTrackName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());
|
||||||
|
|
||||||
return new Streams(info.getName(), info.getDescription().getContent(),
|
return new Streams(info.getName(), info.getDescription().getContent(),
|
||||||
info.getTextualUploadDate(), info.getUploaderName(), substringYouTube(info.getUploaderUrl()),
|
info.getTextualUploadDate(), info.getUploaderName(), substringYouTube(info.getUploaderUrl()),
|
||||||
|
@ -85,7 +85,7 @@ public class CollectionUtils {
|
||||||
|
|
||||||
private static StreamItem collectRelatedStream(Object o) {
|
private static StreamItem collectRelatedStream(Object o) {
|
||||||
|
|
||||||
StreamInfoItem item = (StreamInfoItem) o;
|
var item = (StreamInfoItem) o;
|
||||||
|
|
||||||
return new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
return new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()),
|
rewriteURL(item.getThumbnailUrl()),
|
||||||
|
@ -99,7 +99,7 @@ public class CollectionUtils {
|
||||||
|
|
||||||
private static PlaylistItem collectRelatedPlaylist(Object o) {
|
private static PlaylistItem collectRelatedPlaylist(Object o) {
|
||||||
|
|
||||||
PlaylistInfoItem item = (PlaylistInfoItem) o;
|
var item = (PlaylistInfoItem) o;
|
||||||
|
|
||||||
return new PlaylistItem(substringYouTube(item.getUrl()), item.getName(),
|
return new PlaylistItem(substringYouTube(item.getUrl()), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()),
|
rewriteURL(item.getThumbnailUrl()),
|
||||||
|
@ -110,7 +110,7 @@ public class CollectionUtils {
|
||||||
|
|
||||||
private static ChannelItem collectRelatedChannel(Object o) {
|
private static ChannelItem collectRelatedChannel(Object o) {
|
||||||
|
|
||||||
ChannelInfoItem item = (ChannelInfoItem) o;
|
var item = (ChannelInfoItem) o;
|
||||||
|
|
||||||
return new ChannelItem(substringYouTube(item.getUrl()), item.getName(),
|
return new ChannelItem(substringYouTube(item.getUrl()), item.getName(),
|
||||||
rewriteURL(item.getThumbnailUrl()),
|
rewriteURL(item.getThumbnailUrl()),
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
|
import java.util.concurrent.CompletionException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.resp.InvalidRequestResponse;
|
import me.kavin.piped.utils.resp.InvalidRequestResponse;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
|
|
||||||
import java.util.concurrent.CompletionException;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
public class ExceptionHandler {
|
public class ExceptionHandler {
|
||||||
|
|
||||||
public static Exception handle(Exception e) {
|
public static Exception handle(Exception e) {
|
||||||
return handle(e, null);
|
return handle(e, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Exception handle(Exception e, String path) {
|
public static Exception handle(@Var Exception e, String path) {
|
||||||
|
|
||||||
if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException))
|
if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException))
|
||||||
e = (Exception) e.getCause();
|
e = (Exception) e.getCause();
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.obj.db.PubSub;
|
import me.kavin.piped.utils.obj.db.PubSub;
|
||||||
import okhttp3.FormBody;
|
import okhttp3.FormBody;
|
||||||
|
@ -7,17 +13,13 @@ import okio.Buffer;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
import rocks.kavin.reqwest4j.ReqwestUtils;
|
import rocks.kavin.reqwest4j.ReqwestUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class PubSubHelper {
|
public class PubSubHelper {
|
||||||
public static void subscribePubSub(String channelId) throws IOException {
|
public static void subscribePubSub(String channelId) throws IOException {
|
||||||
|
|
||||||
if (!ChannelHelpers.isValidId(channelId))
|
if (!ChannelHelpers.isValidId(channelId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PubSub pubsub = DatabaseHelper.getPubSubFromId(channelId);
|
@Var PubSub pubsub = DatabaseHelper.getPubSubFromId(channelId);
|
||||||
|
|
||||||
if (pubsub == null || System.currentTimeMillis() - pubsub.getSubbedAt() > TimeUnit.DAYS.toMillis(4)) {
|
if (pubsub == null || System.currentTimeMillis() - pubsub.getSubbedAt() > TimeUnit.DAYS.toMillis(4)) {
|
||||||
|
|
||||||
|
@ -47,13 +49,13 @@ public class PubSubHelper {
|
||||||
var resp = ReqwestUtils.fetch(callback, "POST", buffer.readByteArray(), Map.of());
|
var resp = ReqwestUtils.fetch(callback, "POST", buffer.readByteArray(), Map.of());
|
||||||
|
|
||||||
if (resp.status() != 202)
|
if (resp.status() != 202)
|
||||||
System.out.println("Failed to subscribe: " + resp.status() + "\n" + new String(resp.body()));
|
System.out.println("Failed to subscribe: " + resp.status() + "\n" + new String(resp.body(), UTF_8));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePubSub(String channelId) {
|
public static void updatePubSub(String channelId) {
|
||||||
var pubsub = DatabaseHelper.getPubSubFromId(channelId);
|
@Var var pubsub = DatabaseHelper.getPubSubFromId(channelId);
|
||||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
if (pubsub == null) {
|
if (pubsub == null) {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import rocks.kavin.reqwest4j.ReqwestUtils;
|
import rocks.kavin.reqwest4j.ReqwestUtils;
|
||||||
import rocks.kavin.reqwest4j.Response;
|
import rocks.kavin.reqwest4j.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
|
|
||||||
public class RequestUtils {
|
public class RequestUtils {
|
||||||
|
|
||||||
public static Response sendGetRaw(String url) throws IOException {
|
public static Response sendGetRaw(String url) throws IOException {
|
||||||
|
@ -21,14 +21,14 @@ public class RequestUtils {
|
||||||
public static String sendGet(String url) throws IOException {
|
public static String sendGet(String url) throws IOException {
|
||||||
return new String(
|
return new String(
|
||||||
ReqwestUtils.fetch(url, "GET", null, Map.of())
|
ReqwestUtils.fetch(url, "GET", null, Map.of())
|
||||||
.body()
|
.body(), UTF_8
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sendGet(String url, String ua) throws IOException {
|
public static String sendGet(String url, String ua) throws IOException {
|
||||||
return new String(
|
return new String(
|
||||||
ReqwestUtils.fetch(url, "GET", null, Map.of("User-Agent", ua))
|
ReqwestUtils.fetch(url, "GET", null, Map.of("User-Agent", ua))
|
||||||
.body()
|
.body(), UTF_8
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonObject;
|
|
||||||
import com.grack.nanojson.JsonWriter;
|
|
||||||
import me.kavin.piped.consts.Constants;
|
|
||||||
import me.kavin.piped.utils.obj.db.Video;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.hibernate.StatelessSession;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static org.schabi.newpipe.extractor.NewPipe.getPreferredContentCountry;
|
import static org.schabi.newpipe.extractor.NewPipe.getPreferredContentCountry;
|
||||||
import static org.schabi.newpipe.extractor.NewPipe.getPreferredLocalization;
|
import static org.schabi.newpipe.extractor.NewPipe.getPreferredLocalization;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
||||||
|
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
|
import com.grack.nanojson.JsonObject;
|
||||||
|
import com.grack.nanojson.JsonWriter;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import me.kavin.piped.consts.Constants;
|
||||||
|
import me.kavin.piped.utils.obj.db.Channel;
|
||||||
|
import me.kavin.piped.utils.obj.db.Video;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.hibernate.StatelessSession;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
public class VideoHelpers {
|
public class VideoHelpers {
|
||||||
public static void handleNewVideo(String url, long time, me.kavin.piped.utils.obj.db.Channel channel) {
|
public static void handleNewVideo(String url, long time, Channel channel) {
|
||||||
try {
|
try {
|
||||||
handleNewVideo(StreamInfo.getInfo(url), time, channel);
|
handleNewVideo(StreamInfo.getInfo(url), time, channel);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -26,7 +27,7 @@ public class VideoHelpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleNewVideo(StreamInfo info, long time, me.kavin.piped.utils.obj.db.Channel channel) throws Exception {
|
public static void handleNewVideo(StreamInfo info, long time, @Var Channel channel) throws Exception {
|
||||||
|
|
||||||
if (channel == null)
|
if (channel == null)
|
||||||
channel = DatabaseHelper.getChannelFromId(
|
channel = DatabaseHelper.getChannelFromId(
|
||||||
|
@ -43,7 +44,7 @@ public class VideoHelpers {
|
||||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||||
if (!DatabaseHelper.doesVideoExist(s, info.getId())) {
|
if (!DatabaseHelper.doesVideoExist(s, info.getId())) {
|
||||||
|
|
||||||
Video video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
|
var video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
|
||||||
Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
|
Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
|
||||||
|
|
||||||
var tr = s.beginTransaction();
|
var tr = s.beginTransaction();
|
||||||
|
@ -65,13 +66,13 @@ public class VideoHelpers {
|
||||||
|
|
||||||
public static boolean isShort(String videoId) throws Exception {
|
public static boolean isShort(String videoId) throws Exception {
|
||||||
|
|
||||||
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
|
||||||
getPreferredLocalization(), getPreferredContentCountry())
|
getPreferredLocalization(), getPreferredContentCountry())
|
||||||
.value("url", "https://www.youtube.com/shorts/" + videoId)
|
.value("url", "https://www.youtube.com/shorts/" + videoId)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
||||||
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
||||||
body, getPreferredLocalization());
|
body, getPreferredLocalization());
|
||||||
|
|
||||||
return jsonResponse.getObject("endpoint").has("reelWatchEndpoint");
|
return jsonResponse.getObject("endpoint").has("reelWatchEndpoint");
|
||||||
|
|
|
@ -2,7 +2,7 @@ package me.kavin.piped.utils;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
@AllArgsConstructor
|
SuppressWarnings
|
||||||
public class WaitingListener {
|
public class WaitingListener {
|
||||||
|
|
||||||
private final long maxWaitTime;
|
private final long maxWaitTime;
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
package me.kavin.piped.utils.matrix;
|
package me.kavin.piped.utils.matrix;
|
||||||
|
|
||||||
|
import static me.kavin.piped.consts.Constants.mapper;
|
||||||
|
import static me.kavin.piped.utils.obj.MatrixHelper.*;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.google.errorprone.annotations.Var;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.*;
|
import me.kavin.piped.utils.*;
|
||||||
import me.kavin.piped.utils.obj.MatrixHelper;
|
import me.kavin.piped.utils.obj.MatrixHelper;
|
||||||
|
@ -16,14 +24,6 @@ import okhttp3.RequestBody;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.StreamSupport;
|
|
||||||
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
|
||||||
import static me.kavin.piped.utils.obj.MatrixHelper.*;
|
|
||||||
|
|
||||||
public class SyncRunner implements Runnable {
|
public class SyncRunner implements Runnable {
|
||||||
|
|
||||||
private final OkHttpClient client;
|
private final OkHttpClient client;
|
||||||
|
@ -45,7 +45,7 @@ public class SyncRunner implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String user_id = null;
|
@Var String user_id = null;
|
||||||
|
|
||||||
if (!UNAUTHENTICATED) {
|
if (!UNAUTHENTICATED) {
|
||||||
// whoami to get the user id
|
// whoami to get the user id
|
||||||
|
@ -62,7 +62,7 @@ public class SyncRunner implements Runnable {
|
||||||
// Join room and get the room id
|
// Join room and get the room id
|
||||||
System.out.println("Room ID: " + ROOM_ID);
|
System.out.println("Room ID: " + ROOM_ID);
|
||||||
|
|
||||||
String filter_id = null;
|
@Var String filter_id = null;
|
||||||
|
|
||||||
// We have to filter on client-side if unauthenticated
|
// We have to filter on client-side if unauthenticated
|
||||||
if (!UNAUTHENTICATED) {
|
if (!UNAUTHENTICATED) {
|
||||||
|
@ -72,12 +72,12 @@ public class SyncRunner implements Runnable {
|
||||||
|
|
||||||
System.out.println("Filter ID: " + filter_id);
|
System.out.println("Filter ID: " + filter_id);
|
||||||
|
|
||||||
String next_batch = null;
|
@Var String next_batch = null;
|
||||||
|
|
||||||
//noinspection InfiniteLoopStatement
|
//noinspection InfiniteLoopStatement
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
String url;
|
@Var String url;
|
||||||
|
|
||||||
if (UNAUTHENTICATED) {
|
if (UNAUTHENTICATED) {
|
||||||
url = this.url + "/_matrix/client/v3/events?room_id=" + URLUtils.silentEncode(ROOM_ID);
|
url = this.url + "/_matrix/client/v3/events?room_id=" + URLUtils.silentEncode(ROOM_ID);
|
||||||
|
@ -141,7 +141,7 @@ public class SyncRunner implements Runnable {
|
||||||
|
|
||||||
Streams streams = CollectionUtils.collectStreamInfo(info);
|
Streams streams = CollectionUtils.collectStreamInfo(info);
|
||||||
|
|
||||||
FederatedGeoBypassResponse bypassResponse = new FederatedGeoBypassResponse(bypassRequest.getVideoId(), Constants.YOUTUBE_COUNTRY, streams);
|
var bypassResponse = new FederatedGeoBypassResponse(bypassRequest.getVideoId(), Constants.YOUTUBE_COUNTRY, streams);
|
||||||
|
|
||||||
MatrixHelper.sendEvent("video.piped.stream.bypass.response", bypassResponse);
|
MatrixHelper.sendEvent("video.piped.stream.bypass.response", bypassResponse);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package me.kavin.piped.utils.obj;
|
||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@NoArgsConstructor
|
SuppressWarnings
|
||||||
public class ChannelItem extends ContentItem {
|
public class ChannelItem extends ContentItem {
|
||||||
|
|
||||||
public final String type = "channel";
|
public final String type = "channel";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@NoArgsConstructor
|
SuppressWarnings
|
||||||
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION, property = "type")
|
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION, property = "type")
|
||||||
@JsonSubTypes({
|
@JsonSubTypes({
|
||||||
@JsonSubTypes.Type(name = "stream", value = StreamItem.class),
|
@JsonSubTypes.Type(name = "stream", value = StreamItem.class),
|
||||||
|
|
|
@ -2,7 +2,7 @@ package me.kavin.piped.utils.obj;
|
||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@NoArgsConstructor
|
SuppressWarnings
|
||||||
public class PlaylistItem extends ContentItem {
|
public class PlaylistItem extends ContentItem {
|
||||||
|
|
||||||
public final String type = "playlist";
|
public final String type = "playlist";
|
||||||
|
|
|
@ -5,8 +5,8 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@AllArgsConstructor
|
SuppressWarnings
|
||||||
@NoArgsConstructor
|
SuppressWarnings
|
||||||
public class PreviewFrames {
|
public class PreviewFrames {
|
||||||
|
|
||||||
public List<String> urls;
|
public List<String> urls;
|
||||||
|
|
|
@ -6,10 +6,10 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@NoArgsConstructor
|
SuppressWarnings
|
||||||
@AllArgsConstructor
|
SuppressWarnings
|
||||||
@Getter
|
@Getter
|
||||||
public class FederatedGeoBypassRequest {
|
public class FederatedGeoBypassRequest {
|
||||||
private String videoId;
|
private String SuppressWarnings
|
||||||
private List<String> allowedCountries;
|
private List<String> SuppressWarnings
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import lombok.NoArgsConstructor;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.obj.Streams;
|
import me.kavin.piped.utils.obj.Streams;
|
||||||
|
|
||||||
@NoArgsConstructor
|
SuppressWarnings
|
||||||
@Getter
|
@Getter
|
||||||
public class FederatedGeoBypassResponse {
|
public class FederatedGeoBypassResponse {
|
||||||
private String videoId;
|
private String SuppressWarnings
|
||||||
private String country;
|
private String SuppressWarnings
|
||||||
private String videoProxyUrl;
|
private String SuppressWarnings
|
||||||
private Streams data;
|
private Streams SuppressWarnings
|
||||||
|
|
||||||
public FederatedGeoBypassResponse(String videoId, String country, Streams data) {
|
public FederatedGeoBypassResponse(String videoId, String country, Streams data) {
|
||||||
this.videoId = videoId;
|
this.videoId = videoId;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue