mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Merge pull request #475 from TeamPiped/check-georestricted-topic
Check if geo restricted on unavailable videos.
This commit is contained in:
commit
0eca3d1d70
1 changed files with 17 additions and 3 deletions
|
@ -20,6 +20,7 @@ import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
||||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
|
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
|
||||||
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;
|
||||||
|
@ -105,17 +106,23 @@ public class StreamHandlers {
|
||||||
});
|
});
|
||||||
|
|
||||||
StreamInfo info = null;
|
StreamInfo info = null;
|
||||||
|
Throwable exception = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
info = futureStream.get(10, TimeUnit.SECONDS);
|
info = futureStream.get(10, TimeUnit.SECONDS);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
if (!(e.getCause() instanceof GeographicRestrictionException)) {
|
exception = e.getCause();
|
||||||
|
if (
|
||||||
|
// Some videos, like topic channel videos are not available everywhere
|
||||||
|
!(exception instanceof ContentNotAvailableException contentNotAvailableException && contentNotAvailableException.getMessage().equals("This video is not available")) &&
|
||||||
|
!(e.getCause() instanceof GeographicRestrictionException)
|
||||||
|
) {
|
||||||
ExceptionUtils.rethrow(e);
|
ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
// We're geo restricted
|
// We might be geo restricted
|
||||||
|
|
||||||
if (Constants.MATRIX_TOKEN != null && Constants.GEO_RESTRICTION_CHECKER_URL != null) {
|
if (Constants.MATRIX_TOKEN != null && Constants.GEO_RESTRICTION_CHECKER_URL != null) {
|
||||||
|
|
||||||
|
@ -123,6 +130,10 @@ public class StreamHandlers {
|
||||||
|
|
||||||
{
|
{
|
||||||
var restrictedTree = RequestUtils.sendGetJson(Constants.GEO_RESTRICTION_CHECKER_URL + "/api/region/check?video_id=" + videoId);
|
var restrictedTree = RequestUtils.sendGetJson(Constants.GEO_RESTRICTION_CHECKER_URL + "/api/region/check?video_id=" + videoId);
|
||||||
|
if (!restrictedTree.get("restricted").asBoolean()) {
|
||||||
|
assert exception != null;
|
||||||
|
throw (Exception) exception;
|
||||||
|
}
|
||||||
var it = restrictedTree.get("regions").elements();
|
var it = restrictedTree.get("regions").elements();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
var region = it.next();
|
var region = it.next();
|
||||||
|
@ -203,7 +214,10 @@ public class StreamHandlers {
|
||||||
throw new GeographicRestrictionException("This instance does not have a geo restriction checker set in its configuration");
|
throw new GeographicRestrictionException("This instance does not have a geo restriction checker set in its configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new GeographicRestrictionException("Geo restricted content, this instance is not part of the Matrix Federation protocol");
|
if (exception == null)
|
||||||
|
throw new GeographicRestrictionException("Geo restricted content, this instance is not part of the Matrix Federation protocol");
|
||||||
|
else
|
||||||
|
throw (Exception) exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
Streams streams = CollectionUtils.collectStreamInfo(info);
|
Streams streams = CollectionUtils.collectStreamInfo(info);
|
||||||
|
|
Loading…
Reference in a new issue