diff --git a/tubearchivist/home/templates/home/video.html b/tubearchivist/home/templates/home/video.html index d1ff3a7..3848f16 100644 --- a/tubearchivist/home/templates/home/video.html +++ b/tubearchivist/home/templates/home/video.html @@ -5,31 +5,11 @@
- {% if video.channel.channel_overwrites.integrate_sponsorblock %} - {% if video.channel.channel_overwrites.integrate_sponsorblock == True %} - {% if not video.sponsorblock %} -

This video doesn't have any sponsor segments added. To add a segment go to this video on YouTube and add a segment using the SponsorBlock extension.

- {% endif %} - {% if video.sponsorblock %} - {% for segment in video.sponsorblock %} - {% if segment.locked != 1 %} -

This video has unlocked sponsor segments. Go to this video on YouTube and vote on the segments using the SponsorBlock extension.

- {{ break }} - {% endif %} - {% endfor %} - {% endif %} - {% endif %} - {% elif config.downloads.integrate_sponsorblock %} - {% if not video.sponsorblock %} + {% if video.sponsorblock.is_enabled %} + {% if video.sponsorblock.segments|length == 0 %}

This video doesn't have any sponsor segments added. To add a segment go to this video on YouTube and add a segment using the SponsorBlock extension.

- {% endif %} - {% if video.sponsorblock %} - {% for segment in video.sponsorblock %} - {% if segment.locked != 1 %} -

This video has unlocked sponsor segments. Go to this video on YouTube and vote on the segments using the SponsorBlock extension.

- {{ break }} - {% endif %} - {% endfor %} + {% elif video.sponsorblock.has_unlocked %} +

This video has unlocked sponsor segments. Go to this video on YouTube and vote on the segments using the SponsorBlock extension.

{% endif %} {% endif %}
diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index ee95b6f..4031ec0 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -333,24 +333,21 @@ function createPlayer(button) { var videoData = getVideoData(videoId); var sponsorBlockElements = ''; - if (videoData.config.downloads.integrate_sponsorblock && (typeof(videoData.data.channel.channel_overwrites) == "undefined" || typeof(videoData.data.channel.channel_overwrites.integrate_sponsorblock) == "undefined" || videoData.data.channel.channel_overwrites.integrate_sponsorblock == true)) { + if (videoData.data.sponsorblock.is_enabled) { sponsorBlock = videoData.data.sponsorblock; - if (!sponsorBlock) { + if (sponsorBlock.segments.length == 0) { sponsorBlockElements = `

This video doesn't have any sponsor segments added. To add a segment go to this video on Youtube and add a segment using the SponsorBlock extension.

`; } else { - for(let i in sponsorBlock) { - if(sponsorBlock[i].locked != 1) { - sponsorBlockElements = ` -
-

This video has unlocked sponsor segments. Go to this video on YouTube and vote on the segments using the SponsorBlock extension.

-
- `; - break; - } + if (sponsorBlock.has_unlocked) { + sponsorBlockElements = ` +
+

This video has unlocked sponsor segments. Go to this video on YouTube and vote on the segments using the SponsorBlock extension.

+
+ `; } } } @@ -425,53 +422,6 @@ function createPlayer(button) { divPlayer.innerHTML = markup; } -// function sendSponsorBlockVote(uuid, vote) { -// var videoId = getVideoPlayerVideoId(); -// postSponsorSegmentVote(videoId, uuid, vote); -// } - -// var sponsorBlockTimestamps = []; -// function sendSponsorBlockSegment() { -// var videoId = getVideoPlayerVideoId(); -// var currentTime = getVideoPlayerCurrentTime(); -// var sponsorBlockElement = document.getElementById("sponsorblock"); -// if (sponsorBlockTimestamps[1]) { -// if (sponsorBlockTimestamps[1] > sponsorBlockTimestamps[0]) { -// postSponsorSegment(videoId, sponsorBlockTimestamps[0], sponsorBlockTimestamps[1]); -// sponsorBlockElement.innerHTML = ` -//

Timestamps sent! (Not really)

-// `; -// setTimeout(function(){ -// sponsorBlockElement.innerHTML = ` -// -// `; -// }, 3000); -// } else { -// sponsorBlockElement.innerHTML = ` -// Invalid Timestamps! -// `; -// setTimeout(function(){ -// sponsorBlockElement.innerHTML = ` -// -// `; -// }, 3000); -// } -// sponsorBlockTimestamps = []; -// } else if (sponsorBlockTimestamps[0]) { -// sponsorBlockTimestamps.push(currentTime); -// sponsorBlockElement.innerHTML = ` -//

${sponsorBlockTimestamps[0].toFixed(1)} s |

-//

${sponsorBlockTimestamps[1].toFixed(1)} s |

-// -// `; -// } else { -// sponsorBlockTimestamps.push(currentTime); -// sponsorBlockElement.innerHTML = ` -// -// `; -// } -// } - // Add video tag to video page when passed a video id, function loaded on page load `video.html (115-117)` function insertVideoTag(videoData, videoProgress) { var videoTag = createVideoTag(videoData, videoProgress); @@ -563,23 +513,14 @@ function onVideoProgress() { var videoElement = getVideoPlayer(); // var sponsorBlockElement = document.getElementById("sponsorblock"); var notificationsElement = document.getElementById("notifications"); - if (sponsorBlock) { - for(let i in sponsorBlock) { - if(sponsorBlock[i].segment[0] <= currentTime + 0.3 && sponsorBlock[i].segment[0] >= currentTime) { - videoElement.currentTime = sponsorBlock[i].segment[1]; - notificationsElement.innerHTML += `

Skipped sponsor segment from ${formatTime(sponsorBlock[i].segment[0])} to ${formatTime(sponsorBlock[i].segment[1])}.

`; + if (sponsorBlock.segments.length > 0) { + for(let i in sponsorBlock.segments) { + if(sponsorBlock.segments[i].segment[0] <= currentTime + 0.3 && sponsorBlock.segments[i].segment[0] >= currentTime) { + videoElement.currentTime = sponsorBlock.segments[i].segment[1]; + notificationsElement.innerHTML += `

Skipped sponsor segment from ${formatTime(sponsorBlock.segments[i].segment[0])} to ${formatTime(sponsorBlock.segments[i].segment[1])}.

`; } - // if(currentTime >= sponsorBlock[i].segment[1] && currentTime <= sponsorBlock[i].segment[1] + 0.2) { - // if(sponsorBlock[i].locked != 1) { - // sponsorBlockElement.innerHTML += ` - //
- // - // - //
`; - // } - // } - if(currentTime > sponsorBlock[i].segment[1] + 10) { - var notificationsElementUUID = document.getElementById("notification-" + sponsorBlock[i].UUID); + if(currentTime > sponsorBlock.segments[i].segment[1] + 10) { + var notificationsElementUUID = document.getElementById("notification-" + sponsorBlock.segments[i].UUID); if(notificationsElementUUID) { notificationsElementUUID.outerHTML = ''; } @@ -602,6 +543,12 @@ function onVideoEnded() { if (!getVideoPlayerWatchStatus()) { // Check if video is already marked as watched updateVideoWatchStatus(videoId, "unwatched"); } + for(let i in sponsorBlock.segments) { + var notificationsElementUUID = document.getElementById("notification-" + sponsorBlock.segments[i].UUID); + if(notificationsElementUUID) { + notificationsElementUUID.outerHTML = ''; + } + } } function watchedThreshold(currentTime, duration) {