mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Support region localization for trending (#79)
* Support region localization for trending * Revert linting, remove defaulting to US, and fix warning. Co-authored-by: FireMasterK <20838718+FireMasterK@users.noreply.github.com>
This commit is contained in:
parent
1af5754f18
commit
ac3c43b1ed
2 changed files with 12 additions and 5 deletions
|
@ -147,7 +147,8 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
}
|
||||
})).map("/trending", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(ResponseHelper.trendingResponse(), "public, max-age=3600");
|
||||
return getJsonResponse(ResponseHelper.trendingResponse(request.getQueryParameter("region")),
|
||||
"public, max-age=3600");
|
||||
} catch (Exception e) {
|
||||
return getErrorResponse(e);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,10 @@ import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
|||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||
import org.schabi.newpipe.extractor.search.SearchInfo;
|
||||
|
@ -201,13 +204,16 @@ public class ResponseHelper {
|
|||
|
||||
}
|
||||
|
||||
public static final byte[] trendingResponse() throws ParsingException, ExtractionException, IOException {
|
||||
public static final byte[] trendingResponse(String region)
|
||||
throws ParsingException, ExtractionException, IOException {
|
||||
|
||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||
|
||||
String url = Constants.YOUTUBE_SERVICE.getKioskList().getListLinkHandlerFactoryByType("Trending")
|
||||
.getUrl("Trending");
|
||||
KioskInfo info = KioskInfo.getInfo(Constants.YOUTUBE_SERVICE, url);
|
||||
KioskList kioskList = Constants.YOUTUBE_SERVICE.getKioskList();
|
||||
kioskList.forceContentCountry(new ContentCountry(region));
|
||||
KioskExtractor<?> extractor = kioskList.getDefaultKioskExtractor();
|
||||
extractor.fetchPage();
|
||||
KioskInfo info = KioskInfo.getInfo(extractor);
|
||||
|
||||
info.getRelatedItems().forEach(o -> {
|
||||
StreamInfoItem item = o;
|
||||
|
|
Loading…
Reference in a new issue