0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-09 04:55:07 +00:00
VueTube/NUXT/components/Player/sponsorblock.vue

115 lines
2.3 KiB
Vue
Raw Normal View History

2022-06-01 03:40:36 +00:00
<template>
<div>
2022-06-01 18:35:14 +00:00
<v-progress-linear
v-for="block in blocks"
:key="block.UUID"
:buffer-value="(block.segment[1] / video.duration) * 100"
:value="(block.segment[0] / video.duration) * 100"
style="
z-index: 4;
width: 100%;
background: transparent;
pointer-events: none;
"
2022-06-01 19:02:02 +00:00
:class="!fullscreen || controls ? '' : 'invisible'"
2022-06-01 18:35:14 +00:00
background-color="white"
background-opacity="1"
color="transparent"
height="2"
:style="
fullscreen
? 'width: calc(100% - 2rem); left: 1rem; position: absolute; bottom: 3rem;'
: 'width: 100%; left: 0; position: absolute; bottom: 0;'
"
2022-06-01 18:35:14 +00:00
/>
</div>
2022-06-01 03:40:36 +00:00
</template>
<script>
export default {
props: {
video: {
type: Object,
required: true,
},
2022-06-01 04:00:54 +00:00
videoid: {
type: String,
required: true,
},
2022-06-01 18:35:14 +00:00
fullscreen: {
type: Boolean,
required: true,
},
2022-06-01 19:05:19 +00:00
controls: {
type: Boolean,
required: true,
},
2022-06-01 03:40:36 +00:00
},
data: () => ({
2022-06-01 18:35:14 +00:00
blocks: [],
}),
2022-06-01 03:40:36 +00:00
mounted() {
2022-06-01 06:13:16 +00:00
let vid = this.video;
let id = this.videoid;
2022-06-01 03:40:36 +00:00
2022-06-01 06:13:16 +00:00
vid.addEventListener("loadeddata", (e) => {
if (vid.readyState >= 3) {
this.$youtube.getSponsorBlock(id, (data) => {
console.log("sbreturn", data);
if (Array.isArray(data)) {
2022-06-01 18:35:14 +00:00
this.blocks = data;
2022-06-01 03:40:36 +00:00
// iterate over data.segments array
vid.addEventListener("timeupdate", () => {
2022-06-01 18:35:14 +00:00
// console.log("sb check", data);
data.forEach((sponsor) => {
2022-06-01 06:13:16 +00:00
let vidTime = vid.currentTime;
2022-06-01 03:40:36 +00:00
if (
vidTime >= sponsor.segment[0] &&
2022-06-01 18:47:00 +00:00
vidTime <= sponsor.segment[1]
) {
2022-06-01 06:13:16 +00:00
console.log("Skipping the sponsor");
2022-06-01 21:12:00 +00:00
this.$youtube.showToast("Skipped sponsor")
2022-06-01 18:35:14 +00:00
vid.currentTime = sponsor.segment[1] + 1;
2022-06-01 06:13:16 +00:00
}
});
});
}
});
2022-06-01 03:40:36 +00:00
}
});
2022-06-01 03:40:36 +00:00
},
};
</script>
<style>
.sponsor {
color: green;
}
2022-06-01 18:35:14 +00:00
.selfpromo {
color: yellow;
}
.exclusive_access {
color: orange;
}
.interaction {
color: blue;
}
.intro {
color: purple;
}
.outro {
color: purple;
}
.music_offtopic {
color: red;
}
.poi_highlight {
color: #ff00ff;
}
.filler {
color: blue;
}
</style>