diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 4e391e4c7..e3c580238 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -89,6 +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.VideoSegment; import org.schabi.newpipe.util.external_communication.KoreUtils; import org.schabi.newpipe.util.ListHelper; @@ -1566,6 +1567,19 @@ public final class VideoDetailFragment binding.detailThumbsDisabledView.setVisibility(View.VISIBLE); } else { + if (info.getDislikeCount() == -1) { + new Thread(() -> { + info.setDislikeCount(ReturnYoutubeDislikeUtils.getDislikes(info)); + if (info.getDislikeCount() >= 0) { + activity.runOnUiThread(() -> { + binding.detailThumbsDownCountView.setText(Localization + .shortCount(activity, info.getDislikeCount())); + binding.detailThumbsDownCountView.setVisibility(View.VISIBLE); + binding.detailThumbsDownImgView.setVisibility(View.VISIBLE); + }); + } + }).start(); + } if (info.getDislikeCount() >= 0) { binding.detailThumbsDownCountView.setText(Localization .shortCount(activity, info.getDislikeCount())); diff --git a/app/src/main/java/org/schabi/newpipe/util/ReturnYoutubeDislikeUtils.java b/app/src/main/java/org/schabi/newpipe/util/ReturnYoutubeDislikeUtils.java new file mode 100644 index 000000000..452dbaff4 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/util/ReturnYoutubeDislikeUtils.java @@ -0,0 +1,68 @@ +package org.schabi.newpipe.util; + +import android.util.Log; + +import com.grack.nanojson.JsonObject; +import com.grack.nanojson.JsonParser; + +import org.schabi.newpipe.DownloaderImpl; +import org.schabi.newpipe.MainActivity; +import org.schabi.newpipe.extractor.stream.StreamInfo; + +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 boolean DEBUG = MainActivity.DEBUG; + + private ReturnYoutubeDislikeUtils() { + } + + @SuppressWarnings("CheckStyle") + 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); + + if (!isReturnYoutubeDislikeEnabled) { + return -1; + } + */ + + if (!streamInfo.getUrl().startsWith("https://www.youtube.com")) { + return -1; + } + + JsonObject response = null; + + try { + final String responseBody = + DownloaderImpl + .getInstance() + .setCustomTimeout(3) + .get(APIURL + streamInfo.getId()) + .responseBody(); + + response = JsonParser.object().from(responseBody); + + } catch (final Exception ex) { + if (DEBUG) { + Log.w(TAG, Log.getStackTraceString(ex)); + } + } + + if (response == null) { + return -1; + } + + if (response.has("dislikes")) { + return response.getInt("dislikes", 0); + } + + return -1; + } + +}