some small ReturnYouTubeDislike-related changes, and added a setting to toggle the functionality
This commit is contained in:
parent
38adce106c
commit
ba5581d61f
5 changed files with 26 additions and 14 deletions
|
@ -89,7 +89,7 @@ import org.schabi.newpipe.player.playqueue.SinglePlayQueue;
|
||||||
import org.schabi.newpipe.util.Constants;
|
import org.schabi.newpipe.util.Constants;
|
||||||
import org.schabi.newpipe.util.DeviceUtils;
|
import org.schabi.newpipe.util.DeviceUtils;
|
||||||
import org.schabi.newpipe.util.ExtractorHelper;
|
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.VideoSegment;
|
||||||
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
||||||
import org.schabi.newpipe.util.ListHelper;
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
|
@ -1569,7 +1569,7 @@ public final class VideoDetailFragment
|
||||||
} else {
|
} else {
|
||||||
if (info.getDislikeCount() == -1) {
|
if (info.getDislikeCount() == -1) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
info.setDislikeCount(ReturnYoutubeDislikeUtils.getDislikes(info));
|
info.setDislikeCount(ReturnYouTubeDislikeUtils.getDislikes(getContext(), info));
|
||||||
if (info.getDislikeCount() >= 0) {
|
if (info.getDislikeCount() >= 0) {
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
binding.detailThumbsDownCountView.setText(Localization
|
binding.detailThumbsDownCountView.setText(Localization
|
||||||
|
|
|
@ -1,36 +1,39 @@
|
||||||
package org.schabi.newpipe.util;
|
package org.schabi.newpipe.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
|
|
||||||
import org.schabi.newpipe.DownloaderImpl;
|
import org.schabi.newpipe.DownloaderImpl;
|
||||||
import org.schabi.newpipe.MainActivity;
|
import org.schabi.newpipe.MainActivity;
|
||||||
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
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 API_URL = "https://returnyoutubedislikeapi.com/votes?videoId=";
|
||||||
private static final String TAG = ReturnYoutubeDislikeUtils.class.getSimpleName();
|
private static final String TAG = ReturnYouTubeDislikeUtils.class.getSimpleName();
|
||||||
private static final boolean DEBUG = MainActivity.DEBUG;
|
private static final boolean DEBUG = MainActivity.DEBUG;
|
||||||
|
|
||||||
private ReturnYoutubeDislikeUtils() {
|
private ReturnYouTubeDislikeUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("CheckStyle")
|
@SuppressWarnings("CheckStyle")
|
||||||
public static int getDislikes(/*final Context context,*/
|
public static int getDislikes(final Context context,
|
||||||
final StreamInfo streamInfo) {
|
final StreamInfo streamInfo) {
|
||||||
/*
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
final boolean isReturnYoutubeDislikeEnabled = prefs.getBoolean(context
|
final boolean isReturnYouTubeDislikeEnabled = prefs.getBoolean(context
|
||||||
.getString(R.string.return_youtube_dislikes_enable_key), false);
|
.getString(R.string.enable_return_youtube_dislike_key), false);
|
||||||
|
|
||||||
if (!isReturnYoutubeDislikeEnabled) {
|
if (!isReturnYouTubeDislikeEnabled) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
if (!streamInfo.getUrl().startsWith("https://www.youtube.com")) {
|
if (!streamInfo.getUrl().startsWith("https://www.youtube.com")) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -43,7 +46,7 @@ public final class ReturnYoutubeDislikeUtils {
|
||||||
DownloaderImpl
|
DownloaderImpl
|
||||||
.getInstance()
|
.getInstance()
|
||||||
.setCustomTimeout(3)
|
.setCustomTimeout(3)
|
||||||
.get(APIURL + streamInfo.getId())
|
.get(API_URL + streamInfo.getId())
|
||||||
.responseBody();
|
.responseBody();
|
||||||
|
|
||||||
response = JsonParser.object().from(responseBody);
|
response = JsonParser.object().from(responseBody);
|
||||||
|
@ -64,5 +67,4 @@ public final class ReturnYoutubeDislikeUtils {
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -415,6 +415,7 @@
|
||||||
<string name="sponsor_block_clear_whitelist_key" translatable="false">sponsor_block_clear_whitelist</string>
|
<string name="sponsor_block_clear_whitelist_key" translatable="false">sponsor_block_clear_whitelist</string>
|
||||||
|
|
||||||
<!-- Extras -->
|
<!-- 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="enable_local_player_key" translatable="false">enable_local_player</string>
|
||||||
<string name="force_auto_fullscreen_key" translatable="false">force_auto_fullscreen</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>
|
<string name="disable_error_reports_key" translatable="false">disable_error_reports</string>
|
||||||
|
|
|
@ -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="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_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="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>
|
</resources>
|
|
@ -33,5 +33,12 @@
|
||||||
android:key="@string/disable_error_reports_key"
|
android:key="@string/disable_error_reports_key"
|
||||||
android:summary="@string/disable_error_reports_summary"
|
android:summary="@string/disable_error_reports_summary"
|
||||||
android:title="@string/disable_error_reports_title"/>
|
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>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Add table
Reference in a new issue