Fix segments not appearing when loaded early

This commit is contained in:
Ajay Ramachandran
2021-10-01 18:07:15 -04:00
parent 23a91c626d
commit ef70e71051
2 changed files with 8 additions and 1 deletions

View File

@@ -386,6 +386,12 @@ function createPreviewBar(): void {
function durationChangeListener(): void { function durationChangeListener(): void {
updateAdFlag(); updateAdFlag();
updatePreviewBar(); updatePreviewBar();
sponsorTimes = sponsorTimes.filter(segmentDurationFilter);
}
function segmentDurationFilter(segment: SponsorTime): boolean {
return segment.videoDuration === 0 || video.duration === 0 || Math.abs(video.duration - segment.videoDuration) < 2;
} }
function cancelSponsorSchedule(): void { function cancelSponsorSchedule(): void {
@@ -669,7 +675,7 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
const recievedSegments: SponsorTime[] = JSON.parse(response.responseText) const recievedSegments: SponsorTime[] = JSON.parse(response.responseText)
?.filter((video) => video.videoID === id) ?.filter((video) => video.videoID === id)
?.map((video) => video.segments)[0] ?.map((video) => video.segments)[0]
?.filter((segment) => segment.videoDuration === 0 || Math.abs(video.duration - segment.videoDuration) < 2); ?.filter(segmentDurationFilter);
if (!recievedSegments || !recievedSegments.length) { if (!recievedSegments || !recievedSegments.length) {
// return if no video found // return if no video found
retryFetch(); retryFetch();

View File

@@ -80,6 +80,7 @@ export interface SponsorTime {
hidden?: SponsorHideType; hidden?: SponsorHideType;
source?: SponsorSourceType; source?: SponsorSourceType;
videoDuration?: number;
} }
export interface ScheduledTime extends SponsorTime { export interface ScheduledTime extends SponsorTime {