From 37a96d063f2db6ff9f7082f6ae43a0a188abdd34 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sun, 10 Jan 2021 14:13:20 +0100 Subject: [PATCH] Add different error messages for SoundCloud and YouTube unavailable contents Add new error strings for the six new exceptions created in the extractor and catch these exceptions. Extractor is, of course, updated with this PR. --- app/build.gradle | 2 +- .../newpipe/fragments/BaseStateFragment.java | 30 +++++++++++++++++-- .../schabi/newpipe/util/ExtractorHelper.java | 23 +++++++++++++- app/src/main/res/values-fr/strings.xml | 3 +- app/src/main/res/values/strings.xml | 8 ++++- 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9a6430f53..7c504e968 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -180,7 +180,7 @@ dependencies { // NewPipe dependencies // You can use a local version by uncommenting a few lines in settings.gradle - implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.20.11' + implementation "com.github.TeamNewPipe:NewPipeExtractor:7e6f464407fc1a2c8fb0886d294093526a6ef0f1" implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" implementation "org.jsoup:jsoup:1.13.1" diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index f876b767c..cf02af4a9 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -20,9 +20,15 @@ import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import org.schabi.newpipe.ReCaptchaActivity; +import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; +import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; +import org.schabi.newpipe.extractor.exceptions.PrivateContentException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; +import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException; +import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException; import org.schabi.newpipe.ktx.ExceptionUtils; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.ErrorInfo; @@ -223,12 +229,30 @@ public abstract class BaseStateFragment extends BaseFragment implements ViewC if (exception instanceof ReCaptchaException) { onReCaptchaException((ReCaptchaException) exception); return true; - } else if (exception instanceof ContentNotAvailableException) { - showError(getString(R.string.content_not_available), false); - return true; } else if (ExceptionUtils.isNetworkRelated(exception)) { showError(getString(R.string.network_error), true); return true; + } else if (exception instanceof AgeRestrictedContentException) { + showError(getString(R.string.restricted_video_no_stream), false); + return true; + } else if (exception instanceof GeographicRestrictionException) { + showError(getString(R.string.georestricted_content), false); + return true; + } else if (exception instanceof PaidContentException) { + showError(getString(R.string.paid_content), false); + return true; + } else if (exception instanceof PrivateContentException) { + showError(getString(R.string.private_content), false); + return true; + } else if (exception instanceof SoundCloudGoPlusContentException) { + showError(getString(R.string.soundcloud_go_plus_content), false); + return true; + } else if (exception instanceof YoutubeMusicPremiumContentException) { + showError(getString(R.string.youtube_music_premium_content), false); + return true; + } else if (exception instanceof ContentNotAvailableException) { + showError(getString(R.string.content_not_available), false); + return true; } else if (exception instanceof ContentNotSupportedException) { showError(getString(R.string.content_not_supported), false); return true; diff --git a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java index 6ee69dcd9..d6e3a0e80 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -1,6 +1,6 @@ /* * Copyright 2017 Mauricio Colli - * Extractors.java is part of NewPipe + * ExtractorHelper.java is part of NewPipe * * License: GPL-3.0+ * This program is free software: you can redistribute it and/or modify @@ -44,10 +44,16 @@ import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.comments.CommentsInfo; +import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; +import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.exceptions.PrivateContentException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; +import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException; +import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException; import org.schabi.newpipe.extractor.feed.FeedExtractor; import org.schabi.newpipe.extractor.feed.FeedInfo; import org.schabi.newpipe.extractor.kiosk.KioskInfo; @@ -300,6 +306,21 @@ public final class ExtractorHelper { context.startActivity(intent); } else if (ExceptionUtils.isNetworkRelated(exception)) { Toast.makeText(context, R.string.network_error, Toast.LENGTH_LONG).show(); + } else if (exception instanceof AgeRestrictedContentException) { + Toast.makeText(context, R.string.restricted_video_no_stream, + Toast.LENGTH_LONG).show(); + } else if (exception instanceof GeographicRestrictionException) { + Toast.makeText(context, R.string.georestricted_content, Toast.LENGTH_LONG).show(); + } else if (exception instanceof PaidContentException) { + Toast.makeText(context, R.string.paid_content, Toast.LENGTH_LONG).show(); + } else if (exception instanceof PrivateContentException) { + Toast.makeText(context, R.string.private_content, Toast.LENGTH_LONG).show(); + } else if (exception instanceof SoundCloudGoPlusContentException) { + Toast.makeText(context, R.string.soundcloud_go_plus_content, + Toast.LENGTH_LONG).show(); + } else if (exception instanceof YoutubeMusicPremiumContentException) { + Toast.makeText(context, R.string.youtube_music_premium_content, + Toast.LENGTH_LONG).show(); } else if (exception instanceof ContentNotAvailableException) { Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show(); } else if (exception instanceof ContentNotSupportedException) { diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c1afa106d..c241254db 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -665,4 +665,5 @@ Désactiver pour masquer la description de la vidéo et les informations supplémentaires Afficher la description Plante l\'application - \ No newline at end of file + Ce contenu n\'est pas disponible dans votre pays. + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6a13c2b03..a8a343645 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ - + Tap \"Search\" to get started \n @@ -164,6 +164,7 @@ Turn on YouTube\'s \"Restricted Mode\" YouTube provides a \"Restricted Mode\" which hides potentially mature content This video is age restricted.\n\nTurn on \"%1$s\" in the settings if you want to see it. + This video is age-restricted.\nDue to new YouTube policies with age-restricted videos, NewPipe cannot access any of its video streams and thus is unable to play it. Live Downloads Downloads @@ -700,4 +701,9 @@ Recent Chapters No app on your device can open this + This content is not available in your country. + This is a SoundCloud Go+ track, at least in your country, so it cannot be streamed or downloaded by NewPipe. + This content is private, so it cannot be streamed or downloaded by NewPipe. + This video is available only to YouTube Music Premium members, so it cannot be streamed or downloaded by NewPipe. + This content is only available to users who have paid, so it cannot be streamed or downloaded by NewPipe.