2021-04-01 20:43:35 +05:30
|
|
|
<template>
|
2021-05-06 23:00:02 +05:30
|
|
|
<div class="uk-container-expand">
|
2021-06-22 15:19:14 +05:30
|
|
|
<div
|
|
|
|
data-shaka-player-container
|
2021-08-04 10:43:22 +05:30
|
|
|
style="width: 100%; height: 100%; background: #000"
|
|
|
|
:style="!isEmbed ? { 'max-height': '75vh', 'min-height': '250px' } : {}"
|
2021-06-22 15:19:14 +05:30
|
|
|
ref="container"
|
|
|
|
>
|
2021-07-05 00:12:10 +05:30
|
|
|
<video
|
|
|
|
data-shaka-player
|
|
|
|
class="uk-width-expand"
|
|
|
|
:autoplay="shouldAutoPlay"
|
|
|
|
:loop="selectedAutoLoop"
|
|
|
|
ref="videoEl"
|
|
|
|
></video>
|
2021-05-06 23:00:02 +05:30
|
|
|
</div>
|
2021-04-01 20:43:35 +05:30
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-07-30 15:04:23 +05:30
|
|
|
<style>
|
|
|
|
.shaka-text-container > div {
|
|
|
|
height: auto !important;
|
|
|
|
width: auto !important;
|
|
|
|
top: auto !important;
|
|
|
|
left: auto !important;
|
|
|
|
}
|
2021-07-31 15:09:21 +05:30
|
|
|
|
|
|
|
.shaka-text-container * {
|
|
|
|
background-color: rgba(8, 8, 8, 0.75) !important;
|
|
|
|
color: white !important;
|
|
|
|
}
|
2021-07-30 15:04:23 +05:30
|
|
|
</style>
|
|
|
|
|
2021-04-01 20:43:35 +05:30
|
|
|
<script>
|
|
|
|
import("shaka-player/dist/controls.css");
|
|
|
|
const shaka = import("shaka-player/dist/shaka-player.ui.js");
|
2021-06-10 02:51:35 +05:30
|
|
|
import muxjs from "mux.js";
|
|
|
|
window.muxjs = muxjs;
|
2021-04-01 20:43:35 +05:30
|
|
|
|
|
|
|
export default {
|
2021-05-06 23:00:02 +05:30
|
|
|
props: {
|
|
|
|
video: Object,
|
|
|
|
sponsors: Object,
|
|
|
|
selectedAutoPlay: Boolean,
|
2021-07-05 00:12:10 +05:30
|
|
|
selectedAutoLoop: Boolean,
|
2021-08-04 10:43:22 +05:30
|
|
|
isEmbed: Boolean,
|
2021-05-06 23:00:02 +05:30
|
|
|
},
|
2021-07-07 19:48:09 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
player: null,
|
|
|
|
};
|
|
|
|
},
|
2021-05-06 23:00:02 +05:30
|
|
|
computed: {
|
2021-07-04 23:56:02 +05:30
|
|
|
shouldAutoPlay: _this => {
|
|
|
|
return _this.getPreferenceBoolean("playerAutoPlay", true);
|
2021-05-06 23:00:02 +05:30
|
|
|
},
|
2021-07-21 16:18:59 +05:30
|
|
|
preferredVideoCodecs: _this => {
|
|
|
|
var preferredVideoCodecs = [];
|
|
|
|
|
|
|
|
if (_this.$refs.videoEl.canPlayType('video/mp4; codecs="av01.0.08M.08"') !== "")
|
|
|
|
preferredVideoCodecs.push("av01");
|
|
|
|
if (_this.$refs.videoEl.canPlayType('video/webm; codecs="vp9"') !== "") preferredVideoCodecs.push("vp9");
|
|
|
|
if (_this.$refs.videoEl.canPlayType('video/mp4; codecs="avc1.4d401f"') !== "")
|
|
|
|
preferredVideoCodecs.push("avc1");
|
|
|
|
|
|
|
|
return preferredVideoCodecs;
|
|
|
|
},
|
2021-05-06 23:00:02 +05:30
|
|
|
},
|
2021-07-10 02:25:09 +05:30
|
|
|
mounted() {
|
|
|
|
if (!this.shaka) this.shakaPromise = shaka.then(shaka => shaka.default).then(shaka => (this.shaka = shaka));
|
|
|
|
},
|
2021-05-06 23:00:02 +05:30
|
|
|
methods: {
|
|
|
|
loadVideo() {
|
2021-06-10 02:51:35 +05:30
|
|
|
const component = this;
|
2021-05-06 23:00:02 +05:30
|
|
|
const videoEl = this.$refs.videoEl;
|
2021-04-01 20:43:35 +05:30
|
|
|
|
2021-05-06 23:00:02 +05:30
|
|
|
videoEl.setAttribute("poster", this.video.thumbnailUrl);
|
2021-04-01 20:43:35 +05:30
|
|
|
|
2021-05-06 23:00:02 +05:30
|
|
|
if (this.$route.query.t) videoEl.currentTime = this.$route.query.t;
|
2021-04-01 20:43:35 +05:30
|
|
|
|
2021-05-06 23:00:02 +05:30
|
|
|
const noPrevPlayer = !this.player;
|
|
|
|
|
|
|
|
var streams = [];
|
|
|
|
|
|
|
|
streams.push(...this.video.audioStreams);
|
|
|
|
streams.push(...this.video.videoStreams);
|
|
|
|
|
2021-07-08 01:04:46 +05:30
|
|
|
const MseSupport = window.MediaSource !== undefined;
|
|
|
|
|
2021-07-28 13:32:23 +05:30
|
|
|
const lbry = this.video.videoStreams.filter(stream => stream.quality === "LBRY")[0];
|
|
|
|
|
2021-06-10 02:51:35 +05:30
|
|
|
var uri;
|
|
|
|
|
|
|
|
if (this.video.livestream) {
|
|
|
|
uri = this.video.hls;
|
2021-07-28 13:32:23 +05:30
|
|
|
} else if (this.video.audioStreams.length > 0 && !lbry && MseSupport) {
|
2021-08-16 01:24:34 +05:30
|
|
|
if (!this.video.dash) {
|
|
|
|
const dash = require("@/utils/DashUtils.js").default.generate_dash_file_from_formats(
|
|
|
|
streams,
|
|
|
|
this.video.duration,
|
|
|
|
);
|
2021-06-10 02:51:35 +05:30
|
|
|
|
2021-08-16 01:24:34 +05:30
|
|
|
uri = "data:application/dash+xml;charset=utf-8;base64," + btoa(dash);
|
|
|
|
} else uri = this.video.dash;
|
2021-07-28 13:32:23 +05:30
|
|
|
} else if (lbry) {
|
|
|
|
uri = lbry.url;
|
2021-06-18 18:50:41 +05:30
|
|
|
} else {
|
2021-07-11 01:29:21 +05:30
|
|
|
uri = this.video.videoStreams.filter(stream => stream.codec == null).slice(-1)[0].url;
|
2021-06-10 02:51:35 +05:30
|
|
|
}
|
2021-05-06 23:00:02 +05:30
|
|
|
|
|
|
|
if (noPrevPlayer)
|
2021-07-10 02:25:09 +05:30
|
|
|
this.shakaPromise.then(() => {
|
|
|
|
this.shaka.polyfill.installAll();
|
|
|
|
|
|
|
|
const localPlayer = new this.shaka.Player(videoEl);
|
|
|
|
|
|
|
|
localPlayer.getNetworkingEngine().registerRequestFilter((_type, request) => {
|
|
|
|
const uri = request.uris[0];
|
|
|
|
var url = new URL(uri);
|
|
|
|
if (url.host.endsWith(".googlevideo.com")) {
|
|
|
|
url.searchParams.set("host", url.host);
|
|
|
|
url.host = new URL(component.video.proxyUrl).host;
|
|
|
|
request.uris[0] = url.toString();
|
|
|
|
}
|
|
|
|
});
|
2021-06-10 02:51:35 +05:30
|
|
|
|
2021-07-10 02:25:09 +05:30
|
|
|
localPlayer.configure(
|
|
|
|
"streaming.bufferingGoal",
|
|
|
|
Math.max(this.getPreferenceNumber("bufferGoal", 10), 10),
|
|
|
|
);
|
2021-06-22 16:24:20 +05:30
|
|
|
|
2021-07-10 02:25:09 +05:30
|
|
|
this.setPlayerAttrs(localPlayer, videoEl, uri, this.shaka);
|
|
|
|
});
|
2021-06-10 02:51:35 +05:30
|
|
|
else this.setPlayerAttrs(this.player, videoEl, uri, this.shaka);
|
2021-05-06 23:00:02 +05:30
|
|
|
|
|
|
|
if (noPrevPlayer) {
|
|
|
|
videoEl.addEventListener("timeupdate", () => {
|
|
|
|
if (this.sponsors && this.sponsors.segments) {
|
|
|
|
const time = videoEl.currentTime;
|
|
|
|
this.sponsors.segments.map(segment => {
|
2021-07-08 03:51:44 +05:30
|
|
|
if (!segment.skipped || this.selectedAutoLoop) {
|
2021-05-06 23:00:02 +05:30
|
|
|
const end = segment.segment[1];
|
|
|
|
if (time >= segment.segment[0] && time < end) {
|
|
|
|
console.log("Skipped segment at " + time);
|
|
|
|
videoEl.currentTime = end;
|
|
|
|
segment.skipped = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
videoEl.addEventListener("volumechange", () => {
|
2021-07-04 23:56:02 +05:30
|
|
|
this.setPreference("volume", videoEl.volume);
|
2021-05-06 23:00:02 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
videoEl.addEventListener("ended", () => {
|
2021-07-05 00:12:10 +05:30
|
|
|
if (!this.selectedAutoLoop && this.selectedAutoPlay && this.video.relatedStreams.length > 0) {
|
2021-06-25 00:09:22 +05:30
|
|
|
const params = this.$route.query;
|
|
|
|
let url = this.video.relatedStreams[0].url;
|
|
|
|
const searchParams = new URLSearchParams();
|
|
|
|
for (var param in params)
|
|
|
|
switch (param) {
|
|
|
|
case "v":
|
|
|
|
case "t":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
searchParams.set(param, params[param]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const paramStr = searchParams.toString();
|
|
|
|
if (paramStr.length > 0) url += "&" + paramStr;
|
|
|
|
this.$router.push(url);
|
|
|
|
}
|
2021-05-06 23:00:02 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Add sponsors on seekbar: https://github.com/ajayyy/SponsorBlock/blob/e39de9fd852adb9196e0358ed827ad38d9933e29/src/js-components/previewBar.ts#L12
|
|
|
|
},
|
2021-06-10 02:51:35 +05:30
|
|
|
setPlayerAttrs(localPlayer, videoEl, uri, shaka) {
|
2021-06-08 00:52:29 +05:30
|
|
|
if (!this.ui) {
|
|
|
|
this.ui = new shaka.ui.Overlay(localPlayer, this.$refs.container, videoEl);
|
|
|
|
|
|
|
|
const config = {
|
2021-07-23 01:44:16 +05:30
|
|
|
overflowMenuButtons: ["quality", "captions", "picture_in_picture", "playback_rate", "airplay"],
|
2021-06-08 00:52:29 +05:30
|
|
|
seekBarColors: {
|
|
|
|
base: "rgba(255, 255, 255, 0.3)",
|
|
|
|
buffered: "rgba(255, 255, 255, 0.54)",
|
|
|
|
played: "rgb(255, 0, 0)",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.ui.configure(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
const player = this.ui.getControls().getPlayer();
|
|
|
|
|
|
|
|
this.player = player;
|
|
|
|
|
2021-07-04 00:54:09 +05:30
|
|
|
const disableVideo = this.getPreferenceBoolean("listen", false) && !this.video.livestream;
|
2021-07-15 14:11:36 +05:30
|
|
|
|
|
|
|
this.player.configure({
|
2021-07-21 16:18:59 +05:30
|
|
|
preferredVideoCodecs: this.preferredVideoCodecs,
|
2021-07-15 14:11:36 +05:30
|
|
|
preferredAudioCodecs: ["opus", "mp4a"],
|
|
|
|
manifest: {
|
|
|
|
disableVideo: disableVideo,
|
|
|
|
},
|
|
|
|
});
|
2021-06-08 02:05:45 +05:30
|
|
|
|
2021-07-04 23:56:02 +05:30
|
|
|
const quality = this.getPreferenceNumber("quality", 0);
|
2021-07-15 14:11:36 +05:30
|
|
|
const qualityConds =
|
|
|
|
quality > 0 && (this.video.audioStreams.length > 0 || this.video.livestream) && !disableVideo;
|
2021-06-22 01:33:11 +05:30
|
|
|
if (qualityConds) this.player.configure("abr.enabled", false);
|
|
|
|
|
2021-08-16 01:24:34 +05:30
|
|
|
player.load(uri, 0, uri.indexOf("dash") >= 0 ? "application/dash+xml" : "video/mp4").then(() => {
|
2021-06-22 01:33:11 +05:30
|
|
|
if (qualityConds) {
|
|
|
|
var leastDiff = Number.MAX_VALUE;
|
|
|
|
var bestStream = null;
|
|
|
|
player
|
|
|
|
.getVariantTracks()
|
|
|
|
.sort((a, b) => a.bandwidth - b.bandwidth)
|
|
|
|
.forEach(stream => {
|
|
|
|
const diff = Math.abs(quality - stream.height);
|
|
|
|
if (diff < leastDiff) {
|
|
|
|
leastDiff = diff;
|
|
|
|
bestStream = stream;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
player.selectVariantTrack(bestStream);
|
|
|
|
}
|
|
|
|
|
2021-05-06 23:00:02 +05:30
|
|
|
this.video.subtitles.map(subtitle => {
|
|
|
|
player.addTextTrackAsync(
|
|
|
|
subtitle.url,
|
|
|
|
subtitle.code,
|
|
|
|
"SUBTITLE",
|
|
|
|
subtitle.mimeType,
|
|
|
|
null,
|
|
|
|
subtitle.name,
|
|
|
|
);
|
|
|
|
});
|
2021-07-04 23:56:02 +05:30
|
|
|
videoEl.volume = this.getPreferenceNumber("volume", 1);
|
2021-05-06 23:00:02 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2021-07-07 19:48:09 +05:30
|
|
|
activated() {
|
2021-06-01 14:49:01 +05:30
|
|
|
import("hotkeys-js")
|
|
|
|
.then(mod => mod.default)
|
|
|
|
.then(hotkeys => {
|
|
|
|
this.hotkeys = hotkeys;
|
|
|
|
var self = this;
|
2021-08-16 18:20:25 +05:30
|
|
|
hotkeys("f,m,j,k,l,space,up,down,left,right", function(e, handler) {
|
2021-06-01 14:49:01 +05:30
|
|
|
const videoEl = self.$refs.videoEl;
|
|
|
|
switch (handler.key) {
|
|
|
|
case "f":
|
|
|
|
if (document.fullscreenElement) document.exitFullscreen();
|
|
|
|
else self.$refs.container.requestFullscreen();
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "m":
|
|
|
|
videoEl.muted = !videoEl.muted;
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
2021-08-16 18:20:25 +05:30
|
|
|
case "j":
|
|
|
|
videoEl.currentTime = Math.max(videoEl.currentTime - 15, 0);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "l":
|
|
|
|
videoEl.currentTime = videoEl.currentTime + 15;
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "k":
|
2021-06-01 14:49:01 +05:30
|
|
|
case "space":
|
|
|
|
if (videoEl.paused) videoEl.play();
|
|
|
|
else videoEl.pause();
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "up":
|
|
|
|
videoEl.volume = Math.min(videoEl.volume + 0.05, 1);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "down":
|
|
|
|
videoEl.volume = Math.max(videoEl.volume - 0.05, 0);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "left":
|
|
|
|
videoEl.currentTime = Math.max(videoEl.currentTime - 5, 0);
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
videoEl.currentTime = videoEl.currentTime + 5;
|
|
|
|
e.preventDefault();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-04-03 21:15:45 +05:30
|
|
|
},
|
2021-07-07 19:48:09 +05:30
|
|
|
deactivated() {
|
|
|
|
if (this.ui) {
|
|
|
|
this.ui.destroy();
|
|
|
|
this.ui = undefined;
|
|
|
|
this.player = undefined;
|
|
|
|
}
|
2021-05-06 23:00:02 +05:30
|
|
|
if (this.player) {
|
|
|
|
this.player.destroy();
|
|
|
|
this.player = undefined;
|
|
|
|
}
|
2021-06-01 14:49:01 +05:30
|
|
|
if (this.hotkeys) this.hotkeys.unbind();
|
2021-07-07 19:48:09 +05:30
|
|
|
this.$refs.container.querySelectorAll("div").forEach(node => node.remove());
|
2021-04-07 17:15:40 +05:30
|
|
|
},
|
2021-04-01 20:43:35 +05:30
|
|
|
};
|
|
|
|
</script>
|