Merge pull request #127 from tr7zw/sponsorblock

Adding support for returnyoutubedislike.com
This commit is contained in:
poly 2022-01-29 19:43:05 -07:00 committed by GitHub
commit 636142fc3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 82 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,19 @@ 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));
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) { 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;
}
}