2020-11-11 09:20:57 +00:00
|
|
|
<template>
|
2020-11-12 20:42:02 +00:00
|
|
|
<div class="uk-container uk-container-xlarge">
|
|
|
|
<h1 class="uk-text-bold">{{ video.title }}</h1>
|
|
|
|
<video controls ref="player" class="video-js preview-player-dimensions "></video>
|
2020-11-11 09:20:57 +00:00
|
|
|
|
|
|
|
<img :src="video.uploaderAvatar" />
|
|
|
|
<router-link class="uk-text-bold" v-bind:to="video.uploaderUrl || '/'">
|
2020-11-12 20:42:02 +00:00
|
|
|
<a>{{ video.uploader }}</a>
|
2020-11-11 09:20:57 +00:00
|
|
|
</router-link>
|
|
|
|
|
2020-11-12 20:42:02 +00:00
|
|
|
<p class="uk-dark">
|
|
|
|
<font-awesome-icon icon="thumbs-down"></font-awesome-icon>
|
|
|
|
{{ video.likes }}
|
|
|
|
<font-awesome-icon icon="thumbs-up"></font-awesome-icon>
|
|
|
|
{{ video.dislikes }}
|
|
|
|
</p>
|
2020-11-11 09:20:57 +00:00
|
|
|
<p>
|
2020-11-12 20:42:02 +00:00
|
|
|
<font-awesome-icon icon="eye"></font-awesome-icon> {{ video.views }} views
|
2020-11-11 09:20:57 +00:00
|
|
|
</p>
|
2020-11-12 20:42:02 +00:00
|
|
|
<p class="uk-light" v-html="video.description"></p>
|
|
|
|
<a v-if="sponsors && sponsors.segments">Sponsors Segments: {{ sponsors.segments.length }}</a>
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
<div class="uk-tile-default uk-text-secondary" style="background: #0b0e0f; width: 300px" v-bind:key="related.url" v-for="related in video.relatedStreams">
|
|
|
|
<router-link class="uk-link-muted" v-bind:to="related.url">
|
|
|
|
<p class="uk-text-emphasis">{{ related.title }}</p>
|
|
|
|
<img style="width: 100%" v-bind:src="related.thumbnail" />
|
|
|
|
</router-link>
|
|
|
|
<p>
|
|
|
|
<router-link class="uk-link-muted" v-bind:to="related.uploaderUrl || '/'">
|
|
|
|
<p>{{ related.uploaderName }}</p>
|
|
|
|
</router-link>
|
|
|
|
<font-awesome-icon icon="eye"></font-awesome-icon>
|
|
|
|
{{ related.views }} views
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
2020-11-11 09:20:57 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import "video.js/dist/video-js.css";
|
|
|
|
import "@silvermine/videojs-quality-selector/dist/css/quality-selector.css";
|
|
|
|
import videojs from "video.js";
|
2020-11-13 12:05:02 +00:00
|
|
|
require("videojs-hotkeys");
|
2020-11-11 09:20:57 +00:00
|
|
|
import Constants from "@/Constants.js";
|
|
|
|
require("@silvermine/videojs-quality-selector")(videojs);
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "App",
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
video: {
|
|
|
|
title: "Loading...",
|
|
|
|
},
|
|
|
|
player: null,
|
2020-11-15 20:02:11 +00:00
|
|
|
audioplayer: null,
|
2020-11-11 09:20:57 +00:00
|
|
|
sponsors: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getVideoData();
|
|
|
|
this.getSponsors();
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
if (this.player) {
|
|
|
|
this.player.dispose();
|
|
|
|
}
|
2020-11-15 20:02:11 +00:00
|
|
|
if (this.audioplayer) {
|
|
|
|
this.audioplayer.pause()
|
|
|
|
}
|
2020-11-11 09:20:57 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
"$route.query.v": function (v) {
|
|
|
|
if (v) {
|
2020-11-15 20:02:11 +00:00
|
|
|
if (this.audioplayer)
|
|
|
|
this.audioplayer.pause()
|
2020-11-11 09:20:57 +00:00
|
|
|
this.getVideoData();
|
|
|
|
this.getSponsors();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async fetchVideo() {
|
|
|
|
return await (
|
|
|
|
await fetch(Constants.BASE_URL + "/streams/" + this.$route.query.v)
|
|
|
|
).json();
|
|
|
|
},
|
|
|
|
async fetchSponsors() {
|
|
|
|
return await (
|
|
|
|
await fetch(Constants.BASE_URL + "/sponsors/" + this.$route.query.v + "?category=[\"sponsor\",\"interaction\",\"selfpromo\",\"music_offtopic\"]")
|
|
|
|
).json();
|
|
|
|
},
|
|
|
|
async getVideoData() {
|
|
|
|
this.fetchVideo()
|
|
|
|
.then((data) => (this.video = data))
|
|
|
|
.then(() => {
|
|
|
|
document.title = this.video.title + " - Piped";
|
|
|
|
|
|
|
|
this.video.description = this.video.description.replaceAll("http://www.youtube.com", "").replaceAll("https://www.youtube.com", "")
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
autoplay: false,
|
|
|
|
controlBar: {
|
|
|
|
children: [
|
|
|
|
"playToggle",
|
|
|
|
"currentTimeDisplay",
|
|
|
|
"progressControl",
|
|
|
|
"volumePanel",
|
|
|
|
"qualitySelector",
|
2020-11-12 20:42:02 +00:00
|
|
|
"captionsButton",
|
2020-11-11 09:20:57 +00:00
|
|
|
"fullscreenToggle",
|
|
|
|
],
|
|
|
|
},
|
2020-11-12 20:42:02 +00:00
|
|
|
responsive: false,
|
|
|
|
aspectRatio: '16:9'
|
2020-11-11 09:20:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const noPrevPlayer = !this.player
|
|
|
|
|
|
|
|
if (noPrevPlayer) this.player = videojs(this.$refs.player, options);
|
|
|
|
|
|
|
|
this.player.hotkeys({
|
|
|
|
volumeStep: 0.1,
|
|
|
|
seekStep: 5,
|
|
|
|
enableModifiersForNumbers: false,
|
|
|
|
enableHoverScroll: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.player.poster(this.video.thumbnailUrl);
|
|
|
|
|
|
|
|
var src = [];
|
|
|
|
|
2020-11-15 20:02:11 +00:00
|
|
|
if (this.video.livestream) {
|
|
|
|
|
2020-11-11 09:20:57 +00:00
|
|
|
src.push({
|
2020-11-15 20:02:11 +00:00
|
|
|
src: this.video.hls,
|
|
|
|
type: 'application/x-mpegURL'
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.video.videoStreams.map((stream) =>
|
|
|
|
src.push({
|
|
|
|
src: stream.url,
|
2020-11-11 09:20:57 +00:00
|
|
|
type: stream.mimeType,
|
|
|
|
label: stream.quality,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2020-11-12 20:42:02 +00:00
|
|
|
this.video.audioStreams.map((stream) =>
|
|
|
|
src.push({
|
|
|
|
src: stream.url,
|
|
|
|
type: stream.mimeType,
|
2020-11-15 20:02:11 +00:00
|
|
|
label: stream.quality,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.audioplayer = new Audio((this.video.audioStreams.slice(-1)[0].url));
|
2020-11-12 20:42:02 +00:00
|
|
|
|
2020-11-11 09:20:57 +00:00
|
|
|
this.player.src(src);
|
|
|
|
|
2020-11-15 20:02:11 +00:00
|
|
|
if (noPrevPlayer) {
|
2020-11-11 09:20:57 +00:00
|
|
|
this.player.on('timeupdate', () => {
|
|
|
|
if (this.sponsors && this.sponsors.segments) {
|
|
|
|
const time = this.player.currentTime()
|
|
|
|
this.sponsors.segments.map(segment => {
|
|
|
|
if (!segment.skipped) {
|
|
|
|
const end = segment.segment[1]
|
|
|
|
if (time >= segment.segment[0] && time < end) {
|
|
|
|
this.player.currentTime(end)
|
2020-11-15 20:02:11 +00:00
|
|
|
this.audioplayer.currentTime = end
|
2020-11-11 09:20:57 +00:00
|
|
|
segment.skipped = true
|
2020-11-15 20:02:11 +00:00
|
|
|
return
|
2020-11-11 09:20:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-11-15 20:02:11 +00:00
|
|
|
|
|
|
|
if (this.audioplayer) {
|
|
|
|
if (Math.abs(this.audioplayer.currentTime - this.player.currentTime()) > 0.25) {
|
|
|
|
this.audioplayer.currentTime = this.player.currentTime()
|
|
|
|
}
|
|
|
|
}
|
2020-11-11 09:20:57 +00:00
|
|
|
});
|
|
|
|
|
2020-11-15 20:02:11 +00:00
|
|
|
this.player.on('play', () => {
|
|
|
|
this.audioplayer.play()
|
|
|
|
});
|
|
|
|
|
|
|
|
this.player.on('pause', () => {
|
|
|
|
this.audioplayer.currentTime = this.player.currentTime()
|
|
|
|
this.audioplayer.pause()
|
|
|
|
});
|
|
|
|
|
|
|
|
this.player.on('volumechange', () => {
|
|
|
|
this.audioplayer.volume = this.player.volume()
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-12 20:42:02 +00:00
|
|
|
if (!noPrevPlayer)
|
|
|
|
this.player.remoteTextTracks().map(track => this.player.removeRemoteTextTrack(track));
|
2020-11-11 09:20:57 +00:00
|
|
|
|
|
|
|
this.video.subtitles.map(subtitle => {
|
|
|
|
this.player.addRemoteTextTrack({
|
|
|
|
kind: "captions",
|
2020-11-12 20:42:02 +00:00
|
|
|
src: subtitle.url.replace("fmt=ttml", "fmt=vtt"),
|
2020-11-11 09:20:57 +00:00
|
|
|
label: "Track",
|
2020-11-12 20:42:02 +00:00
|
|
|
type: "captions/captions.vtt"
|
|
|
|
}, false).mode = "showing"
|
2020-11-11 09:20:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
//TODO: Add sponsors on seekbar: https://github.com/ajayyy/SponsorBlock/blob/e39de9fd852adb9196e0358ed827ad38d9933e29/src/js-components/previewBar.ts#L12
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async getSponsors() {
|
|
|
|
this.fetchSponsors().then((data) => (this.sponsors = data));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.vjs-current-time {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|