some small ReturnYouTubeDislike-related changes, and added a setting to toggle the functionality

This commit is contained in:
polymorphicshade 2022-01-29 20:16:45 -07:00
parent 38adce106c
commit ba5581d61f
5 changed files with 26 additions and 14 deletions

View file

@ -89,7 +89,7 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ReturnYoutubeDislikeUtils;
import org.schabi.newpipe.util.ReturnYouTubeDislikeUtils;
import org.schabi.newpipe.util.VideoSegment;
import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.ListHelper;
@ -1569,7 +1569,7 @@ public final class VideoDetailFragment
} else {
if (info.getDislikeCount() == -1) {
new Thread(() -> {
info.setDislikeCount(ReturnYoutubeDislikeUtils.getDislikes(info));
info.setDislikeCount(ReturnYouTubeDislikeUtils.getDislikes(getContext(), info));
if (info.getDislikeCount() >= 0) {
activity.runOnUiThread(() -> {
binding.detailThumbsDownCountView.setText(Localization

View file

@ -1,36 +1,39 @@
package org.schabi.newpipe.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.preference.PreferenceManager;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import org.schabi.newpipe.DownloaderImpl;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream.StreamInfo;
public final class ReturnYoutubeDislikeUtils {
public final class ReturnYouTubeDislikeUtils {
private static final String APIURL = "https://returnyoutubedislikeapi.com/votes?videoId=";
private static final String TAG = ReturnYoutubeDislikeUtils.class.getSimpleName();
private static final String API_URL = "https://returnyoutubedislikeapi.com/votes?videoId=";
private static final String TAG = ReturnYouTubeDislikeUtils.class.getSimpleName();
private static final boolean DEBUG = MainActivity.DEBUG;
private ReturnYoutubeDislikeUtils() {
private ReturnYouTubeDislikeUtils() {
}
@SuppressWarnings("CheckStyle")
public static int getDislikes(/*final Context context,*/
public static int getDislikes(final Context context,
final StreamInfo streamInfo) {
/*
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean isReturnYoutubeDislikeEnabled = prefs.getBoolean(context
.getString(R.string.return_youtube_dislikes_enable_key), false);
final boolean isReturnYouTubeDislikeEnabled = prefs.getBoolean(context
.getString(R.string.enable_return_youtube_dislike_key), false);
if (!isReturnYoutubeDislikeEnabled) {
if (!isReturnYouTubeDislikeEnabled) {
return -1;
}
*/
if (!streamInfo.getUrl().startsWith("https://www.youtube.com")) {
return -1;
@ -43,7 +46,7 @@ public final class ReturnYoutubeDislikeUtils {
DownloaderImpl
.getInstance()
.setCustomTimeout(3)
.get(APIURL + streamInfo.getId())
.get(API_URL + streamInfo.getId())
.responseBody();
response = JsonParser.object().from(responseBody);
@ -64,5 +67,4 @@ public final class ReturnYoutubeDislikeUtils {
return -1;
}
}

View file

@ -415,6 +415,7 @@
<string name="sponsor_block_clear_whitelist_key" translatable="false">sponsor_block_clear_whitelist</string>
<!-- Extras -->
<string name="enable_return_youtube_dislike_key" translatable="false">enable_return_youtube_dislike</string>
<string name="enable_local_player_key" translatable="false">enable_local_player</string>
<string name="force_auto_fullscreen_key" translatable="false">force_auto_fullscreen</string>
<string name="disable_error_reports_key" translatable="false">disable_error_reports</string>

View file

@ -778,4 +778,6 @@
<string name="force_auto_fullscreen_summary">If enabled, when the device is set to landscape, force fullscreen mode even if the device is a tablet or TV.</string>
<string name="disable_error_reports_title">Disable Error Reporting</string>
<string name="disable_error_reports_summary">Prevent all error reporting screens from appearing. This may result in the app behaving unexpectedly. <b>USE AT YOUR OWN RISK!</b></string>
<string name="enable_return_youtube_dislike_title">Show Dislike Count</string>
<string name="enable_return_youtube_dislike_summary">Use the ReturnYouTubeDislike API to show the amount of dislikes for a video. This only works for YouTube videos.\n<b>WARNING: Your IP address will be visible to the API. Use at your own risk!</b></string>
</resources>

View file

@ -33,5 +33,12 @@
android:key="@string/disable_error_reports_key"
android:summary="@string/disable_error_reports_summary"
android:title="@string/disable_error_reports_title"/>
<SwitchPreference
app:iconSpaceReserved="false"
android:defaultValue="false"
android:key="@string/enable_return_youtube_dislike_key"
android:summary="@string/enable_return_youtube_dislike_summary"
android:title="@string/enable_return_youtube_dislike_title"/>
</PreferenceCategory>
</PreferenceScreen>