2020-11-11 14:50:57 +05:30
|
|
|
<template>
|
2021-12-27 20:16:32 +05:30
|
|
|
<div v-if="video && isEmbed" class="absolute top-0 left-0 h-full w-full z-50">
|
2021-08-04 10:43:22 +05:30
|
|
|
<Player
|
|
|
|
ref="videoPlayer"
|
|
|
|
:video="video"
|
|
|
|
:sponsors="sponsors"
|
2021-10-09 00:22:51 +05:30
|
|
|
:selected-auto-play="false"
|
|
|
|
:selected-auto-loop="selectedAutoLoop"
|
|
|
|
:is-embed="isEmbed"
|
2021-08-04 10:43:22 +05:30
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-12-27 20:16:26 +05:30
|
|
|
<div v-if="video && !isEmbed" class="w-full">
|
2021-06-07 00:42:03 +05:30
|
|
|
<ErrorHandler v-if="video && video.error" :message="video.message" :error="video.error" />
|
2020-11-17 10:45:35 +05:30
|
|
|
|
2021-06-07 00:17:43 +05:30
|
|
|
<div v-show="!video.error">
|
2021-07-05 00:12:10 +05:30
|
|
|
<Player
|
|
|
|
ref="videoPlayer"
|
|
|
|
:video="video"
|
|
|
|
:sponsors="sponsors"
|
2021-10-09 00:22:51 +05:30
|
|
|
:selected-auto-play="selectedAutoPlay"
|
|
|
|
:selected-auto-loop="selectedAutoLoop"
|
2021-07-05 00:12:10 +05:30
|
|
|
/>
|
2021-12-27 20:16:32 +05:30
|
|
|
<div class="font-bold mt-2 text-2xl break-words">
|
2021-07-30 00:56:56 +05:30
|
|
|
{{ video.title }}
|
|
|
|
</div>
|
2021-06-07 00:17:43 +05:30
|
|
|
|
2021-12-27 20:16:32 +05:30
|
|
|
<div class="flex mb-1.5">
|
|
|
|
<span>{{ addCommas(video.views) }} views</span>
|
|
|
|
<span class="ml-2">{{ uploadDate }}</span>
|
|
|
|
|
|
|
|
<div class="flex items-center relative ml-auto children:ml-2">
|
|
|
|
<template v-if="video.likes >= 0">
|
|
|
|
<div>
|
|
|
|
<font-awesome-icon icon="thumbs-up"></font-awesome-icon>
|
2021-12-27 20:16:33 +05:30
|
|
|
<b class="ml-2">{{ addCommas(video.likes) }}</b>
|
2021-12-27 20:16:32 +05:30
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<font-awesome-icon icon="thumbs-down"></font-awesome-icon>
|
2021-12-27 20:16:33 +05:30
|
|
|
<b class="ml-2">{{ video.dislikes >= 0 ? addCommas(video.dislikes) : "?" }}</b>
|
2021-12-27 20:16:32 +05:30
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template v-if="video.likes < 0">
|
|
|
|
<div>
|
|
|
|
<b v-t="'video.ratings_disabled'" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<a :href="'https://youtu.be/' + getVideoId()" class="uk-margin-small-left btn">
|
|
|
|
<b>{{ $t("player.watch_on") }} </b>
|
|
|
|
<font-awesome-icon :icon="['fab', 'youtube']"></font-awesome-icon>
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
v-if="video.lbryId"
|
|
|
|
:href="'https://odysee.com/' + video.lbryId"
|
|
|
|
class="uk-margin-small-left btn"
|
|
|
|
>
|
|
|
|
<b>{{ $t("player.watch_on") }} LBRY</b>
|
|
|
|
</a>
|
|
|
|
<router-link
|
|
|
|
:to="toggleListenUrl"
|
|
|
|
:aria-label="(isListening ? 'Watch ' : 'Listen to ') + video.title"
|
|
|
|
:title="(isListening ? 'Watch ' : 'Listen to ') + video.title"
|
|
|
|
class="uk-margin-small-left btn"
|
|
|
|
>
|
|
|
|
<font-awesome-icon :icon="isListening ? 'tv' : 'headphones'"></font-awesome-icon>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
2021-07-18 23:17:39 +05:30
|
|
|
</div>
|
|
|
|
|
2021-12-27 20:16:32 +05:30
|
|
|
<div class="flex">
|
|
|
|
<div class="flex items-center">
|
|
|
|
<img :src="video.uploaderAvatar" alt="" loading="lazy" class="rounded-full" />
|
|
|
|
<router-link v-if="video.uploaderUrl" class="link" :to="video.uploaderUrl">
|
|
|
|
{{ video.uploader }} </router-link
|
|
|
|
><font-awesome-icon class="ml-1" v-if="video.uploaderVerified" icon="check"></font-awesome-icon>
|
|
|
|
</div>
|
|
|
|
<button v-if="authenticated" class="btn relative ml-auto" @click="subscribeHandler">
|
2021-08-25 22:00:21 +05:30
|
|
|
{{ subscribed ? $t("actions.unsubscribe") : $t("actions.subscribe") }}
|
2021-07-18 23:17:39 +05:30
|
|
|
</button>
|
2021-07-01 01:56:04 +05:30
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 20:16:30 +05:30
|
|
|
<button class="btn" @click="showDesc = !showDesc">
|
2021-09-05 18:38:26 +05:30
|
|
|
{{ showDesc ? $t("actions.minimize_description") : $t("actions.show_description") }}
|
2021-12-27 20:16:30 +05:30
|
|
|
</button>
|
2021-10-09 00:22:51 +05:30
|
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
2021-12-27 20:16:32 +05:30
|
|
|
<p
|
|
|
|
v-show="showDesc"
|
|
|
|
class="break-words"
|
|
|
|
:style="[{ colour: foregroundColor }]"
|
|
|
|
v-html="purifyHTML(video.description)"
|
|
|
|
></p>
|
2021-07-18 23:17:39 +05:30
|
|
|
<div v-if="showDesc && sponsors && sponsors.segments">
|
2021-09-05 18:38:26 +05:30
|
|
|
{{ $t("video.sponsor_segments") }}: {{ sponsors.segments.length }}
|
2021-07-18 23:17:39 +05:30
|
|
|
</div>
|
2021-06-07 00:17:43 +05:30
|
|
|
</div>
|
2020-11-17 10:45:35 +05:30
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-09-22 03:18:55 +05:30
|
|
|
<label for="chkAutoLoop"
|
|
|
|
><b>{{ $t("actions.loop_this_video") }}:</b></label
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
id="chkAutoLoop"
|
|
|
|
v-model="selectedAutoLoop"
|
2021-10-09 00:22:51 +05:30
|
|
|
class="uk-checkbox"
|
2021-09-22 03:18:55 +05:30
|
|
|
type="checkbox"
|
2021-10-09 00:22:51 +05:30
|
|
|
@change="onChange($event)"
|
2021-09-22 03:18:55 +05:30
|
|
|
/>
|
2021-07-05 00:12:10 +05:30
|
|
|
<br />
|
2021-09-22 03:18:55 +05:30
|
|
|
<label for="chkAutoPlay"
|
|
|
|
><b>{{ $t("actions.auto_play_next_video") }}:</b></label
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
id="chkAutoPlay"
|
|
|
|
v-model="selectedAutoPlay"
|
2021-10-09 00:22:51 +05:30
|
|
|
class="uk-checkbox"
|
2021-09-22 03:18:55 +05:30
|
|
|
type="checkbox"
|
2021-10-09 00:22:51 +05:30
|
|
|
@change="onChange($event)"
|
2021-09-22 03:18:55 +05:30
|
|
|
/>
|
2020-12-10 13:23:30 +05:30
|
|
|
|
2021-05-26 01:16:21 +05:30
|
|
|
<hr />
|
|
|
|
|
2021-12-27 20:16:26 +05:30
|
|
|
<div class="grid xl:grid-cols-5 sm:grid-cols-4 grid-cols-1">
|
|
|
|
<div v-if="comments" ref="comments" class="xl:col-span-4 sm:col-span-3">
|
2021-12-27 20:16:32 +05:30
|
|
|
<Comment
|
2021-10-09 00:22:51 +05:30
|
|
|
v-for="comment in comments.comments"
|
|
|
|
:key="comment.commentId"
|
2021-12-27 20:16:32 +05:30
|
|
|
:comment="comment"
|
|
|
|
:uploader="video.uploader"
|
|
|
|
:video-id="getVideoId()"
|
|
|
|
/>
|
2021-05-26 01:16:21 +05:30
|
|
|
</div>
|
|
|
|
|
2021-12-27 20:16:32 +05:30
|
|
|
<div v-if="video" class="order-first sm:order-last">
|
|
|
|
<a class="btn mb-2 sm:hidden" @click="showRecs = !showRecs">
|
2021-10-04 05:38:25 +05:30
|
|
|
{{ showRecs ? $t("actions.minimize_recommendations") : $t("actions.show_recommendations") }}
|
|
|
|
</a>
|
2021-05-26 01:16:21 +05:30
|
|
|
<div
|
2021-10-09 00:22:51 +05:30
|
|
|
v-for="related in video.relatedStreams"
|
2021-10-04 05:38:25 +05:30
|
|
|
v-show="showRecs || !smallView"
|
2021-10-09 00:22:51 +05:30
|
|
|
:key="related.url"
|
2021-12-27 20:16:29 +05:30
|
|
|
class="uk-tile-default w-auto"
|
2021-06-29 01:15:03 +05:30
|
|
|
:style="[{ background: backgroundColor }]"
|
2021-05-26 01:16:21 +05:30
|
|
|
>
|
2021-06-25 00:08:04 +05:30
|
|
|
<VideoItem :video="related" height="94" width="168" />
|
2021-05-26 01:16:21 +05:30
|
|
|
</div>
|
2021-12-27 20:16:26 +05:30
|
|
|
<hr class="sm:hidden" />
|
2021-05-26 01:16:21 +05:30
|
|
|
</div>
|
2020-11-17 10:45:35 +05:30
|
|
|
</div>
|
2020-11-13 02:12:02 +05:30
|
|
|
</div>
|
2020-11-11 14:50:57 +05:30
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-04-01 20:43:35 +05:30
|
|
|
import Player from "@/components/Player.vue";
|
2021-06-25 00:08:04 +05:30
|
|
|
import VideoItem from "@/components/VideoItem.vue";
|
2021-06-07 00:17:43 +05:30
|
|
|
import ErrorHandler from "@/components/ErrorHandler.vue";
|
2021-07-21 15:49:51 +05:30
|
|
|
import Comment from "@/components/Comment.vue";
|
2020-11-11 14:50:57 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "App",
|
2021-10-09 00:22:51 +05:30
|
|
|
components: {
|
|
|
|
Player,
|
|
|
|
VideoItem,
|
|
|
|
ErrorHandler,
|
|
|
|
Comment,
|
|
|
|
},
|
2020-11-11 14:50:57 +05:30
|
|
|
data() {
|
2021-10-04 05:38:25 +05:30
|
|
|
const smallViewQuery = window.matchMedia("(max-width: 640px)");
|
2020-11-11 14:50:57 +05:30
|
|
|
return {
|
|
|
|
video: {
|
2021-04-07 17:15:40 +05:30
|
|
|
title: "Loading...",
|
2020-11-11 14:50:57 +05:30
|
|
|
},
|
2020-12-14 19:11:49 +05:30
|
|
|
sponsors: null,
|
2021-07-05 00:12:10 +05:30
|
|
|
selectedAutoLoop: false,
|
2021-01-15 15:19:46 +05:30
|
|
|
selectedAutoPlay: null,
|
2021-04-07 17:15:40 +05:30
|
|
|
showDesc: true,
|
2021-10-04 05:38:25 +05:30
|
|
|
showRecs: true,
|
2021-05-26 01:16:21 +05:30
|
|
|
comments: null,
|
2021-07-18 23:17:39 +05:30
|
|
|
subscribed: false,
|
|
|
|
channelId: null,
|
2021-07-21 03:18:35 +05:30
|
|
|
active: true,
|
2021-10-04 05:38:25 +05:30
|
|
|
smallViewQuery: smallViewQuery,
|
|
|
|
smallView: smallViewQuery.matches,
|
2020-11-11 14:50:57 +05:30
|
|
|
};
|
|
|
|
},
|
2021-10-09 00:22:51 +05:30
|
|
|
computed: {
|
|
|
|
isListening(_this) {
|
|
|
|
return _this.getPreferenceBoolean("listen", false);
|
|
|
|
},
|
|
|
|
toggleListenUrl(_this) {
|
|
|
|
const url = new URL(window.location.href);
|
|
|
|
url.searchParams.set("listen", _this.isListening ? "0" : "1");
|
|
|
|
return url.href;
|
|
|
|
},
|
|
|
|
isEmbed(_this) {
|
|
|
|
return String(_this.$route.path).indexOf("/embed/") == 0;
|
|
|
|
},
|
|
|
|
uploadDate(_this) {
|
|
|
|
return new Date(_this.video.uploadDate).toLocaleString(undefined, {
|
|
|
|
month: "short",
|
|
|
|
day: "numeric",
|
|
|
|
year: "numeric",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2020-11-11 14:50:57 +05:30
|
|
|
mounted() {
|
2021-07-07 19:48:09 +05:30
|
|
|
this.getVideoData().then(() => {
|
2021-08-22 15:57:09 +05:30
|
|
|
(async () => {
|
2021-10-27 05:19:56 +05:30
|
|
|
const videoId = this.getVideoId();
|
|
|
|
const instance = this;
|
2021-11-01 00:06:47 +05:30
|
|
|
if (window.db && !this.video.error) {
|
2021-08-22 15:57:09 +05:30
|
|
|
var tx = window.db.transaction("watch_history", "readwrite");
|
|
|
|
var store = tx.objectStore("watch_history");
|
2021-10-27 05:19:56 +05:30
|
|
|
var request = store.get(videoId);
|
|
|
|
request.onsuccess = function(event) {
|
|
|
|
var video = event.target.result;
|
|
|
|
if (video) {
|
|
|
|
video.watchedAt = Date.now();
|
|
|
|
} else {
|
|
|
|
video = {
|
|
|
|
videoId: videoId,
|
|
|
|
title: instance.video.title,
|
|
|
|
duration: instance.video.duration,
|
|
|
|
thumbnail: instance.video.thumbnailUrl,
|
|
|
|
uploaderUrl: instance.video.uploaderUrl,
|
|
|
|
uploaderName: instance.video.uploader,
|
|
|
|
watchedAt: Date.now(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
store.put(video);
|
2021-08-22 15:57:09 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|
2021-07-21 03:18:35 +05:30
|
|
|
if (this.active) this.$refs.videoPlayer.loadVideo();
|
2021-07-07 19:48:09 +05:30
|
|
|
});
|
2020-11-11 14:50:57 +05:30
|
|
|
this.getSponsors();
|
2021-08-04 10:43:22 +05:30
|
|
|
if (!this.isEmbed && this.getPreferenceBoolean("comments", true)) this.getComments();
|
2021-10-04 05:38:25 +05:30
|
|
|
window.addEventListener("resize", () => {
|
|
|
|
this.smallView = this.smallViewQuery.matches;
|
|
|
|
});
|
2021-07-07 19:48:09 +05:30
|
|
|
},
|
|
|
|
activated() {
|
2021-07-21 03:18:35 +05:30
|
|
|
this.active = true;
|
2021-09-22 03:18:55 +05:30
|
|
|
this.selectedAutoPlay = this.getPreferenceBoolean("autoplay", false);
|
2021-07-30 14:33:16 +05:30
|
|
|
this.showDesc = !this.getPreferenceBoolean("minimizeDescription", false);
|
2021-07-21 16:29:53 +05:30
|
|
|
if (this.video.duration) {
|
|
|
|
document.title = this.video.title + " - Piped";
|
|
|
|
this.$refs.videoPlayer.loadVideo();
|
|
|
|
}
|
2021-05-26 13:40:22 +05:30
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2021-07-07 19:48:09 +05:30
|
|
|
deactivated() {
|
2021-07-21 03:18:35 +05:30
|
|
|
this.active = false;
|
2021-05-26 13:40:22 +05:30
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
2020-11-11 14:50:57 +05:30
|
|
|
},
|
2021-09-06 02:31:26 +05:30
|
|
|
unmounted() {
|
2021-09-06 02:23:59 +05:30
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2020-11-11 14:50:57 +05:30
|
|
|
methods: {
|
2021-02-24 15:05:41 +05:30
|
|
|
fetchVideo() {
|
2021-07-04 23:56:02 +05:30
|
|
|
return this.fetchJson(this.apiUrl() + "/streams/" + this.getVideoId());
|
2020-11-11 14:50:57 +05:30
|
|
|
},
|
|
|
|
async fetchSponsors() {
|
2021-07-04 23:56:02 +05:30
|
|
|
return await this.fetchJson(this.apiUrl() + "/sponsors/" + this.getVideoId(), {
|
2021-06-15 17:07:35 +05:30
|
|
|
category:
|
2021-07-04 00:54:09 +05:30
|
|
|
'["' +
|
|
|
|
this.getPreferenceString("selectedSkip", "sponsor,interaction,selfpromo,music_offtopic").replaceAll(
|
|
|
|
",",
|
|
|
|
'","',
|
|
|
|
) +
|
|
|
|
'"]',
|
2021-06-15 17:07:35 +05:30
|
|
|
});
|
2020-11-11 14:50:57 +05:30
|
|
|
},
|
2021-05-26 01:16:21 +05:30
|
|
|
fetchComments() {
|
2021-07-04 23:56:02 +05:30
|
|
|
return this.fetchJson(this.apiUrl() + "/comments/" + this.getVideoId());
|
2021-05-26 01:16:21 +05:30
|
|
|
},
|
2020-12-10 13:23:30 +05:30
|
|
|
onChange() {
|
2021-07-04 00:54:09 +05:30
|
|
|
this.setPreference("autoplay", this.selectedAutoPlay);
|
2020-12-10 13:23:30 +05:30
|
|
|
},
|
2020-11-11 14:50:57 +05:30
|
|
|
async getVideoData() {
|
2021-07-07 19:48:09 +05:30
|
|
|
await this.fetchVideo()
|
2021-02-24 15:05:41 +05:30
|
|
|
.then(data => {
|
|
|
|
this.video = data;
|
2021-11-11 13:46:00 +05:30
|
|
|
this.video.id = this.getVideoId();
|
2021-02-24 15:05:41 +05:30
|
|
|
})
|
2020-11-11 14:50:57 +05:30
|
|
|
.then(() => {
|
2021-06-07 00:17:43 +05:30
|
|
|
if (!this.video.error) {
|
|
|
|
document.title = this.video.title + " - Piped";
|
2021-07-18 23:17:39 +05:30
|
|
|
this.channelId = this.video.uploaderUrl.split("/")[2];
|
2021-08-04 10:43:22 +05:30
|
|
|
if (!this.isEmbed) this.fetchSubscribedStatus();
|
2020-11-11 14:50:57 +05:30
|
|
|
|
2021-10-09 00:22:51 +05:30
|
|
|
this.video.description = this.video.description
|
|
|
|
.replaceAll("http://www.youtube.com", "")
|
|
|
|
.replaceAll("https://www.youtube.com", "")
|
|
|
|
.replaceAll("\n", "<br>");
|
2021-06-07 00:17:43 +05:30
|
|
|
}
|
2020-11-11 14:50:57 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
async getSponsors() {
|
2021-07-04 00:54:09 +05:30
|
|
|
if (this.getPreferenceBoolean("sponsorblock", true))
|
2021-02-25 20:10:40 +05:30
|
|
|
this.fetchSponsors().then(data => (this.sponsors = data));
|
2021-04-07 17:15:40 +05:30
|
|
|
},
|
2021-05-26 01:16:21 +05:30
|
|
|
async getComments() {
|
|
|
|
this.fetchComments().then(data => (this.comments = data));
|
|
|
|
},
|
2021-07-18 23:17:39 +05:30
|
|
|
async fetchSubscribedStatus() {
|
2021-07-21 02:13:03 +05:30
|
|
|
if (!this.channelId || !this.authenticated) return;
|
2021-07-18 23:17:39 +05:30
|
|
|
|
|
|
|
this.fetchJson(
|
|
|
|
this.apiUrl() + "/subscribed",
|
|
|
|
{
|
|
|
|
channelId: this.channelId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
).then(json => {
|
|
|
|
this.subscribed = json.subscribed;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
subscribeHandler() {
|
|
|
|
this.fetchJson(this.apiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: this.channelId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.subscribed = !this.subscribed;
|
|
|
|
},
|
2021-05-26 13:40:22 +05:30
|
|
|
handleScroll() {
|
|
|
|
if (this.loading || !this.comments || !this.comments.nextpage) return;
|
2021-05-26 13:54:20 +05:30
|
|
|
if (window.innerHeight + window.scrollY >= this.$refs.comments.offsetHeight - window.innerHeight) {
|
2021-05-26 13:40:22 +05:30
|
|
|
this.loading = true;
|
2021-07-04 23:56:02 +05:30
|
|
|
this.fetchJson(this.apiUrl() + "/nextpage/comments/" + this.getVideoId(), {
|
2021-07-30 00:56:56 +05:30
|
|
|
nextpage: this.comments.nextpage,
|
2021-06-15 17:07:35 +05:30
|
|
|
}).then(json => {
|
2021-05-26 13:40:22 +05:30
|
|
|
this.comments.nextpage = json.nextpage;
|
|
|
|
this.loading = false;
|
|
|
|
json.comments.map(comment => this.comments.comments.push(comment));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-06-07 23:08:19 +05:30
|
|
|
getVideoId() {
|
|
|
|
return this.$route.query.v || this.$route.params.v;
|
|
|
|
},
|
2021-04-01 20:43:35 +05:30
|
|
|
},
|
2020-11-11 14:50:57 +05:30
|
|
|
};
|
|
|
|
</script>
|