Add a basic implementation for returnyoutubedislike.com

This commit is contained in:
tr7zw 2022-01-28 21:33:08 +01:00
parent eb2ddd6b48
commit bc9303bd9a
2 changed files with 80 additions and 0 deletions

View file

@ -89,6 +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.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;
@ -1566,6 +1567,17 @@ public final class VideoDetailFragment
binding.detailThumbsDisabledView.setVisibility(View.VISIBLE); binding.detailThumbsDisabledView.setVisibility(View.VISIBLE);
} else { } else {
if (info.getDislikeCount() == -1) {
new Thread(() -> {
info.setDislikeCount(ReturnYoutubeDislikeUtils.getDislikes(info));
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) { if (info.getDislikeCount() >= 0) {
binding.detailThumbsDownCountView.setText(Localization binding.detailThumbsDownCountView.setText(Localization
.shortCount(activity, info.getDislikeCount())); .shortCount(activity, info.getDislikeCount()));

View file

@ -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;
}
}