add intro skipping
This commit is contained in:
43
script.js
43
script.js
@@ -7,7 +7,7 @@ let useTrailers = true; // Set to false to disable trailers
|
|||||||
let setRandomMovie = true; // Set to false to disable random movie selection from the list
|
let setRandomMovie = true; // Set to false to disable random movie selection from the list
|
||||||
let showOnOtherPages = false; // Set to true to show the slideshow on all pages eg. favorites tab, requests tab, etc.
|
let showOnOtherPages = false; // Set to true to show the slideshow on all pages eg. favorites tab, requests tab, etc.
|
||||||
//let showTitle = false; // Set to false to hide the title TBD
|
//let showTitle = false; // Set to false to hide the title TBD
|
||||||
let disableTrailerControls = true; // Set to false to enable trailer controls
|
let disableTrailerControls = false; // Set to false to enable trailer controls
|
||||||
let setMutedHover = true; // Set to false to disable unmuting the video on hover
|
let setMutedHover = true; // Set to false to disable unmuting the video on hover
|
||||||
let umuteOnHover = true; // Set to false to disable unmuting the video on hover
|
let umuteOnHover = true; // Set to false to disable unmuting the video on hover
|
||||||
let unmutedVolume = 20; // Set the volume level when the video is unmuted
|
let unmutedVolume = 20; // Set the volume level when the video is unmuted
|
||||||
@@ -42,18 +42,28 @@ if (setMutedHover) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get SponsorBlock-Data for the outro segment of the trailer
|
// Get SponsorBlock-Data for the outro/intro segment of the trailer
|
||||||
const fetchSponsorBlockOutro = async (videoId) => {
|
const fetchSponsorBlockData = async (videoId) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&category=outro`);
|
const response = await fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoId}&categories=["intro","outro"]`);
|
||||||
const segments = await response.json();
|
const segments = await response.json();
|
||||||
if (segments.length > 0 && Array.isArray(segments[0].segment)) {
|
|
||||||
return segments[0].segment; // returns array: [start, end]
|
let intro = null;
|
||||||
}
|
let outro = null;
|
||||||
return null;
|
|
||||||
|
segments.forEach(segment => {
|
||||||
|
if (segment.category === "intro" && Array.isArray(segment.segment)) {
|
||||||
|
intro = segment.segment; // [start, end] of the intro
|
||||||
|
} else if (segment.category === "outro" && Array.isArray(segment.segment)) {
|
||||||
|
outro = segment.segment; // [start, end] of the outro
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return { intro, outro };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching SponsorBlock data:', error);
|
console.error('Error fetching SponsorBlock data:', error);
|
||||||
return null;
|
return null;
|
||||||
|
//return { intro: null, outro: null };
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -287,15 +297,24 @@ const createSlideElement = (movie, hasVideo = false) => {
|
|||||||
events: {
|
events: {
|
||||||
'onReady': event => {
|
'onReady': event => {
|
||||||
if (useSponsorBlock) {
|
if (useSponsorBlock) {
|
||||||
fetchSponsorBlockOutro(videoId).then(outroSegment => {
|
fetchSponsorBlockData(videoId).then(({ intro, outro }) => {
|
||||||
if (outroSegment) {
|
if (intro) {
|
||||||
console.log(`SponsorBlock outro segment: Start - ${outroSegment[0]}s, End - ${outroSegment[1]}s`);
|
console.log(`SponsorBlock intro segment: Start - ${intro[0]}s, End - ${intro[1]}s`);
|
||||||
|
if (player && typeof player.seekTo === 'function') {
|
||||||
|
player.seekTo(intro[1], true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('No intro segment found/provided');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outro) {
|
||||||
|
console.log(`SponsorBlock outro segment: Start - ${outro[0]}s, End - ${outro[1]}s`);
|
||||||
monitorOutro(player, outroSegment);
|
monitorOutro(player, outroSegment);
|
||||||
} else {
|
} else {
|
||||||
console.log('No outro segment found/provided');
|
console.log('No outro segment found/provided');
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Error reading SponsorBlock outro segment:', error);
|
console.error('Error reading SponsorBlock data:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (trailerMaxLength > 0) {
|
if (trailerMaxLength > 0) {
|
||||||
|
Reference in New Issue
Block a user