From cd3edfe07fa655a1ba1fc33c82a16fa713465473 Mon Sep 17 00:00:00 2001 From: xfileFIN Date: Sat, 24 Jul 2021 02:48:33 +0300 Subject: [PATCH] Skipped video length fixed --- .../java/pl/jakubweg/PlayerController.java | 2 +- .../java/pl/jakubweg/SponsorBlockUtils.java | 46 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/pl/jakubweg/PlayerController.java b/app/src/main/java/pl/jakubweg/PlayerController.java index 2afd00a5..e884f575 100644 --- a/app/src/main/java/pl/jakubweg/PlayerController.java +++ b/app/src/main/java/pl/jakubweg/PlayerController.java @@ -335,7 +335,7 @@ public class PlayerController { public static void setSponsorBarRect(final Object self) { try { - Field field = self.getClass().getDeclaredField("e"); + Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect"); field.setAccessible(true); Rect rect = (Rect) field.get(self); if (rect != null) { diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java index 127a07b1..4914fb38 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java @@ -26,6 +26,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; import java.util.TimeZone; +import java.util.concurrent.TimeUnit; import pl.jakubweg.objects.SponsorSegment; import pl.jakubweg.objects.UserStats; @@ -49,12 +50,8 @@ import static pl.jakubweg.requests.Requester.voteForSegment; public abstract class SponsorBlockUtils { public static final String TAG = "jakubweg.SponsorBlockUtils"; public static final String DATE_FORMAT = "HH:mm:ss.SSS"; - public static final String WITHOUT_SEGMENTS_FORMAT = " (m:ss)"; - public static final String WITHOUT_SEGMENTS_FORMAT_H = " (H:m:ss)"; @SuppressLint("SimpleDateFormat") public static final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT); - public static final SimpleDateFormat withoutSegmentsFormatter = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT); - public static final SimpleDateFormat withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H); public static boolean videoHasSegments = false; public static String timeWithoutSegments = ""; private static final int sponsorBtnId = 1234; @@ -414,8 +411,45 @@ public abstract class SponsorBlockUtils { for (SponsorSegment segment : sponsorSegmentsOfCurrentVideo) { timeWithoutSegments -= segment.end - segment.start; } - Date date = new Date(timeWithoutSegments); - return timeWithoutSegments >= 3600000 ? withoutSegmentsFormatterH.format(date) : withoutSegmentsFormatter.format(date); + return String.format(" (%s)", formatToVideoTimeString(TimeUnit.MILLISECONDS.toSeconds(timeWithoutSegments + 500L), 3)); + } + + public static String formatToVideoTimeString(long seconds, int padAmount) { + StringBuilder sb = new StringBuilder(); + sb.append(seconds >= 0L ? "" : "-"); + long abs_seconds = Math.abs(seconds); + long minutes = abs_seconds / 60L; + long hours = minutes / 60L; + if(hours > 0L) { + minutes %= 60L; + padAmount = Math.max(padAmount, 5); + } + + String seconds_str = Long.toString(abs_seconds % 60L); + if(seconds_str.length() == 1) { + String safe_str = String.valueOf(seconds_str); + seconds_str = safe_str.length() == 0 ? new String("0") : "0".concat(safe_str); + } + + String minutes_str = Long.toString(minutes); + if(minutes_str.length() == 1 && padAmount > 3) { + String safe_str = String.valueOf(minutes_str); + minutes_str = safe_str.length() == 0 ? new String("0") : "0".concat(safe_str); + } + + if(padAmount > 4) { + sb.append(hours); + sb.append(':'); + sb.append(minutes_str); + sb.append(':'); + sb.append(seconds_str); + return sb.toString(); + } + + sb.append(minutes_str); + sb.append(':'); + sb.append(seconds_str); + return sb.toString(); } public static void playerTypeChanged(String playerType) {