Skip to content

Commit ea53b7d

Browse files
authored
Merge pull request #5385 from TiA4f8R/soundcloud-error-improvements
Better error messages for SoundCloud and YouTube unavailable contents
2 parents b360920 + 37a96d0 commit ea53b7d

5 files changed

Lines changed: 59 additions & 7 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ dependencies {
180180

181181
// NewPipe dependencies
182182
// You can use a local version by uncommenting a few lines in settings.gradle
183-
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.20.11'
183+
implementation "com.github.TeamNewPipe:NewPipeExtractor:7e6f464407fc1a2c8fb0886d294093526a6ef0f1"
184184
implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751"
185185

186186
implementation "org.jsoup:jsoup:1.13.1"

app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
import org.schabi.newpipe.MainActivity;
2121
import org.schabi.newpipe.R;
2222
import org.schabi.newpipe.ReCaptchaActivity;
23+
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
2324
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
2425
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
26+
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
27+
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
28+
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
2529
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
30+
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
31+
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
2632
import org.schabi.newpipe.ktx.ExceptionUtils;
2733
import org.schabi.newpipe.report.ErrorActivity;
2834
import org.schabi.newpipe.report.ErrorInfo;
@@ -223,12 +229,30 @@ protected boolean onError(final Throwable exception) {
223229
if (exception instanceof ReCaptchaException) {
224230
onReCaptchaException((ReCaptchaException) exception);
225231
return true;
226-
} else if (exception instanceof ContentNotAvailableException) {
227-
showError(getString(R.string.content_not_available), false);
228-
return true;
229232
} else if (ExceptionUtils.isNetworkRelated(exception)) {
230233
showError(getString(R.string.network_error), true);
231234
return true;
235+
} else if (exception instanceof AgeRestrictedContentException) {
236+
showError(getString(R.string.restricted_video_no_stream), false);
237+
return true;
238+
} else if (exception instanceof GeographicRestrictionException) {
239+
showError(getString(R.string.georestricted_content), false);
240+
return true;
241+
} else if (exception instanceof PaidContentException) {
242+
showError(getString(R.string.paid_content), false);
243+
return true;
244+
} else if (exception instanceof PrivateContentException) {
245+
showError(getString(R.string.private_content), false);
246+
return true;
247+
} else if (exception instanceof SoundCloudGoPlusContentException) {
248+
showError(getString(R.string.soundcloud_go_plus_content), false);
249+
return true;
250+
} else if (exception instanceof YoutubeMusicPremiumContentException) {
251+
showError(getString(R.string.youtube_music_premium_content), false);
252+
return true;
253+
} else if (exception instanceof ContentNotAvailableException) {
254+
showError(getString(R.string.content_not_available), false);
255+
return true;
232256
} else if (exception instanceof ContentNotSupportedException) {
233257
showError(getString(R.string.content_not_supported), false);
234258
return true;

app/src/main/java/org/schabi/newpipe/util/ExtractorHelper.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2017 Mauricio Colli <mauriciocolli@outlook.com>
3-
* Extractors.java is part of NewPipe
3+
* ExtractorHelper.java is part of NewPipe
44
*
55
* License: GPL-3.0+
66
* This program is free software: you can redistribute it and/or modify
@@ -44,10 +44,16 @@
4444
import org.schabi.newpipe.extractor.StreamingService;
4545
import org.schabi.newpipe.extractor.channel.ChannelInfo;
4646
import org.schabi.newpipe.extractor.comments.CommentsInfo;
47+
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
4748
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
4849
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
50+
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
51+
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
4952
import org.schabi.newpipe.extractor.exceptions.ParsingException;
53+
import org.schabi.newpipe.extractor.exceptions.PrivateContentException;
5054
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
55+
import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException;
56+
import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException;
5157
import org.schabi.newpipe.extractor.feed.FeedExtractor;
5258
import org.schabi.newpipe.extractor.feed.FeedInfo;
5359
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
@@ -300,6 +306,21 @@ public static void handleGeneralException(final Context context, final int servi
300306
context.startActivity(intent);
301307
} else if (ExceptionUtils.isNetworkRelated(exception)) {
302308
Toast.makeText(context, R.string.network_error, Toast.LENGTH_LONG).show();
309+
} else if (exception instanceof AgeRestrictedContentException) {
310+
Toast.makeText(context, R.string.restricted_video_no_stream,
311+
Toast.LENGTH_LONG).show();
312+
} else if (exception instanceof GeographicRestrictionException) {
313+
Toast.makeText(context, R.string.georestricted_content, Toast.LENGTH_LONG).show();
314+
} else if (exception instanceof PaidContentException) {
315+
Toast.makeText(context, R.string.paid_content, Toast.LENGTH_LONG).show();
316+
} else if (exception instanceof PrivateContentException) {
317+
Toast.makeText(context, R.string.private_content, Toast.LENGTH_LONG).show();
318+
} else if (exception instanceof SoundCloudGoPlusContentException) {
319+
Toast.makeText(context, R.string.soundcloud_go_plus_content,
320+
Toast.LENGTH_LONG).show();
321+
} else if (exception instanceof YoutubeMusicPremiumContentException) {
322+
Toast.makeText(context, R.string.youtube_music_premium_content,
323+
Toast.LENGTH_LONG).show();
303324
} else if (exception instanceof ContentNotAvailableException) {
304325
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
305326
} else if (exception instanceof ContentNotSupportedException) {

app/src/main/res/values-fr/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,5 @@
665665
<string name="show_description_summary">Désactiver pour masquer la description de la vidéo et les informations supplémentaires</string>
666666
<string name="show_description_title">Afficher la description</string>
667667
<string name="crash_the_app">Plante l\'application</string>
668-
</resources>
668+
<string name="georestricted_content">Ce contenu n\'est pas disponible dans votre pays.</string>
669+
</resources>

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string name="main_bg_subtitle">Tap \"Search\" to get started
44
\n</string>
@@ -164,6 +164,7 @@
164164
<string name="youtube_restricted_mode_enabled_title">Turn on YouTube\'s \"Restricted Mode\"</string>
165165
<string name="youtube_restricted_mode_enabled_summary">YouTube provides a \"Restricted Mode\" which hides potentially mature content</string>
166166
<string name="restricted_video">This video is age restricted.\n\nTurn on \"%1$s\" in the settings if you want to see it.</string>
167+
<string name="restricted_video_no_stream">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.</string>
167168
<string name="duration_live">Live</string>
168169
<string name="downloads">Downloads</string>
169170
<string name="downloads_title">Downloads</string>
@@ -700,4 +701,9 @@
700701
<string name="recent">Recent</string>
701702
<string name="chapters">Chapters</string>
702703
<string name="no_app_to_open_intent">No app on your device can open this</string>
704+
<string name="georestricted_content">This content is not available in your country.</string>
705+
<string name="soundcloud_go_plus_content">This is a SoundCloud Go+ track, at least in your country, so it cannot be streamed or downloaded by NewPipe.</string>
706+
<string name="private_content">This content is private, so it cannot be streamed or downloaded by NewPipe.</string>
707+
<string name="youtube_music_premium_content">This video is available only to YouTube Music Premium members, so it cannot be streamed or downloaded by NewPipe.</string>
708+
<string name="paid_content">This content is only available to users who have paid, so it cannot be streamed or downloaded by NewPipe.</string>
703709
</resources>

0 commit comments

Comments
 (0)