From cc7a25d9ce8a4546e981d438e6b32125f3eac160 Mon Sep 17 00:00:00 2001 From: bopol Date: Mon, 30 Mar 2020 12:38:42 +0200 Subject: [PATCH 1/3] handle ContentNotSupportedException in BaseStateFragment thus not supported soundcloud streams (e.g. hls streams) don't crash anyore --- app/build.gradle | 2 +- .../java/org/schabi/newpipe/fragments/BaseStateFragment.java | 4 ++++ app/src/main/res/values-eo/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index baa11bd20e3..6ad29f89fd2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -136,7 +136,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.TeamNewPipe:NewPipeExtractor:69e0624e3' + implementation 'com.github.B0pol:NewPipeExtractor:cf24e2935cbb46117ab7bd2705d5e86f68f649e1' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' 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 861dc2c60da..cf49cf30290 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -20,6 +20,7 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.ReCaptchaActivity; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; +import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; @@ -216,6 +217,9 @@ protected boolean onError(final Throwable exception) { } else if (exception instanceof IOException) { showError(getString(R.string.network_error), true); return true; + } else if (exception instanceof ContentNotSupportedException) { + showError(getString(R.string.content_not_supported), false); + return true; } return false; diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index 797ee4bf4b7..f985931e530 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -586,4 +586,5 @@ Mutigi Malmutigi Helpo + Tio enhavo ne estas ankoraŭ subtenata per NewPipe.\n\nĜi espereble estos en sekvanta versio. \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 14556f1c3df..b35e60b459a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -598,4 +598,5 @@ \n \n Donc le choix vous revient : Préferez-vous la vitesse ou des informations précises \? Aide + Ce contenu n\'est pas encore supporté par NewPipe.\n\nIl le sera peut-être dans une version future. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ef09be9f4c9..ea2202c5858 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -637,4 +637,5 @@ Enable fast mode Disable fast mode Do you think feed loading is too slow? If so, try enabling fast loading (you can change it in settings or by pressing the button below).\n\nNewPipe offers two feed loading strategies:\n• Fetching the whole subscription channel, which is slow but complete.\n• Using a dedicated service endpoint, which is fast but usually not complete.\n\nThe difference between the two is that the fast one usually lacks some information, like the item\'s duration or type (can\'t distinguish between live videos and normal ones) and it may return less items.\n\nYouTube is an example of a service that offers this fast method with its RSS feed.\n\nSo the choice boils down to what you prefer: speed or precise information. + This content is not yet supported by NewPipe.\n\nIt will hopefully be supported in a future version. \ No newline at end of file From c392804f47e9fe2ac0c3f86ac9726fe63ed51751 Mon Sep 17 00:00:00 2001 From: bopol Date: Tue, 7 Apr 2020 14:54:49 +0200 Subject: [PATCH 2/3] handle ContentNotSupportedException in ExtractorHelper.handleGeneralException() --- app/build.gradle | 2 +- app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 6ad29f89fd2..c11a5521646 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -136,7 +136,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.B0pol:NewPipeExtractor:cf24e2935cbb46117ab7bd2705d5e86f68f649e1' + implementation 'com.github.B0pol:NewPipeExtractor:9a7c6b7ab00c0f5b8337232fc66d3d9b538c229f' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' 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 9c6ab189810..701acddad65 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java @@ -37,6 +37,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.comments.CommentsInfo; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; +import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.feed.FeedExtractor; @@ -293,6 +294,8 @@ public static void handleGeneralException(final Context context, final int servi Toast.makeText(context, R.string.network_error, 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) { + Toast.makeText(context, R.string.content_not_supported, Toast.LENGTH_LONG).show(); } else { int errorId = exception instanceof YoutubeStreamExtractor.DecryptException ? R.string.youtube_signature_decryption_error From 4c128d837cbf778fcd5f1f7e1154e3f95da0aa4c Mon Sep 17 00:00:00 2001 From: bopol Date: Tue, 7 Apr 2020 15:39:06 +0200 Subject: [PATCH 3/3] handle ContentNotSupportedException for Channel Fragment (when an user has no video tab) --- app/build.gradle | 2 +- .../list/channel/ChannelFragment.java | 43 +++++++++++++++++-- app/src/main/res/layout/fragment_channel.xml | 11 +++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c11a5521646..b714faa8420 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -136,7 +136,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.B0pol:NewPipeExtractor:9a7c6b7ab00c0f5b8337232fc66d3d9b538c229f' + implementation 'com.github.TeamNewPipe:NewPipeExtractor:a5155fb' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 8c93ee293e9..fbe3e34c726 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.text.TextUtils; import android.util.Log; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -30,6 +31,7 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelInfo; +import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; @@ -45,6 +47,7 @@ import org.schabi.newpipe.util.ShareUtils; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -83,6 +86,9 @@ public class ChannelFragment extends BaseListInfoFragment { private LinearLayout headerPopupButton; private LinearLayout headerBackgroundButton; private MenuItem menuRssButton; + private TextView contentNotSupportedTextView; + private TextView kaomojiTextView; + private TextView noVideosTextView; public static ChannelFragment getInstance(final int serviceId, final String url, final String name) { @@ -118,6 +124,14 @@ public View onCreateView(@NonNull final LayoutInflater inflater, return inflater.inflate(R.layout.fragment_channel, container, false); } + @Override + public void onViewCreated(final View rootView, final Bundle savedInstanceState) { + super.onViewCreated(rootView, savedInstanceState); + contentNotSupportedTextView = rootView.findViewById(R.id.error_content_not_supported); + kaomojiTextView = rootView.findViewById(R.id.channel_kaomoji); + noVideosTextView = rootView.findViewById(R.id.channel_no_videos); + } + @Override public void onDestroy() { super.onDestroy(); @@ -234,7 +248,7 @@ private void monitorSubscription(final ChannelInfo info) { .debounce(100, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe((List subscriptionEntities) -> - updateSubscribeButton(!subscriptionEntities.isEmpty()), onError)); + updateSubscribeButton(!subscriptionEntities.isEmpty()), onError)); } @@ -417,9 +431,23 @@ public void handleResult(@NonNull final ChannelInfo result) { playlistCtrl.setVisibility(View.VISIBLE); - if (!result.getErrors().isEmpty()) { - showSnackBarError(result.getErrors(), UserAction.REQUESTED_CHANNEL, - NewPipe.getNameOfService(result.getServiceId()), result.getUrl(), 0); + List errors = new ArrayList<>(result.getErrors()); + if (!errors.isEmpty()) { + + // handling ContentNotSupportedException not to show the error but an appropriate string + // so that crashes won't be sent uselessly and the user will understand what happened + for (Iterator it = errors.iterator(); it.hasNext();) { + Throwable throwable = it.next(); + if (throwable instanceof ContentNotSupportedException) { + showContentNotSupported(); + it.remove(); + } + } + + if (!errors.isEmpty()) { + showSnackBarError(errors, UserAction.REQUESTED_CHANNEL, + NewPipe.getNameOfService(result.getServiceId()), result.getUrl(), 0); + } } if (disposables != null) { @@ -439,6 +467,13 @@ public void handleResult(@NonNull final ChannelInfo result) { .playOnBackgroundPlayer(activity, getPlayQueue(), false)); } + private void showContentNotSupported() { + contentNotSupportedTextView.setVisibility(View.VISIBLE); + kaomojiTextView.setText("(︶︹︺)"); + kaomojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 45f); + noVideosTextView.setVisibility(View.GONE); + } + private PlayQueue getPlayQueue() { return getPlayQueue(0); } diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index f6f8afaa3c8..898440db674 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -32,6 +32,7 @@ tools:visibility="visible"> + +