Skipped video length fixed

This commit is contained in:
xfileFIN 2021-07-24 02:48:33 +03:00
parent 9be95a105b
commit f79eb0a01f
2 changed files with 41 additions and 7 deletions

View File

@ -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) {

View File

@ -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) {