mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Revert linting, remove defaulting to US, and fix warning.
This commit is contained in:
parent
616de20f5b
commit
c8d3a8842f
2 changed files with 98 additions and 84 deletions
|
@ -1,8 +1,26 @@
|
||||||
package me.kavin.piped;
|
package me.kavin.piped;
|
||||||
|
|
||||||
|
import static io.activej.config.converter.ConfigConverters.ofInetSocketAddress;
|
||||||
|
import static io.activej.http.HttpHeaders.CACHE_CONTROL;
|
||||||
|
import static io.activej.http.HttpHeaders.CONTENT_TYPE;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.rometools.rome.feed.synd.SyndFeed;
|
import com.rometools.rome.feed.synd.SyndFeed;
|
||||||
import com.rometools.rome.io.SyndFeedInput;
|
import com.rometools.rome.io.SyndFeedInput;
|
||||||
|
|
||||||
import io.activej.config.Config;
|
import io.activej.config.Config;
|
||||||
import io.activej.http.AsyncServlet;
|
import io.activej.http.AsyncServlet;
|
||||||
import io.activej.http.HttpMethod;
|
import io.activej.http.HttpMethod;
|
||||||
|
@ -17,22 +35,6 @@ import me.kavin.piped.utils.CustomServletDecorator;
|
||||||
import me.kavin.piped.utils.ResponseHelper;
|
import me.kavin.piped.utils.ResponseHelper;
|
||||||
import me.kavin.piped.utils.SponsorBlockUtils;
|
import me.kavin.piped.utils.SponsorBlockUtils;
|
||||||
import me.kavin.piped.utils.resp.ErrorResponse;
|
import me.kavin.piped.utils.resp.ErrorResponse;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import static io.activej.config.converter.ConfigConverters.ofInetSocketAddress;
|
|
||||||
import static io.activej.http.HttpHeaders.CACHE_CONTROL;
|
|
||||||
import static io.activej.http.HttpHeaders.CONTENT_TYPE;
|
|
||||||
|
|
||||||
public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
||||||
|
|
||||||
|
@ -145,7 +147,8 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
||||||
}
|
}
|
||||||
})).map("/trending", AsyncServlet.ofBlocking(executor, request -> {
|
})).map("/trending", AsyncServlet.ofBlocking(executor, request -> {
|
||||||
try {
|
try {
|
||||||
return getJsonResponse(ResponseHelper.trendingResponse(request.getQueryParameter("region")), "public, max-age=3600");
|
return getJsonResponse(ResponseHelper.trendingResponse(request.getQueryParameter("region")),
|
||||||
|
"public, max-age=3600");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return getErrorResponse(e);
|
return getErrorResponse(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import java.io.IOException;
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import java.net.MalformedURLException;
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
import java.net.URI;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import java.net.URL;
|
||||||
import me.kavin.piped.consts.Constants;
|
import java.net.http.HttpRequest;
|
||||||
import me.kavin.piped.ipfs.IPFS;
|
import java.net.http.HttpRequest.BodyPublishers;
|
||||||
import me.kavin.piped.utils.obj.*;
|
import java.net.http.HttpResponse.BodyHandlers;
|
||||||
import me.kavin.piped.utils.obj.search.SearchChannel;
|
import java.util.Collections;
|
||||||
import me.kavin.piped.utils.obj.search.SearchItem;
|
import java.util.List;
|
||||||
import me.kavin.piped.utils.obj.search.SearchPlaylist;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import me.kavin.piped.utils.obj.search.SearchStream;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
|
@ -32,17 +33,28 @@ import org.schabi.newpipe.extractor.search.SearchInfo;
|
||||||
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 com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import java.net.MalformedURLException;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import java.net.URI;
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.http.HttpRequest;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
import java.net.http.HttpRequest.BodyPublishers;
|
import me.kavin.piped.consts.Constants;
|
||||||
import java.net.http.HttpResponse.BodyHandlers;
|
import me.kavin.piped.ipfs.IPFS;
|
||||||
import java.util.Collections;
|
import me.kavin.piped.utils.obj.Channel;
|
||||||
import java.util.List;
|
import me.kavin.piped.utils.obj.ChapterSegment;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import me.kavin.piped.utils.obj.Comment;
|
||||||
import java.util.concurrent.TimeUnit;
|
import me.kavin.piped.utils.obj.CommentsPage;
|
||||||
|
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.StreamItem;
|
||||||
|
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.search.SearchChannel;
|
||||||
|
import me.kavin.piped.utils.obj.search.SearchItem;
|
||||||
|
import me.kavin.piped.utils.obj.search.SearchPlaylist;
|
||||||
|
import me.kavin.piped.utils.obj.search.SearchStream;
|
||||||
|
|
||||||
public class ResponseHelper {
|
public class ResponseHelper {
|
||||||
|
|
||||||
|
@ -192,15 +204,14 @@ public class ResponseHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final byte[] trendingResponse(String region) throws ParsingException, ExtractionException, IOException {
|
public static final byte[] trendingResponse(String region)
|
||||||
|
throws ParsingException, ExtractionException, IOException {
|
||||||
region = (region == null || region.isEmpty()) ? "US" : region;
|
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
KioskList kioskList = Constants.YOUTUBE_SERVICE.getKioskList();
|
KioskList kioskList = Constants.YOUTUBE_SERVICE.getKioskList();
|
||||||
kioskList.forceContentCountry(new ContentCountry(region));
|
kioskList.forceContentCountry(new ContentCountry(region));
|
||||||
KioskExtractor extractor = kioskList.getDefaultKioskExtractor();
|
KioskExtractor<?> extractor = kioskList.getDefaultKioskExtractor();
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
KioskInfo info = KioskInfo.getInfo(extractor);
|
KioskInfo info = KioskInfo.getInfo(extractor);
|
||||||
|
|
||||||
|
@ -291,26 +302,26 @@ public class ResponseHelper {
|
||||||
|
|
||||||
info.getRelatedItems().forEach(item -> {
|
info.getRelatedItems().forEach(item -> {
|
||||||
switch (item.getInfoType()) {
|
switch (item.getInfoType()) {
|
||||||
case STREAM:
|
case STREAM:
|
||||||
StreamInfoItem stream = (StreamInfoItem) item;
|
StreamInfoItem stream = (StreamInfoItem) item;
|
||||||
items.add(new SearchStream(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchStream(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
item.getUrl().substring(23), stream.getTextualUploadDate(), stream.getUploaderName(),
|
item.getUrl().substring(23), stream.getTextualUploadDate(), stream.getUploaderName(),
|
||||||
optionalSubstring(stream.getUploaderUrl(), 23), stream.getViewCount(), stream.getDuration(),
|
optionalSubstring(stream.getUploaderUrl(), 23), stream.getViewCount(), stream.getDuration(),
|
||||||
stream.isUploaderVerified()));
|
stream.isUploaderVerified()));
|
||||||
break;
|
break;
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
ChannelInfoItem channel = (ChannelInfoItem) item;
|
ChannelInfoItem channel = (ChannelInfoItem) item;
|
||||||
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
item.getUrl().substring(23), channel.getDescription(), channel.getSubscriberCount(),
|
item.getUrl().substring(23), channel.getDescription(), channel.getSubscriberCount(),
|
||||||
channel.getStreamCount(), channel.isVerified()));
|
channel.getStreamCount(), channel.isVerified()));
|
||||||
break;
|
break;
|
||||||
case PLAYLIST:
|
case PLAYLIST:
|
||||||
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
||||||
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
item.getUrl().substring(23), playlist.getUploaderName(), playlist.getStreamCount()));
|
item.getUrl().substring(23), playlist.getUploaderName(), playlist.getStreamCount()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -334,26 +345,26 @@ public class ResponseHelper {
|
||||||
|
|
||||||
pages.getItems().forEach(item -> {
|
pages.getItems().forEach(item -> {
|
||||||
switch (item.getInfoType()) {
|
switch (item.getInfoType()) {
|
||||||
case STREAM:
|
case STREAM:
|
||||||
StreamInfoItem stream = (StreamInfoItem) item;
|
StreamInfoItem stream = (StreamInfoItem) item;
|
||||||
items.add(new SearchStream(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchStream(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
item.getUrl().substring(23), stream.getTextualUploadDate(), stream.getUploaderName(),
|
item.getUrl().substring(23), stream.getTextualUploadDate(), stream.getUploaderName(),
|
||||||
optionalSubstring(stream.getUploaderUrl(), 23), stream.getViewCount(), stream.getDuration(),
|
optionalSubstring(stream.getUploaderUrl(), 23), stream.getViewCount(), stream.getDuration(),
|
||||||
stream.isUploaderVerified()));
|
stream.isUploaderVerified()));
|
||||||
break;
|
break;
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
ChannelInfoItem channel = (ChannelInfoItem) item;
|
ChannelInfoItem channel = (ChannelInfoItem) item;
|
||||||
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
item.getUrl().substring(23), channel.getDescription(), channel.getSubscriberCount(),
|
item.getUrl().substring(23), channel.getDescription(), channel.getSubscriberCount(),
|
||||||
channel.getStreamCount(), channel.isVerified()));
|
channel.getStreamCount(), channel.isVerified()));
|
||||||
break;
|
break;
|
||||||
case PLAYLIST:
|
case PLAYLIST:
|
||||||
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
||||||
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
item.getUrl().substring(23), playlist.getUploaderName(), playlist.getStreamCount()));
|
item.getUrl().substring(23), playlist.getUploaderName(), playlist.getStreamCount()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -425,7 +436,7 @@ public class ResponseHelper {
|
||||||
String lbryId = 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);
|
||||||
|
|
||||||
if (!lbryId.isEmpty())
|
if (!lbryId.isEmpty())
|
||||||
new JSONObject(Constants.h2client.send(HttpRequest
|
new JSONObject(Constants.h2client.send(HttpRequest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue