mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-12-11 21:17:47 +01:00
Merge remote-tracking branch 'upstream/length-without-segments-pr' into feature/length-without-segments
This commit is contained in:
commit
13a12c9523
@ -1,9 +1,11 @@
|
|||||||
package fi.vanced.libraries.youtube.player;
|
package fi.vanced.libraries.youtube.player;
|
||||||
|
|
||||||
import fi.vanced.libraries.youtube.sponsors.player.ui.SponsorBlockView;
|
import fi.vanced.libraries.youtube.sponsors.player.ui.SponsorBlockView;
|
||||||
|
import pl.jakubweg.SponsorBlockUtils;
|
||||||
|
|
||||||
public class PlayerType {
|
public class PlayerType {
|
||||||
public static void playerTypeChanged(String playerType) {
|
public static void playerTypeChanged(String playerType) {
|
||||||
SponsorBlockView.playerTypeChanged(playerType);
|
SponsorBlockView.playerTypeChanged(playerType);
|
||||||
|
SponsorBlockUtils.playerTypeChanged(playerType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import java.util.Objects;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import fi.razerman.youtube.Helpers.XSwipeHelper;
|
import fi.razerman.youtube.Helpers.XSwipeHelper;
|
||||||
|
import fi.razerman.youtube.XGlobals;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
@ -59,6 +60,8 @@ public abstract class SponsorBlockUtils {
|
|||||||
public static final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT);
|
public static final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT);
|
||||||
public static final SimpleDateFormat withoutSegmentsFormatter = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT);
|
public static final SimpleDateFormat withoutSegmentsFormatter = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT);
|
||||||
public static final SimpleDateFormat withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H);
|
public static final SimpleDateFormat withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H);
|
||||||
|
private static boolean videoHasSegments = false;
|
||||||
|
private static boolean needToAppendTime = false;
|
||||||
private static final int sponsorBtnId = 1234;
|
private static final int sponsorBtnId = 1234;
|
||||||
public static final View.OnClickListener sponsorBlockBtnListener = new View.OnClickListener() {
|
public static final View.OnClickListener sponsorBlockBtnListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -471,9 +474,13 @@ public abstract class SponsorBlockUtils {
|
|||||||
switch (connection.getResponseCode()) {
|
switch (connection.getResponseCode()) {
|
||||||
default:
|
default:
|
||||||
Log.e(TAG, "Unable to download segments: Status: " + connection.getResponseCode() + " " + connection.getResponseMessage());
|
Log.e(TAG, "Unable to download segments: Status: " + connection.getResponseCode() + " " + connection.getResponseMessage());
|
||||||
|
videoHasSegments = false;
|
||||||
|
needToAppendTime = false;
|
||||||
break;
|
break;
|
||||||
case 404:
|
case 404:
|
||||||
Log.w(TAG, "No segments for this video (ERR404)");
|
Log.w(TAG, "No segments for this video (ERR404)");
|
||||||
|
videoHasSegments = false;
|
||||||
|
needToAppendTime = false;
|
||||||
break;
|
break;
|
||||||
case 200:
|
case 200:
|
||||||
if (VERBOSE)
|
if (VERBOSE)
|
||||||
@ -507,6 +514,9 @@ public abstract class SponsorBlockUtils {
|
|||||||
|
|
||||||
if (VERBOSE)
|
if (VERBOSE)
|
||||||
Log.v(TAG, "Parsing done");
|
Log.v(TAG, "Parsing done");
|
||||||
|
|
||||||
|
videoHasSegments = true;
|
||||||
|
needToAppendTime = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,11 +526,6 @@ public abstract class SponsorBlockUtils {
|
|||||||
Log.e(TAG, "download segments failed", e);
|
Log.e(TAG, "download segments failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
View layout = XSwipeHelper.nextGenWatchLayout.findViewById(getIdentifier("player_overlays", "id"));
|
|
||||||
View bar = layout.findViewById(getIdentifier("time_bar_total_time", "id"));
|
|
||||||
|
|
||||||
((TextView) bar).append(getTimeWithoutSegments());
|
|
||||||
|
|
||||||
return sponsorSegments.toArray(new SponsorSegment[0]);
|
return sponsorSegments.toArray(new SponsorSegment[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,6 +586,35 @@ public abstract class SponsorBlockUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void forceAppendTimeWithoutSegments() {
|
||||||
|
appendTimeWithoutSegments(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void appendTimeWithoutSegments() {
|
||||||
|
appendTimeWithoutSegments(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void appendTimeWithoutSegments(boolean forceAppend) {
|
||||||
|
try {
|
||||||
|
if (!videoHasSegments || (!needToAppendTime && !forceAppend)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
View layout = XSwipeHelper.nextGenWatchLayout.findViewById(getIdentifier("player_overlays", "id"));
|
||||||
|
if (layout != null) {
|
||||||
|
View bar = layout.findViewById(getIdentifier("time_bar_total_time", "id"));
|
||||||
|
((TextView) bar).append(getTimeWithoutSegments());
|
||||||
|
}
|
||||||
|
else if (XGlobals.debug){
|
||||||
|
Log.d(TAG, "player_overlays was not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
needToAppendTime = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setting the time without segments failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getTimeWithoutSegments() {
|
public static String getTimeWithoutSegments() {
|
||||||
if (!SponsorBlockSettings.isSponsorBlockEnabled || sponsorSegmentsOfCurrentVideo == null) {
|
if (!SponsorBlockSettings.isSponsorBlockEnabled || sponsorSegmentsOfCurrentVideo == null) {
|
||||||
return "";
|
return "";
|
||||||
@ -593,6 +627,18 @@ public abstract class SponsorBlockUtils {
|
|||||||
return timeWithoutSegments >= 3600000 ? withoutSegmentsFormatterH.format(date) : withoutSegmentsFormatter.format(date);
|
return timeWithoutSegments >= 3600000 ? withoutSegmentsFormatterH.format(date) : withoutSegmentsFormatter.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void playerTypeChanged(String playerType) {
|
||||||
|
try {
|
||||||
|
if (videoHasSegments && (playerType.equalsIgnoreCase("NONE"))) {
|
||||||
|
needToAppendTime = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Log.e(TAG, "Player type changed caused a crash.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private enum VoteOption {
|
private enum VoteOption {
|
||||||
UPVOTE(str("vote_upvote")),
|
UPVOTE(str("vote_upvote")),
|
||||||
DOWNVOTE(str("vote_downvote")),
|
DOWNVOTE(str("vote_downvote")),
|
||||||
|
Loading…
Reference in New Issue
Block a user