Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error when video has age limit and setting is disabled #3410

Merged
merged 2 commits into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import io.reactivex.schedulers.Schedulers;

import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
import static org.schabi.newpipe.extractor.stream.StreamExtractor.NO_AGE_LIMIT;
import static org.schabi.newpipe.util.AnimationUtils.animateView;

public class VideoDetailFragment extends BaseStateFragment<StreamInfo>
Expand Down Expand Up @@ -806,19 +807,25 @@ public void startLoading(final boolean forceLoad) {
currentWorker.dispose();
}

final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);

currentWorker = ExtractorHelper.getStreamInfo(serviceId, url, forceLoad)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@NonNull StreamInfo result) -> {
.subscribe((@NonNull final StreamInfo result) -> {
isLoading.set(false);
currentInfo = result;
handleResult(result);
showContent();
}, (@NonNull Throwable throwable) -> {
if (result.getAgeLimit() != NO_AGE_LIMIT && !prefs.getBoolean(
getString(R.string.show_age_restricted_content), false)) {
hideAgeRestrictedContent();
} else {
currentInfo = result;
handleResult(result);
showContent();
}
}, (@NonNull final Throwable throwable) -> {
isLoading.set(false);
onError(throwable);
});

}

private void initTabs() {
Expand Down Expand Up @@ -1232,6 +1239,16 @@ public void handleResult(@NonNull final StreamInfo info) {
}
}

private void hideAgeRestrictedContent() {
showError(getString(R.string.restricted_video), false);

if (relatedStreamsLayout != null) { // tablet
relatedStreamsLayout.setVisibility(View.INVISIBLE);
}

viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
}

public void openDownloadDialog() {
try {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@
<string name="play_btn_text">Play</string>
<string name="content">Content</string>
<string name="show_age_restricted_content_title">Age restricted content</string>
<string name="duration_live">Live</string>
<string name="video_is_age_restricted">Show age restricted video. Future changes are possible from the settings.</string>
<string name="restricted_video">This video is age restricted.\n\nIf you want to view it, enable \"Age restricted content\" in the settings.</string>
<string name="duration_live">Live</string>
<string name="downloads">Downloads</string>
<string name="downloads_title">Downloads</string>
<string name="error_report_title">Error report</string>
Expand Down Expand Up @@ -638,4 +639,4 @@
<string name="feed_use_dedicated_fetch_method_disable_button">Disable fast mode</string>
<string name="feed_use_dedicated_fetch_method_help_text">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.</string>
<string name="content_not_supported">This content is not yet supported by NewPipe.\n\nIt will hopefully be supported in a future version.</string>
</resources>
</resources>