Add importing chapters for cases with unsubmitted segments

This commit is contained in:
Ajay
2022-02-24 02:21:22 -05:00
parent 00ab317a3e
commit 7d8188d575

View File

@@ -812,17 +812,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
updatePreviewBar();
}
// Add existing chapters if we can
if (Config.config.renderAsChapters) {
GenericUtils.wait(() => getExistingChapters(sponsorVideoID, video.duration),
5000, 100, (c) => c?.length > 0).then((chapters) => {
if (!existingChaptersImported && chapters?.length > 0) {
sponsorTimes = sponsorTimes.concat(...chapters);
existingChaptersImported = true;
updatePreviewBar();
}
});
}
importExistingChapters(true);
} else if (response?.status === 404) {
retryFetch();
}
@@ -830,6 +820,20 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
lookupVipInformation(id);
}
function importExistingChapters(wait: boolean) {
if (Config.config.renderAsChapters && !existingChaptersImported
&& (sponsorTimes?.length > 0 || sponsorTimesSubmitting.length > 0)) {
GenericUtils.wait(() => video && getExistingChapters(sponsorVideoID, video.duration),
wait ? 5000 : 0, 100, (c) => c?.length > 0).then((chapters) => {
if (!existingChaptersImported && chapters?.length > 0) {
sponsorTimes = (sponsorTimes ?? []).concat(...chapters);
existingChaptersImported = true;
updatePreviewBar();
}
});
}
}
function getEnabledActionTypes(): ActionType[] {
const actionTypes = [ActionType.Skip, ActionType.Poi, ActionType.Chapter];
if (Config.config.muteSegments) {
@@ -1586,6 +1590,8 @@ function startOrEndTimingNewSegment() {
updateEditButtonsOnPlayer();
updateSponsorTimesSubmitting(false);
importExistingChapters(false);
}
function getIncompleteSegment(): SponsorTime {
@@ -1628,6 +1634,10 @@ function updateSponsorTimesSubmitting(getFromConfig = true) {
source: segmentTime.source
});
}
if (sponsorTimesSubmitting.length > 0) {
importExistingChapters(true);
}
}
updatePreviewBar();