2020-11-11 09:20:57 +00:00
|
|
|
<template>
|
2022-02-22 06:13:36 +00:00
|
|
|
<div v-if="video && isEmbed" class="absolute top-0 left-0 h-full w-full bg-black z-50">
|
2022-01-13 05:12:06 +00:00
|
|
|
<VideoPlayer
|
2021-08-04 05:13:22 +00:00
|
|
|
ref="videoPlayer"
|
|
|
|
:video="video"
|
|
|
|
:sponsors="sponsors"
|
2022-04-08 21:29:50 +00:00
|
|
|
:playlist="playlist"
|
|
|
|
:index="index"
|
2021-10-08 18:52:51 +00:00
|
|
|
:selected-auto-play="false"
|
|
|
|
:selected-auto-loop="selectedAutoLoop"
|
|
|
|
:is-embed="isEmbed"
|
2021-08-04 05:13:22 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2021-12-27 14:46:26 +00:00
|
|
|
<div v-if="video && !isEmbed" class="w-full">
|
2021-06-06 19:12:03 +00:00
|
|
|
<ErrorHandler v-if="video && video.error" :message="video.message" :error="video.error" />
|
2020-11-17 05:15:35 +00:00
|
|
|
|
2021-06-06 18:47:43 +00:00
|
|
|
<div v-show="!video.error">
|
2022-06-24 01:04:01 +00:00
|
|
|
<div :class="isMobile ? 'flex-col' : 'flex'">
|
|
|
|
<VideoPlayer
|
|
|
|
ref="videoPlayer"
|
|
|
|
:video="video"
|
|
|
|
:sponsors="sponsors"
|
|
|
|
:playlist="playlist"
|
|
|
|
:index="index"
|
|
|
|
:selected-auto-play="selectedAutoPlay"
|
|
|
|
:selected-auto-loop="selectedAutoLoop"
|
2022-07-19 16:29:03 +00:00
|
|
|
@timeupdate="onTimeUpdate"
|
2022-06-24 01:04:01 +00:00
|
|
|
/>
|
|
|
|
<ChaptersBar
|
|
|
|
:mobileLayout="isMobile"
|
2022-09-17 17:57:47 +00:00
|
|
|
v-if="video?.chapters?.length > 0 && showChapters"
|
2022-06-24 01:04:01 +00:00
|
|
|
:chapters="video.chapters"
|
2022-07-19 16:29:03 +00:00
|
|
|
:player-position="currentTime"
|
2022-06-24 01:04:01 +00:00
|
|
|
@seek="navigate"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-07-02 16:53:15 +00:00
|
|
|
<!-- video title -->
|
2021-12-27 16:29:25 +00:00
|
|
|
<div class="font-bold mt-2 text-2xl break-words" v-text="video.title" />
|
2022-07-02 16:53:15 +00:00
|
|
|
<div class="flex flex-wrap mt-3 mb-3">
|
|
|
|
<!-- views / date -->
|
|
|
|
<div class="flex flex-auto children:ml-2">
|
|
|
|
<span v-t="{ path: 'video.views', args: { views: addCommas(video.views) } }" />
|
|
|
|
<span> | </span>
|
|
|
|
<span v-text="uploadDate" />
|
|
|
|
</div>
|
|
|
|
<!-- Likes/dilikes -->
|
|
|
|
<div class="flex children:mr-2">
|
2021-12-27 14:46:32 +00:00
|
|
|
<template v-if="video.likes >= 0">
|
2022-10-21 19:51:32 +00:00
|
|
|
<div class="flex items-center">
|
2022-08-17 13:34:57 +00:00
|
|
|
<div class="i-fa-solid:thumbs-up" />
|
|
|
|
<strong class="ml-1" v-text="addCommas(video.likes)" />
|
2021-12-27 14:46:32 +00:00
|
|
|
</div>
|
2022-10-21 19:51:32 +00:00
|
|
|
<div class="flex items-center">
|
2022-08-17 13:34:57 +00:00
|
|
|
<div class="i-fa-solid:thumbs-down" />
|
|
|
|
<strong class="ml-1" v-text="video.dislikes >= 0 ? addCommas(video.dislikes) : '?'" />
|
2021-12-27 14:46:32 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template v-if="video.likes < 0">
|
|
|
|
<div>
|
2021-12-27 14:43:37 +00:00
|
|
|
<strong v-t="'video.ratings_disabled'" />
|
2021-12-27 14:46:32 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
2021-07-18 17:47:39 +00:00
|
|
|
</div>
|
2022-07-02 16:53:15 +00:00
|
|
|
<!-- Channel info & options flex container -->
|
2021-12-27 14:46:32 +00:00
|
|
|
<div class="flex">
|
2022-07-02 04:45:07 +00:00
|
|
|
<!-- Channel Image & Info -->
|
2021-12-27 14:46:32 +00:00
|
|
|
<div class="flex items-center">
|
|
|
|
<img :src="video.uploaderAvatar" alt="" loading="lazy" class="rounded-full" />
|
2022-05-19 21:17:58 +00:00
|
|
|
<router-link v-if="video.uploaderUrl" class="link ml-1.5" :to="video.uploaderUrl">{{
|
|
|
|
video.uploader
|
|
|
|
}}</router-link>
|
2022-07-02 04:45:07 +00:00
|
|
|
<!-- Verified Badge -->
|
2021-12-27 22:33:55 +00:00
|
|
|
<font-awesome-icon class="ml-1" v-if="video.uploaderVerified" icon="check" />
|
2021-12-27 14:46:32 +00:00
|
|
|
</div>
|
2022-11-08 17:03:40 +00:00
|
|
|
<div class="flex relative ml-auto children:mr-1 items-center">
|
2022-04-07 15:48:03 +00:00
|
|
|
<button class="btn" v-if="authenticated" @click="showModal = !showModal">
|
|
|
|
{{ $t("actions.add_to_playlist") }}<font-awesome-icon class="ml-1" icon="circle-plus" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="btn"
|
|
|
|
@click="subscribeHandler"
|
|
|
|
v-t="{
|
|
|
|
path: `actions.${subscribed ? 'unsubscribe' : 'subscribe'}`,
|
|
|
|
args: { count: numberFormat(video.uploaderSubscriberCount) },
|
|
|
|
}"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<PlaylistAddModal v-if="showModal" :video-id="getVideoId()" @close="showModal = !showModal" />
|
2022-08-28 14:29:11 +00:00
|
|
|
<ShareModal
|
|
|
|
v-if="showShareModal"
|
|
|
|
:video-id="getVideoId()"
|
|
|
|
:current-time="currentTime"
|
2022-12-04 23:19:24 +00:00
|
|
|
:playlist-id="playlistId"
|
|
|
|
:playlist-index="index"
|
2022-08-28 14:29:11 +00:00
|
|
|
@close="showShareModal = !showShareModal"
|
|
|
|
/>
|
2022-07-22 17:14:24 +00:00
|
|
|
<div class="flex">
|
|
|
|
<div class="self-center children:mr-1 my-1">
|
2022-07-02 16:53:15 +00:00
|
|
|
<!-- RSS Feed button -->
|
|
|
|
<a
|
|
|
|
aria-label="RSS feed"
|
|
|
|
title="RSS feed"
|
|
|
|
role="button"
|
|
|
|
v-if="video.uploaderUrl"
|
2022-09-09 10:40:18 +00:00
|
|
|
:href="`${apiUrl()}/feed/unauthenticated/rss?channels=${video.uploaderUrl.split('/')[2]}`"
|
2022-07-02 16:53:15 +00:00
|
|
|
target="_blank"
|
|
|
|
class="btn flex-col"
|
|
|
|
>
|
|
|
|
<font-awesome-icon icon="rss" />
|
|
|
|
</a>
|
2022-11-03 09:14:08 +00:00
|
|
|
<WatchOnYouTubeButton :link="`https://youtu.be/${getVideoId()}`" />
|
2022-11-02 16:10:27 +00:00
|
|
|
<!-- Share Dialog -->
|
2022-08-28 14:29:11 +00:00
|
|
|
<button class="btn" @click="showShareModal = !showShareModal">
|
2022-08-29 13:19:14 +00:00
|
|
|
<i18n-t class="lt-lg:hidden" keypath="actions.share" tag="strong"></i18n-t>
|
|
|
|
<font-awesome-icon class="mx-1.5" icon="fa-share" />
|
2022-08-28 14:29:11 +00:00
|
|
|
</button>
|
2022-07-02 16:53:15 +00:00
|
|
|
<!-- LBRY -->
|
|
|
|
<a v-if="video.lbryId" :href="'https://odysee.com/' + video.lbryId" class="btn">
|
|
|
|
<i18n-t keypath="player.watch_on" tag="strong">LBRY</i18n-t>
|
|
|
|
</a>
|
|
|
|
<!-- listen / watch toggle -->
|
|
|
|
<router-link
|
|
|
|
:to="toggleListenUrl"
|
|
|
|
:aria-label="(isListening ? 'Watch ' : 'Listen to ') + video.title"
|
|
|
|
:title="(isListening ? 'Watch ' : 'Listen to ') + video.title"
|
|
|
|
class="btn flex-col"
|
|
|
|
>
|
|
|
|
<font-awesome-icon :icon="isListening ? 'tv' : 'headphones'" />
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-30 20:26:04 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 16:29:25 +00:00
|
|
|
<button
|
|
|
|
class="btn mb-2"
|
|
|
|
@click="showDesc = !showDesc"
|
2022-01-30 23:48:27 +00:00
|
|
|
v-t="`actions.${showDesc ? 'minimize_description' : 'show_description'}`"
|
2021-12-27 16:29:25 +00:00
|
|
|
/>
|
2022-09-17 17:57:47 +00:00
|
|
|
|
2022-09-19 20:23:48 +00:00
|
|
|
<span class="btn" v-show="video?.chapters?.length > 0">
|
|
|
|
<input id="showChapters" type="checkbox" v-model="showChapters" />
|
2022-09-17 17:57:47 +00:00
|
|
|
<label class="ml-2" for="showChapters" v-t="'actions.show_chapters'" />
|
|
|
|
</span>
|
|
|
|
|
2021-10-08 18:52:51 +00:00
|
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
2022-03-01 09:56:27 +00:00
|
|
|
<div v-show="showDesc" class="break-words" v-html="purifyHTML(video.description)" />
|
2021-12-27 16:29:25 +00:00
|
|
|
<div
|
|
|
|
v-if="showDesc && sponsors && sponsors.segments"
|
|
|
|
v-text="`${$t('video.sponsor_segments')}: ${sponsors.segments.length}`"
|
|
|
|
/>
|
2021-06-06 18:47:43 +00:00
|
|
|
</div>
|
2020-11-17 05:15:35 +00:00
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2021-12-27 16:29:25 +00:00
|
|
|
<label for="chkAutoLoop"><strong v-text="`${$t('actions.loop_this_video')}:`" /></label>
|
2021-12-27 14:46:39 +00:00
|
|
|
<input id="chkAutoLoop" v-model="selectedAutoLoop" class="ml-1.5" type="checkbox" @change="onChange($event)" />
|
2021-07-04 18:42:10 +00:00
|
|
|
<br />
|
2021-12-27 16:29:25 +00:00
|
|
|
<label for="chkAutoPlay"><strong v-text="`${$t('actions.auto_play_next_video')}:`" /></label>
|
2021-12-27 14:46:39 +00:00
|
|
|
<input id="chkAutoPlay" v-model="selectedAutoPlay" class="ml-1.5" type="checkbox" @change="onChange($event)" />
|
2020-12-10 07:53:30 +00:00
|
|
|
|
2021-05-25 19:46:21 +00:00
|
|
|
<hr />
|
|
|
|
|
2021-12-27 14:46:26 +00:00
|
|
|
<div class="grid xl:grid-cols-5 sm:grid-cols-4 grid-cols-1">
|
2022-10-23 23:21:47 +00:00
|
|
|
<div class="xl:col-span-4 sm:col-span-3">
|
|
|
|
<button
|
|
|
|
class="btn mb-2"
|
|
|
|
@click="toggleComments"
|
|
|
|
v-t="`actions.${showComments ? 'minimize_comments' : 'show_comments'}`"
|
|
|
|
/>
|
2022-07-20 17:12:21 +00:00
|
|
|
</div>
|
2022-10-23 23:21:47 +00:00
|
|
|
<div v-if="!showComments" class="xl:col-span-4 sm:col-span-3"></div>
|
2022-07-20 17:12:21 +00:00
|
|
|
<div v-else-if="!comments" class="xl:col-span-4 sm:col-span-3">
|
|
|
|
<p class="text-center mt-8" v-t="'comment.loading'"></p>
|
2022-05-15 12:27:10 +00:00
|
|
|
</div>
|
|
|
|
<div v-else-if="comments.disabled" class="xl:col-span-4 sm:col-span-3">
|
2022-07-20 17:12:21 +00:00
|
|
|
<p class="text-center mt-8" v-t="'comment.disabled'"></p>
|
2022-05-15 12:27:10 +00:00
|
|
|
</div>
|
|
|
|
<div v-else ref="comments" class="xl:col-span-4 sm:col-span-3">
|
2022-01-13 05:12:06 +00:00
|
|
|
<CommentItem
|
2021-10-08 18:52:51 +00:00
|
|
|
v-for="comment in comments.comments"
|
|
|
|
:key="comment.commentId"
|
2021-12-27 14:46:32 +00:00
|
|
|
:comment="comment"
|
|
|
|
:uploader="video.uploader"
|
|
|
|
:video-id="getVideoId()"
|
|
|
|
/>
|
2021-05-25 19:46:21 +00:00
|
|
|
</div>
|
|
|
|
|
2021-12-27 14:46:32 +00:00
|
|
|
<div v-if="video" class="order-first sm:order-last">
|
2022-04-08 21:29:50 +00:00
|
|
|
<PlaylistVideos
|
|
|
|
v-if="playlist"
|
|
|
|
:playlist-id="playlistId"
|
|
|
|
:playlist="playlist"
|
|
|
|
:selected-index="index"
|
|
|
|
/>
|
2021-12-27 16:29:25 +00:00
|
|
|
<a
|
2022-07-19 19:47:04 +00:00
|
|
|
class="btn mb-2"
|
2021-12-27 16:29:25 +00:00
|
|
|
@click="showRecs = !showRecs"
|
2022-01-30 23:48:27 +00:00
|
|
|
v-t="`actions.${showRecs ? 'minimize_recommendations' : 'show_recommendations'}`"
|
2021-12-27 16:29:25 +00:00
|
|
|
/>
|
2022-01-12 22:17:22 +00:00
|
|
|
<hr v-show="showRecs" />
|
2022-07-19 19:47:04 +00:00
|
|
|
<div v-show="showRecs">
|
2022-11-01 12:12:54 +00:00
|
|
|
<ContentItem
|
2022-01-12 22:17:22 +00:00
|
|
|
v-for="related in video.relatedStreams"
|
|
|
|
:key="related.url"
|
2022-11-01 12:12:54 +00:00
|
|
|
:item="related"
|
2022-01-12 22:17:22 +00:00
|
|
|
height="94"
|
|
|
|
width="168"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-12-27 14:46:26 +00:00
|
|
|
<hr class="sm:hidden" />
|
2021-05-25 19:46:21 +00:00
|
|
|
</div>
|
2020-11-17 05:15:35 +00:00
|
|
|
</div>
|
2020-11-12 20:42:02 +00:00
|
|
|
</div>
|
2020-11-11 09:20:57 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-08 15:46:49 +00:00
|
|
|
import VideoPlayer from "./VideoPlayer.vue";
|
2022-11-01 12:12:54 +00:00
|
|
|
import ContentItem from "./ContentItem.vue";
|
2022-04-08 15:46:49 +00:00
|
|
|
import ErrorHandler from "./ErrorHandler.vue";
|
|
|
|
import CommentItem from "./CommentItem.vue";
|
2022-05-19 21:17:58 +00:00
|
|
|
import ChaptersBar from "./ChaptersBar.vue";
|
2022-04-07 15:48:03 +00:00
|
|
|
import PlaylistAddModal from "./PlaylistAddModal.vue";
|
2022-08-28 14:29:11 +00:00
|
|
|
import ShareModal from "./ShareModal.vue";
|
2022-04-08 21:29:50 +00:00
|
|
|
import PlaylistVideos from "./PlaylistVideos.vue";
|
2022-11-02 17:23:12 +00:00
|
|
|
import WatchOnYouTubeButton from "./WatchOnYouTubeButton.vue";
|
2020-11-11 09:20:57 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "App",
|
2021-10-08 18:52:51 +00:00
|
|
|
components: {
|
2022-01-13 05:12:06 +00:00
|
|
|
VideoPlayer,
|
2022-11-01 12:12:54 +00:00
|
|
|
ContentItem,
|
2021-10-08 18:52:51 +00:00
|
|
|
ErrorHandler,
|
2022-01-13 05:12:06 +00:00
|
|
|
CommentItem,
|
2022-05-19 21:17:58 +00:00
|
|
|
ChaptersBar,
|
2022-04-07 15:48:03 +00:00
|
|
|
PlaylistAddModal,
|
2022-08-28 14:29:11 +00:00
|
|
|
ShareModal,
|
2022-04-08 21:29:50 +00:00
|
|
|
PlaylistVideos,
|
2022-11-02 17:23:12 +00:00
|
|
|
WatchOnYouTubeButton,
|
2021-10-08 18:52:51 +00:00
|
|
|
},
|
2020-11-11 09:20:57 +00:00
|
|
|
data() {
|
2021-10-04 00:08:25 +00:00
|
|
|
const smallViewQuery = window.matchMedia("(max-width: 640px)");
|
2020-11-11 09:20:57 +00:00
|
|
|
return {
|
|
|
|
video: {
|
2021-04-07 11:45:40 +00:00
|
|
|
title: "Loading...",
|
2020-11-11 09:20:57 +00:00
|
|
|
},
|
2022-04-08 21:29:50 +00:00
|
|
|
playlistId: null,
|
|
|
|
playlist: null,
|
|
|
|
index: null,
|
2020-12-14 13:41:49 +00:00
|
|
|
sponsors: null,
|
2021-07-04 18:42:10 +00:00
|
|
|
selectedAutoLoop: false,
|
2021-01-15 09:49:46 +00:00
|
|
|
selectedAutoPlay: null,
|
2022-10-23 23:21:47 +00:00
|
|
|
showComments: true,
|
2021-04-07 11:45:40 +00:00
|
|
|
showDesc: true,
|
2021-10-04 00:08:25 +00:00
|
|
|
showRecs: true,
|
2022-09-17 17:57:47 +00:00
|
|
|
showChapters: true,
|
2021-05-25 19:46:21 +00:00
|
|
|
comments: null,
|
2021-07-18 17:47:39 +00:00
|
|
|
subscribed: false,
|
|
|
|
channelId: null,
|
2021-07-20 21:48:35 +00:00
|
|
|
active: true,
|
2021-10-04 00:08:25 +00:00
|
|
|
smallViewQuery: smallViewQuery,
|
|
|
|
smallView: smallViewQuery.matches,
|
2022-04-07 15:48:03 +00:00
|
|
|
showModal: false,
|
2022-08-28 14:29:11 +00:00
|
|
|
showShareModal: false,
|
2022-06-24 01:04:01 +00:00
|
|
|
isMobile: true,
|
2022-07-19 16:29:03 +00:00
|
|
|
currentTime: 0,
|
2020-11-11 09:20:57 +00:00
|
|
|
};
|
|
|
|
},
|
2021-10-08 18:52:51 +00:00
|
|
|
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");
|
2022-07-11 04:34:46 +00:00
|
|
|
return url.pathname + url.search;
|
2021-10-08 18:52:51 +00:00
|
|
|
},
|
|
|
|
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 09:20:57 +00:00
|
|
|
mounted() {
|
2022-06-24 01:04:01 +00:00
|
|
|
// check screen size
|
|
|
|
if (window.innerWidth >= 1024) {
|
|
|
|
this.isMobile = false;
|
|
|
|
}
|
|
|
|
// add an event listener to watch for screen size changes
|
|
|
|
window.addEventListener("resize", () => {
|
|
|
|
if (window.innerWidth >= 1024) {
|
|
|
|
this.isMobile = false;
|
|
|
|
} else {
|
|
|
|
this.isMobile = true;
|
|
|
|
}
|
|
|
|
});
|
2021-07-07 14:18:09 +00:00
|
|
|
this.getVideoData().then(() => {
|
2021-08-22 10:27:09 +00:00
|
|
|
(async () => {
|
2021-10-26 23:49:56 +00:00
|
|
|
const videoId = this.getVideoId();
|
|
|
|
const instance = this;
|
2023-01-13 13:40:12 +00:00
|
|
|
if (window.db && this.getPreferenceBoolean("watchHistory", false) && !this.video.error) {
|
2021-08-22 10:27:09 +00:00
|
|
|
var tx = window.db.transaction("watch_history", "readwrite");
|
|
|
|
var store = tx.objectStore("watch_history");
|
2021-10-26 23:49:56 +00:00
|
|
|
var request = store.get(videoId);
|
2022-01-01 14:53:55 +00:00
|
|
|
request.onsuccess = function (event) {
|
2021-10-26 23:49:56 +00:00
|
|
|
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 10:27:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|
2021-07-20 21:48:35 +00:00
|
|
|
if (this.active) this.$refs.videoPlayer.loadVideo();
|
2021-07-07 14:18:09 +00:00
|
|
|
});
|
2022-04-08 21:29:50 +00:00
|
|
|
this.playlistId = this.$route.query.list;
|
|
|
|
this.index = Number(this.$route.query.index);
|
|
|
|
this.getPlaylistData();
|
2020-11-11 09:20:57 +00:00
|
|
|
this.getSponsors();
|
2022-10-23 23:19:57 +00:00
|
|
|
if (!this.isEmbed && this.showComments) this.getComments();
|
2023-01-26 18:01:24 +00:00
|
|
|
window.addEventListener("click", this.handleClick);
|
2021-10-04 00:08:25 +00:00
|
|
|
window.addEventListener("resize", () => {
|
|
|
|
this.smallView = this.smallViewQuery.matches;
|
|
|
|
});
|
2021-07-07 14:18:09 +00:00
|
|
|
},
|
|
|
|
activated() {
|
2021-07-20 21:48:35 +00:00
|
|
|
this.active = true;
|
2022-08-28 10:32:39 +00:00
|
|
|
this.selectedAutoPlay = this.getPreferenceBoolean("autoplay", false);
|
2022-10-23 23:19:57 +00:00
|
|
|
this.showComments = !this.getPreferenceBoolean("minimizeComments", false);
|
2021-07-30 09:03:16 +00:00
|
|
|
this.showDesc = !this.getPreferenceBoolean("minimizeDescription", false);
|
2022-07-19 19:56:16 +00:00
|
|
|
this.showRecs = !this.getPreferenceBoolean("minimizeRecommendations", false);
|
2022-11-09 17:05:11 +00:00
|
|
|
this.showChapters = !this.getPreferenceBoolean("minimizeChapters", false);
|
2021-07-21 10:59:53 +00:00
|
|
|
if (this.video.duration) {
|
|
|
|
document.title = this.video.title + " - Piped";
|
|
|
|
this.$refs.videoPlayer.loadVideo();
|
|
|
|
}
|
2021-05-26 08:10:22 +00:00
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2021-07-07 14:18:09 +00:00
|
|
|
deactivated() {
|
2021-07-20 21:48:35 +00:00
|
|
|
this.active = false;
|
2021-05-26 08:10:22 +00:00
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
2020-11-11 09:20:57 +00:00
|
|
|
},
|
2021-09-05 21:01:26 +00:00
|
|
|
unmounted() {
|
2021-09-05 20:53:59 +00:00
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
2023-01-26 18:01:24 +00:00
|
|
|
window.removeEventListener("click", this.handleClick);
|
2021-09-05 20:53:59 +00:00
|
|
|
},
|
2020-11-11 09:20:57 +00:00
|
|
|
methods: {
|
2021-02-24 09:35:41 +00:00
|
|
|
fetchVideo() {
|
2021-07-04 18:26:02 +00:00
|
|
|
return this.fetchJson(this.apiUrl() + "/streams/" + this.getVideoId());
|
2020-11-11 09:20:57 +00:00
|
|
|
},
|
|
|
|
async fetchSponsors() {
|
2023-02-01 15:37:43 +00:00
|
|
|
var selectedSkip = this.getPreferenceString(
|
|
|
|
"selectedSkip",
|
|
|
|
"sponsor,interaction,selfpromo,music_offtopic",
|
|
|
|
).split(",");
|
2023-02-02 13:25:45 +00:00
|
|
|
const skipOptions = this.getPreferenceJSON("skipOptions");
|
2023-02-06 17:18:04 +00:00
|
|
|
if (skipOptions !== undefined) {
|
2023-02-01 15:37:43 +00:00
|
|
|
selectedSkip = Object.keys(skipOptions).filter(
|
|
|
|
k => skipOptions[k] !== undefined && skipOptions[k] !== "no",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-01 21:30:02 +00:00
|
|
|
const sponsors = await this.fetchJson(this.apiUrl() + "/sponsors/" + this.getVideoId(), {
|
2023-02-01 15:37:43 +00:00
|
|
|
category: JSON.stringify(selectedSkip),
|
2021-06-15 11:37:35 +00:00
|
|
|
});
|
2023-02-01 21:30:02 +00:00
|
|
|
|
|
|
|
const minSegmentLength = Math.max(this.getPreferenceNumber("minSegmentLength", 0), 0);
|
|
|
|
sponsors.segments = sponsors.segments.filter(segment => {
|
|
|
|
const length = segment.segment[1] - segment.segment[0];
|
|
|
|
return length >= minSegmentLength;
|
|
|
|
});
|
|
|
|
|
|
|
|
return sponsors;
|
2020-11-11 09:20:57 +00:00
|
|
|
},
|
2022-10-23 23:21:47 +00:00
|
|
|
toggleComments() {
|
|
|
|
this.showComments = !this.showComments;
|
|
|
|
if (this.showComments && this.comments === null) {
|
|
|
|
this.fetchComments();
|
|
|
|
}
|
|
|
|
},
|
2021-05-25 19:46:21 +00:00
|
|
|
fetchComments() {
|
2021-07-04 18:26:02 +00:00
|
|
|
return this.fetchJson(this.apiUrl() + "/comments/" + this.getVideoId());
|
2021-05-25 19:46:21 +00:00
|
|
|
},
|
2020-12-10 07:53:30 +00:00
|
|
|
onChange() {
|
2022-11-16 18:51:56 +00:00
|
|
|
this.setPreference("autoplay", this.selectedAutoPlay, true);
|
2020-12-10 07:53:30 +00:00
|
|
|
},
|
2020-11-11 09:20:57 +00:00
|
|
|
async getVideoData() {
|
2021-07-07 14:18:09 +00:00
|
|
|
await this.fetchVideo()
|
2021-02-24 09:35:41 +00:00
|
|
|
.then(data => {
|
|
|
|
this.video = data;
|
2021-11-11 08:16:00 +00:00
|
|
|
this.video.id = this.getVideoId();
|
2021-02-24 09:35:41 +00:00
|
|
|
})
|
2020-11-11 09:20:57 +00:00
|
|
|
.then(() => {
|
2021-06-06 18:47:43 +00:00
|
|
|
if (!this.video.error) {
|
|
|
|
document.title = this.video.title + " - Piped";
|
2021-07-18 17:47:39 +00:00
|
|
|
this.channelId = this.video.uploaderUrl.split("/")[2];
|
2021-08-04 05:13:22 +00:00
|
|
|
if (!this.isEmbed) this.fetchSubscribedStatus();
|
2020-11-11 09:20:57 +00:00
|
|
|
|
2022-03-01 09:56:27 +00:00
|
|
|
const parser = new DOMParser();
|
|
|
|
const xmlDoc = parser.parseFromString(this.video.description, "text/html");
|
2022-09-01 15:20:06 +00:00
|
|
|
xmlDoc.querySelectorAll("a").forEach(elem => {
|
|
|
|
if (!elem.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/))
|
|
|
|
elem.outerHTML = elem.getAttribute("href");
|
|
|
|
});
|
2022-03-01 09:56:27 +00:00
|
|
|
xmlDoc.querySelectorAll("br").forEach(elem => (elem.outerHTML = "\n"));
|
2023-01-30 18:42:57 +00:00
|
|
|
this.video.description = this.rewriteDescription(xmlDoc.querySelector("body").innerHTML);
|
2021-06-06 18:47:43 +00:00
|
|
|
}
|
2020-11-11 09:20:57 +00:00
|
|
|
});
|
|
|
|
},
|
2022-04-08 21:29:50 +00:00
|
|
|
async getPlaylistData() {
|
|
|
|
if (this.playlistId) {
|
|
|
|
await this.fetchJson(this.apiUrl() + "/playlists/" + this.playlistId).then(data => {
|
|
|
|
this.playlist = data;
|
|
|
|
});
|
|
|
|
await this.fetchPlaylistPages().then(() => {
|
|
|
|
if (!(this.index >= 0)) {
|
|
|
|
for (let i = 0; i < this.playlist.relatedStreams.length; i++)
|
|
|
|
if (this.playlist.relatedStreams[i].url.substr(-11) == this.getVideoId()) {
|
|
|
|
this.index = i + 1;
|
|
|
|
this.$router.replace({
|
|
|
|
query: { ...this.$route.query, index: this.index },
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async fetchPlaylistPages() {
|
|
|
|
if (this.playlist.nextpage) {
|
|
|
|
await this.fetchJson(this.apiUrl() + "/nextpage/playlists/" + this.playlistId, {
|
|
|
|
nextpage: this.playlist.nextpage,
|
|
|
|
}).then(json => {
|
|
|
|
this.playlist.relatedStreams = this.playlist.relatedStreams.concat(json.relatedStreams);
|
|
|
|
this.playlist.nextpage = json.nextpage;
|
|
|
|
});
|
|
|
|
await this.fetchPlaylistPages();
|
|
|
|
}
|
|
|
|
},
|
2020-11-11 09:20:57 +00:00
|
|
|
async getSponsors() {
|
2021-07-03 19:24:09 +00:00
|
|
|
if (this.getPreferenceBoolean("sponsorblock", true))
|
2021-02-25 14:40:40 +00:00
|
|
|
this.fetchSponsors().then(data => (this.sponsors = data));
|
2021-04-07 11:45:40 +00:00
|
|
|
},
|
2021-05-25 19:46:21 +00:00
|
|
|
async getComments() {
|
2022-12-07 23:31:27 +00:00
|
|
|
this.fetchComments().then(data => {
|
|
|
|
this.rewriteComments(data.comments);
|
|
|
|
this.comments = data;
|
|
|
|
});
|
2021-05-25 19:46:21 +00:00
|
|
|
},
|
2021-07-18 17:47:39 +00:00
|
|
|
async fetchSubscribedStatus() {
|
2022-08-01 14:16:06 +00:00
|
|
|
if (!this.channelId) return;
|
2022-08-02 08:41:35 +00:00
|
|
|
if (!this.authenticated) {
|
|
|
|
this.subscribed = this.isSubscribedLocally(this.channelId);
|
|
|
|
return;
|
|
|
|
}
|
2021-07-18 17:47:39 +00:00
|
|
|
|
|
|
|
this.fetchJson(
|
2022-07-21 04:04:57 +00:00
|
|
|
this.authApiUrl() + "/subscribed",
|
2021-07-18 17:47:39 +00:00
|
|
|
{
|
|
|
|
channelId: this.channelId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
).then(json => {
|
|
|
|
this.subscribed = json.subscribed;
|
|
|
|
});
|
|
|
|
},
|
2022-12-07 23:31:27 +00:00
|
|
|
rewriteComments(data) {
|
|
|
|
data.forEach(comment => {
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const xmlDoc = parser.parseFromString(comment.commentText, "text/html");
|
|
|
|
xmlDoc.querySelectorAll("a").forEach(elem => {
|
|
|
|
if (!elem.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/))
|
|
|
|
elem.outerHTML = elem.getAttribute("href");
|
|
|
|
});
|
|
|
|
comment.commentText = xmlDoc
|
|
|
|
.querySelector("body")
|
|
|
|
.innerHTML.replaceAll(/(?:http(?:s)?:\/\/)?(?:www\.)?youtube\.com(\/[/a-zA-Z0-9_?=&-]*)/gm, "$1")
|
|
|
|
.replaceAll(
|
|
|
|
/(?:http(?:s)?:\/\/)?(?:www\.)?youtu\.be\/(?:watch\?v=)?([/a-zA-Z0-9_?=&-]*)/gm,
|
|
|
|
"/watch?v=$1",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
2021-07-18 17:47:39 +00:00
|
|
|
subscribeHandler() {
|
2022-08-01 14:16:06 +00:00
|
|
|
if (this.authenticated) {
|
|
|
|
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: this.channelId,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
2022-11-07 10:20:13 +00:00
|
|
|
if (!this.handleLocalSubscriptions(this.channelId)) return;
|
2022-08-01 14:16:06 +00:00
|
|
|
}
|
2021-07-18 17:47:39 +00:00
|
|
|
this.subscribed = !this.subscribed;
|
2023-01-26 18:01:24 +00:00
|
|
|
},
|
|
|
|
handleClick(event) {
|
|
|
|
if (!event || !event.target) return;
|
|
|
|
var target = event.target;
|
|
|
|
if (
|
|
|
|
!target.nodeName == "A" ||
|
|
|
|
!target.getAttribute("href") ||
|
|
|
|
!target.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/)
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
const time = parseInt(target.getAttribute("href").match(/(?<=t=)\d+/)[0]);
|
|
|
|
this.navigate(time);
|
|
|
|
event.preventDefault();
|
2021-07-18 17:47:39 +00:00
|
|
|
},
|
2021-05-26 08:10:22 +00:00
|
|
|
handleScroll() {
|
|
|
|
if (this.loading || !this.comments || !this.comments.nextpage) return;
|
2022-10-24 09:49:13 +00:00
|
|
|
if (window.innerHeight + window.scrollY >= this.$refs.comments?.offsetHeight - window.innerHeight) {
|
2021-05-26 08:10:22 +00:00
|
|
|
this.loading = true;
|
2021-07-04 18:26:02 +00:00
|
|
|
this.fetchJson(this.apiUrl() + "/nextpage/comments/" + this.getVideoId(), {
|
2021-07-29 19:26:56 +00:00
|
|
|
nextpage: this.comments.nextpage,
|
2021-06-15 11:37:35 +00:00
|
|
|
}).then(json => {
|
2021-05-26 08:10:22 +00:00
|
|
|
this.comments.nextpage = json.nextpage;
|
|
|
|
this.loading = false;
|
2022-12-07 23:31:27 +00:00
|
|
|
this.rewriteComments(json.comments);
|
|
|
|
this.comments.comments = this.comments.comments.concat(json.comments);
|
2021-05-26 08:10:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-06-07 17:38:19 +00:00
|
|
|
getVideoId() {
|
|
|
|
return this.$route.query.v || this.$route.params.v;
|
|
|
|
},
|
2022-01-13 04:52:14 +00:00
|
|
|
navigate(time) {
|
|
|
|
this.$refs.videoPlayer.seek(time);
|
|
|
|
},
|
2022-07-19 16:29:03 +00:00
|
|
|
onTimeUpdate(time) {
|
|
|
|
this.currentTime = time;
|
|
|
|
},
|
2021-04-01 15:13:35 +00:00
|
|
|
},
|
2020-11-11 09:20:57 +00:00
|
|
|
};
|
|
|
|
</script>
|