From 5e791a51f5b977c75b20b4aa436307a39cb643b6 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 7 Jun 2021 23:08:19 +0530 Subject: [PATCH] Add support for /watch/, /embed/, /w/, /v/, /shorts/ --- src/components/WatchVideo.vue | 11 +++++++---- src/router/router.js | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index f6900995..59078490 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -141,13 +141,13 @@ export default { }, methods: { fetchVideo() { - return this.fetchJson(Constants.BASE_URL + "/streams/" + this.$route.query.v); + return this.fetchJson(Constants.BASE_URL + "/streams/" + this.getVideoId()); }, async fetchSponsors() { return await this.fetchJson( Constants.BASE_URL + "/sponsors/" + - this.$route.query.v + + this.getVideoId() + "?category=" + (localStorage && localStorage.getItem("selectedSkip") !== null ? encodeURIComponent('["' + localStorage.getItem("selectedSkip").replace(",", '","') + '"]') @@ -155,7 +155,7 @@ export default { ); }, fetchComments() { - return this.fetchJson(Constants.BASE_URL + "/comments/" + this.$route.query.v); + return this.fetchJson(Constants.BASE_URL + "/comments/" + this.getVideoId()); }, onChange() { if (localStorage) localStorage.setItem("autoplay", this.selectedAutoPlay); @@ -194,7 +194,7 @@ export default { this.fetchJson( Constants.BASE_URL + "/nextpage/comments/" + - this.$route.query.v + + this.getVideoId() + "?url=" + encodeURIComponent(this.comments.nextpage), ).then(json => { @@ -204,6 +204,9 @@ export default { }); } }, + getVideoId() { + return this.$route.query.v || this.$route.params.v; + }, }, components: { Player, diff --git a/src/router/router.js b/src/router/router.js index 1b84869f..598313a8 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -3,7 +3,26 @@ import { createRouter, createWebHistory } from "vue-router"; const routes = [ { path: "/watch", - name: "Watch", + component: () => import("../components/WatchVideo.vue"), + }, + { + path: "/watch/:v", + component: () => import("../components/WatchVideo.vue"), + }, + { + path: "/embed/:v", + component: () => import("../components/WatchVideo.vue"), + }, + { + path: "/w/:v", + component: () => import("../components/WatchVideo.vue"), + }, + { + path: "/v/:v", + component: () => import("../components/WatchVideo.vue"), + }, + { + path: "/shorts/:v", component: () => import("../components/WatchVideo.vue"), }, {