mirror of
https://github.com/revanced/revanced-patches
synced 2025-02-19 06:36:49 +01:00
Merge pull request #44 from YTVanced/length-without-segments-pr
Length without segments pr
This commit is contained in:
commit
10326aec28
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,8 @@ public class PlayerController {
|
|||||||
|
|
||||||
public static void setCurrentVideoId(final String videoId) {
|
public static void setCurrentVideoId(final String videoId) {
|
||||||
if (videoId == null) {
|
if (videoId == null) {
|
||||||
Log.d(TAG, "setCurrentVideoId: videoId is null");
|
currentVideoId = null;
|
||||||
|
sponsorSegmentsOfCurrentVideo = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import static pl.jakubweg.SponsorBlockSettings.DefaultBehaviour;
|
|||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_ADJUST_NEW_SEGMENT_STEP;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_NEW_SEGMENT_ENABLED;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_NEW_SEGMENT_ENABLED;
|
||||||
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_UUID;
|
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_UUID;
|
||||||
@ -32,6 +33,7 @@ import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_NAME;
|
|||||||
import static pl.jakubweg.SponsorBlockSettings.adjustNewSegmentMillis;
|
import static pl.jakubweg.SponsorBlockSettings.adjustNewSegmentMillis;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.countSkips;
|
import static pl.jakubweg.SponsorBlockSettings.countSkips;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.setSeenGuidelines;
|
import static pl.jakubweg.SponsorBlockSettings.setSeenGuidelines;
|
||||||
|
import static pl.jakubweg.SponsorBlockSettings.showTimeWithoutSegments;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
|
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
|
||||||
import static pl.jakubweg.SponsorBlockSettings.uuid;
|
import static pl.jakubweg.SponsorBlockSettings.uuid;
|
||||||
import static pl.jakubweg.StringRef.str;
|
import static pl.jakubweg.StringRef.str;
|
||||||
@ -247,6 +249,16 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
|
|||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Preference preference = new SwitchPreference(context);
|
||||||
|
preference.setTitle(str("general_time_without_sb"));
|
||||||
|
preference.setSummary(str("general_time_without_sb_sum"));
|
||||||
|
preference.setKey(PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS);
|
||||||
|
preference.setDefaultValue(showTimeWithoutSegments);
|
||||||
|
preferencesToDisableWhenSBDisabled.add(preference);
|
||||||
|
screen.addPreference(preference);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
EditTextPreference preference = new EditTextPreference(context);
|
EditTextPreference preference = new EditTextPreference(context);
|
||||||
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||||
|
@ -28,7 +28,7 @@ public class SponsorBlockSettings {
|
|||||||
public static final String sponsorBlockSkipSegmentsUrl = "https://sponsor.ajay.app/api/skipSegments";
|
public static final String sponsorBlockSkipSegmentsUrl = "https://sponsor.ajay.app/api/skipSegments";
|
||||||
public static final String sponsorBlockViewedUrl = "https://sponsor.ajay.app/api/viewedVideoSponsorTime";
|
public static final String sponsorBlockViewedUrl = "https://sponsor.ajay.app/api/viewedVideoSponsorTime";
|
||||||
public static final String sponsorBlockVoteUrl = "https://sponsor.ajay.app/api/voteOnSponsorTime";
|
public static final String sponsorBlockVoteUrl = "https://sponsor.ajay.app/api/voteOnSponsorTime";
|
||||||
|
public static final String PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS = "sb-length-without-segments";
|
||||||
|
|
||||||
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SkipAutomatically;
|
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SkipAutomatically;
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ public class SponsorBlockSettings {
|
|||||||
public static boolean isVotingEnabled = true;
|
public static boolean isVotingEnabled = true;
|
||||||
public static boolean showToastWhenSkippedAutomatically = true;
|
public static boolean showToastWhenSkippedAutomatically = true;
|
||||||
public static boolean countSkips = true;
|
public static boolean countSkips = true;
|
||||||
|
public static boolean showTimeWithoutSegments = true;
|
||||||
public static int adjustNewSegmentMillis = 150;
|
public static int adjustNewSegmentMillis = 150;
|
||||||
public static String uuid = "<invalid>";
|
public static String uuid = "<invalid>";
|
||||||
private static String sponsorBlockUrlCategories = "[]";
|
private static String sponsorBlockUrlCategories = "[]";
|
||||||
@ -140,6 +141,7 @@ public class SponsorBlockSettings {
|
|||||||
adjustNewSegmentMillis = Integer.parseInt(tmp1);
|
adjustNewSegmentMillis = Integer.parseInt(tmp1);
|
||||||
|
|
||||||
countSkips = preferences.getBoolean(PREFERENCES_KEY_COUNT_SKIPS, countSkips);
|
countSkips = preferences.getBoolean(PREFERENCES_KEY_COUNT_SKIPS, countSkips);
|
||||||
|
showTimeWithoutSegments = preferences.getBoolean(PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS, showTimeWithoutSegments);
|
||||||
|
|
||||||
uuid = preferences.getString(PREFERENCES_KEY_UUID, null);
|
uuid = preferences.getString(PREFERENCES_KEY_UUID, null);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
|
@ -7,12 +7,16 @@ import android.content.DialogInterface;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -32,6 +36,9 @@ import java.util.Locale;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
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;
|
||||||
import static fi.razerman.youtube.XGlobals.debug;
|
import static fi.razerman.youtube.XGlobals.debug;
|
||||||
@ -48,8 +55,14 @@ import static pl.jakubweg.StringRef.str;
|
|||||||
public abstract class SponsorBlockUtils {
|
public abstract class SponsorBlockUtils {
|
||||||
public static final String TAG = "jakubweg.SponsorBlockUtils";
|
public static final String TAG = "jakubweg.SponsorBlockUtils";
|
||||||
public static final String DATE_FORMAT = "HH:mm:ss.SSS";
|
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")
|
@SuppressLint("SimpleDateFormat")
|
||||||
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 withoutSegmentsFormatterH = new SimpleDateFormat(WITHOUT_SEGMENTS_FORMAT_H);
|
||||||
|
private static boolean videoHasSegments = false;
|
||||||
|
private static String timeWithoutSegments = "";
|
||||||
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
|
||||||
@ -459,6 +472,8 @@ public abstract class SponsorBlockUtils {
|
|||||||
URL url = new URL(SponsorBlockSettings.getSponsorBlockUrlWithCategories(videoId));
|
URL url = new URL(SponsorBlockSettings.getSponsorBlockUrlWithCategories(videoId));
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
videoHasSegments = false;
|
||||||
|
timeWithoutSegments = "";
|
||||||
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());
|
||||||
@ -498,6 +513,8 @@ public abstract class SponsorBlockUtils {
|
|||||||
|
|
||||||
if (VERBOSE)
|
if (VERBOSE)
|
||||||
Log.v(TAG, "Parsing done");
|
Log.v(TAG, "Parsing done");
|
||||||
|
|
||||||
|
videoHasSegments = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,9 +524,16 @@ public abstract class SponsorBlockUtils {
|
|||||||
Log.e(TAG, "download segments failed", e);
|
Log.e(TAG, "download segments failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeWithoutSegments = getTimeWithoutSegments(sponsorSegments);
|
||||||
|
|
||||||
return sponsorSegments.toArray(new SponsorSegment[0]);
|
return sponsorSegments.toArray(new SponsorSegment[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getIdentifier(String name, String defType) {
|
||||||
|
Context context = YouTubeTikTokRoot_Application.getAppContext();
|
||||||
|
return context.getResources().getIdentifier(name, defType, context.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendViewCountRequest(SponsorSegment segment) {
|
public static void sendViewCountRequest(SponsorSegment segment) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(SponsorBlockSettings.getSponsorBlockViewedUrl(segment.UUID));
|
URL url = new URL(SponsorBlockSettings.getSponsorBlockViewedUrl(segment.UUID));
|
||||||
@ -562,6 +586,38 @@ public abstract class SponsorBlockUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String appendTimeWithoutSegments(String totalTime) {
|
||||||
|
if (videoHasSegments && SponsorBlockSettings.showTimeWithoutSegments && !TextUtils.isEmpty(totalTime)) {
|
||||||
|
return totalTime + timeWithoutSegments;
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTimeWithoutSegments(ArrayList<SponsorSegment> sponsorSegmentsOfCurrentVideo) {
|
||||||
|
if (!SponsorBlockSettings.isSponsorBlockEnabled || !SponsorBlockSettings.showTimeWithoutSegments || sponsorSegmentsOfCurrentVideo == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
long timeWithoutSegments = PlayerController.getCurrentVideoLength();
|
||||||
|
for (SponsorSegment segment : sponsorSegmentsOfCurrentVideo) {
|
||||||
|
timeWithoutSegments -= segment.end - segment.start;
|
||||||
|
}
|
||||||
|
Date date = new Date(timeWithoutSegments);
|
||||||
|
return timeWithoutSegments >= 3600000 ? withoutSegmentsFormatterH.format(date) : withoutSegmentsFormatter.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playerTypeChanged(String playerType) {
|
||||||
|
try {
|
||||||
|
if (videoHasSegments && (playerType.equalsIgnoreCase("NONE"))) {
|
||||||
|
PlayerController.setCurrentVideoId(null);
|
||||||
|
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")),
|
||||||
|
@ -151,6 +151,8 @@
|
|||||||
<string name="general_skiptoast_sum">Click to see an example toast</string>
|
<string name="general_skiptoast_sum">Click to see an example toast</string>
|
||||||
<string name="general_skipcount">Skip count tracking</string>
|
<string name="general_skipcount">Skip count tracking</string>
|
||||||
<string name="general_skipcount_sum">This lets SponsorBlock leaderboard system know how much time people have saved. The extension sends a message to the server each time you skip a segment.</string>
|
<string name="general_skipcount_sum">This lets SponsorBlock leaderboard system know how much time people have saved. The extension sends a message to the server each time you skip a segment.</string>
|
||||||
|
<string name="general_time_without_sb">Show time without segments</string>
|
||||||
|
<string name="general_time_without_sb_sum">This time appears in brackets next to the current time. This shows the total video duration minus any segments.</string>
|
||||||
<string name="general_adjusting">Adjusting new segment step</string>
|
<string name="general_adjusting">Adjusting new segment step</string>
|
||||||
<string name="general_adjusting_sum">This is the number of milliseconds you can move when you use the time adjustment buttons while adding new segment</string>
|
<string name="general_adjusting_sum">This is the number of milliseconds you can move when you use the time adjustment buttons while adding new segment</string>
|
||||||
<string name="general_uuid">Your unique user id</string>
|
<string name="general_uuid">Your unique user id</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user