2020-11-27 12:16:36 +05:30
|
|
|
<template>
|
2021-06-07 00:17:43 +05:30
|
|
|
<ErrorHandler v-if="channel && channel.error" :message="channel.message" :error="channel.error" />
|
|
|
|
|
2023-03-13 19:09:07 +05:30
|
|
|
<LoadingIndicatorPage :show-content="channel != null && !channel.error">
|
2023-03-16 05:08:29 +05:30
|
|
|
<img
|
|
|
|
v-if="channel.bannerUrl"
|
|
|
|
:src="channel.bannerUrl"
|
2023-08-13 23:01:57 +05:30
|
|
|
class="h-30 w-full object-cover py-1.5 md:h-50"
|
2023-03-16 05:08:29 +05:30
|
|
|
loading="lazy"
|
|
|
|
/>
|
2023-08-13 23:01:57 +05:30
|
|
|
<div class="flex flex-col items-center justify-between md:flex-row">
|
2023-03-15 20:08:30 +05:30
|
|
|
<div class="flex place-items-center">
|
2023-08-13 23:01:57 +05:30
|
|
|
<img height="48" width="48" class="m-1 rounded-full" :src="channel.avatarUrl" />
|
|
|
|
<div class="flex items-center gap-1">
|
2023-07-27 17:16:05 +05:30
|
|
|
<h1 class="!text-xl" v-text="channel.name" />
|
|
|
|
<font-awesome-icon v-if="channel.verified" class="!text-xl" icon="check" />
|
2023-03-15 20:08:30 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-27 12:16:36 +05:30
|
|
|
|
2023-03-15 20:08:30 +05:30
|
|
|
<div class="flex gap-2">
|
|
|
|
<button
|
|
|
|
v-t="{
|
|
|
|
path: `actions.${subscribed ? 'unsubscribe' : 'subscribe'}`,
|
|
|
|
args: { count: numberFormat(channel.subscriberCount) },
|
|
|
|
}"
|
2023-07-27 17:16:05 +05:30
|
|
|
class="btn"
|
|
|
|
@click="subscribeHandler"
|
2023-03-15 20:08:30 +05:30
|
|
|
></button>
|
|
|
|
|
|
|
|
<!-- RSS Feed button -->
|
|
|
|
<a
|
2023-07-27 17:16:05 +05:30
|
|
|
v-if="channel.id"
|
2023-03-15 20:08:30 +05:30
|
|
|
aria-label="RSS feed"
|
|
|
|
title="RSS feed"
|
|
|
|
role="button"
|
|
|
|
:href="`${apiUrl()}/feed/unauthenticated/rss?channels=${channel.id}`"
|
|
|
|
target="_blank"
|
|
|
|
class="btn flex-col"
|
|
|
|
>
|
|
|
|
<font-awesome-icon icon="rss" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-17 04:26:41 +05:30
|
|
|
|
2023-05-23 21:54:32 +05:30
|
|
|
<CollapsableText :text="channel.description" />
|
2022-09-09 02:54:33 +05:30
|
|
|
|
2023-07-27 17:16:05 +05:30
|
|
|
<WatchOnButton :link="`https://youtube.com/channel/${channel.id}`" />
|
2022-11-02 21:40:27 +05:30
|
|
|
|
2023-08-13 23:01:57 +05:30
|
|
|
<div class="mx-1 my-2 flex">
|
2022-11-01 17:37:31 +05:30
|
|
|
<button
|
|
|
|
v-for="(tab, index) in tabs"
|
|
|
|
:key="tab.name"
|
|
|
|
class="btn mr-2"
|
|
|
|
:class="{ active: selectedTab == index }"
|
2023-07-27 17:16:05 +05:30
|
|
|
@click="loadTab(index)"
|
2022-11-01 17:37:31 +05:30
|
|
|
>
|
2022-11-01 17:01:45 +05:30
|
|
|
<span v-text="tab.translatedName"></span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2020-11-27 12:16:36 +05:30
|
|
|
<hr />
|
|
|
|
|
2021-12-27 20:16:22 +05:30
|
|
|
<div class="video-grid">
|
2022-11-01 17:01:45 +05:30
|
|
|
<ContentItem
|
|
|
|
v-for="item in contentItems"
|
|
|
|
:key="item.url"
|
2022-11-01 17:42:54 +05:30
|
|
|
:item="item"
|
2021-12-27 20:16:39 +05:30
|
|
|
height="94"
|
|
|
|
width="168"
|
|
|
|
hide-channel
|
|
|
|
/>
|
2020-11-27 12:16:36 +05:30
|
|
|
</div>
|
2023-03-13 19:09:07 +05:30
|
|
|
</LoadingIndicatorPage>
|
2020-11-27 12:16:36 +05:30
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-04-08 21:16:49 +05:30
|
|
|
import ErrorHandler from "./ErrorHandler.vue";
|
2022-11-01 17:01:45 +05:30
|
|
|
import ContentItem from "./ContentItem.vue";
|
2023-06-16 20:37:35 +05:30
|
|
|
import WatchOnButton from "./WatchOnButton.vue";
|
2023-03-13 19:09:07 +05:30
|
|
|
import LoadingIndicatorPage from "./LoadingIndicatorPage.vue";
|
2023-05-23 21:54:32 +05:30
|
|
|
import CollapsableText from "./CollapsableText.vue";
|
2020-11-27 12:16:36 +05:30
|
|
|
|
|
|
|
export default {
|
2021-10-09 00:22:51 +05:30
|
|
|
components: {
|
|
|
|
ErrorHandler,
|
2022-11-01 17:01:45 +05:30
|
|
|
ContentItem,
|
2023-06-16 20:37:35 +05:30
|
|
|
WatchOnButton,
|
2023-03-13 19:09:07 +05:30
|
|
|
LoadingIndicatorPage,
|
2023-05-23 21:54:32 +05:30
|
|
|
CollapsableText,
|
2021-10-09 00:22:51 +05:30
|
|
|
},
|
2020-11-27 12:16:36 +05:30
|
|
|
data() {
|
|
|
|
return {
|
2021-04-07 17:15:40 +05:30
|
|
|
channel: null,
|
2022-08-02 14:11:35 +05:30
|
|
|
subscribed: false,
|
2022-11-01 17:01:45 +05:30
|
|
|
tabs: [],
|
|
|
|
selectedTab: 0,
|
|
|
|
contentItems: [],
|
2020-11-27 12:16:36 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getChannelData();
|
2021-07-07 19:48:09 +05:30
|
|
|
},
|
|
|
|
activated() {
|
2021-07-21 16:29:53 +05:30
|
|
|
if (this.channel && !this.channel.error) document.title = this.channel.name + " - Piped";
|
2020-11-27 12:16:36 +05:30
|
|
|
window.addEventListener("scroll", this.handleScroll);
|
2021-08-22 15:57:09 +05:30
|
|
|
if (this.channel && !this.channel.error) this.updateWatched(this.channel.relatedStreams);
|
2020-11-27 12:16:36 +05:30
|
|
|
},
|
2021-07-07 19:48:09 +05:30
|
|
|
deactivated() {
|
2020-11-27 12:16:36 +05:30
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2021-09-06 02:23:59 +05:30
|
|
|
unmounted() {
|
|
|
|
window.removeEventListener("scroll", this.handleScroll);
|
|
|
|
},
|
2020-11-27 12:16:36 +05:30
|
|
|
methods: {
|
2021-07-17 04:26:41 +05:30
|
|
|
async fetchSubscribedStatus() {
|
2022-08-02 14:11:35 +05:30
|
|
|
if (!this.channel.id) return;
|
|
|
|
if (!this.authenticated) {
|
|
|
|
this.subscribed = this.isSubscribedLocally(this.channel.id);
|
|
|
|
return;
|
|
|
|
}
|
2022-08-01 19:46:06 +05:30
|
|
|
|
2021-07-17 04:26:41 +05:30
|
|
|
this.fetchJson(
|
2022-07-21 09:34:57 +05:30
|
|
|
this.authApiUrl() + "/subscribed",
|
2021-07-17 04:26:41 +05:30
|
|
|
{
|
|
|
|
channelId: this.channel.id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
).then(json => {
|
|
|
|
this.subscribed = json.subscribed;
|
|
|
|
});
|
|
|
|
},
|
2020-11-27 12:16:36 +05:30
|
|
|
async fetchChannel() {
|
2023-03-12 00:14:07 +05:30
|
|
|
const url = this.$route.path.includes("@")
|
2023-04-27 18:01:46 +05:30
|
|
|
? this.apiUrl() + "/@/" + this.$route.params.channelId
|
2023-03-12 00:14:07 +05:30
|
|
|
: this.apiUrl() + "/" + this.$route.params.path + "/" + this.$route.params.channelId;
|
2021-05-29 00:10:54 +05:30
|
|
|
return await this.fetchJson(url);
|
2020-11-27 12:16:36 +05:30
|
|
|
},
|
|
|
|
async getChannelData() {
|
|
|
|
this.fetchChannel()
|
|
|
|
.then(data => (this.channel = data))
|
2021-06-07 00:17:43 +05:30
|
|
|
.then(() => {
|
2021-07-17 04:26:41 +05:30
|
|
|
if (!this.channel.error) {
|
|
|
|
document.title = this.channel.name + " - Piped";
|
2022-11-01 17:01:45 +05:30
|
|
|
this.contentItems = this.channel.relatedStreams;
|
2022-08-02 14:11:35 +05:30
|
|
|
this.fetchSubscribedStatus();
|
2021-08-22 15:57:09 +05:30
|
|
|
this.updateWatched(this.channel.relatedStreams);
|
2023-07-22 01:37:53 +05:30
|
|
|
this.fetchDeArrowContent(this.channel.relatedStreams);
|
2022-11-01 17:01:45 +05:30
|
|
|
this.tabs.push({
|
|
|
|
translatedName: this.$t("video.videos"),
|
|
|
|
});
|
2023-01-27 00:06:20 +05:30
|
|
|
const tabQuery = this.$route.query.tab;
|
2022-11-01 17:01:45 +05:30
|
|
|
for (let i = 0; i < this.channel.tabs.length; i++) {
|
|
|
|
let tab = this.channel.tabs[i];
|
|
|
|
tab.translatedName = this.getTranslatedTabName(tab.name);
|
|
|
|
this.tabs.push(tab);
|
2023-01-27 00:06:20 +05:30
|
|
|
if (tab.name === tabQuery) this.loadTab(i + 1);
|
2022-11-01 17:01:45 +05:30
|
|
|
}
|
2021-07-17 04:26:41 +05:30
|
|
|
}
|
2021-06-07 00:17:43 +05:30
|
|
|
});
|
2020-11-27 12:16:36 +05:30
|
|
|
},
|
|
|
|
handleScroll() {
|
2022-11-01 20:45:12 +05:30
|
|
|
if (
|
|
|
|
this.loading ||
|
|
|
|
!this.channel ||
|
|
|
|
!this.channel.nextpage ||
|
|
|
|
(this.selectedTab != 0 && !this.tabs[this.selectedTab].tabNextPage)
|
|
|
|
)
|
|
|
|
return;
|
2021-04-07 17:15:40 +05:30
|
|
|
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
|
2020-11-27 12:16:36 +05:30
|
|
|
this.loading = true;
|
2022-11-01 17:09:01 +05:30
|
|
|
if (this.selectedTab == 0) {
|
|
|
|
this.fetchChannelNextPage();
|
|
|
|
} else {
|
|
|
|
this.fetchChannelTabNextPage();
|
|
|
|
}
|
2020-11-27 12:16:36 +05:30
|
|
|
}
|
2021-04-07 17:15:40 +05:30
|
|
|
},
|
2022-11-01 17:09:01 +05:30
|
|
|
fetchChannelNextPage() {
|
|
|
|
this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, {
|
|
|
|
nextpage: this.channel.nextpage,
|
|
|
|
}).then(json => {
|
|
|
|
this.channel.nextpage = json.nextpage;
|
|
|
|
this.loading = false;
|
|
|
|
this.updateWatched(json.relatedStreams);
|
|
|
|
json.relatedStreams.map(stream => this.contentItems.push(stream));
|
2023-07-22 01:37:53 +05:30
|
|
|
this.fetchDeArrowContent(this.contentItems);
|
2022-11-01 17:09:01 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchChannelTabNextPage() {
|
|
|
|
this.fetchJson(this.apiUrl() + "/channels/tabs", {
|
|
|
|
data: this.tabs[this.selectedTab].data,
|
2022-11-01 20:45:12 +05:30
|
|
|
nextpage: this.tabs[this.selectedTab].tabNextPage,
|
2022-11-01 17:09:01 +05:30
|
|
|
}).then(json => {
|
2022-11-01 20:45:12 +05:30
|
|
|
this.tabs[this.selectedTab].tabNextPage = json.nextpage;
|
2022-11-01 17:09:01 +05:30
|
|
|
this.loading = false;
|
|
|
|
json.content.map(item => this.contentItems.push(item));
|
2023-07-22 01:37:53 +05:30
|
|
|
this.fetchDeArrowContent(this.contentItems);
|
2022-11-01 20:45:12 +05:30
|
|
|
this.tabs[this.selectedTab].content = this.contentItems;
|
2022-11-01 17:09:01 +05:30
|
|
|
});
|
|
|
|
},
|
2021-07-17 04:26:41 +05:30
|
|
|
subscribeHandler() {
|
2022-08-01 19:46:06 +05:30
|
|
|
if (this.authenticated) {
|
|
|
|
this.fetchJson(this.authApiUrl() + (this.subscribed ? "/unsubscribe" : "/subscribe"), null, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
channelId: this.channel.id,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
Authorization: this.getAuthToken(),
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
2022-11-07 15:50:13 +05:30
|
|
|
if (!this.handleLocalSubscriptions(this.channel.id)) return;
|
2022-08-01 19:46:06 +05:30
|
|
|
}
|
2021-07-17 04:26:41 +05:30
|
|
|
this.subscribed = !this.subscribed;
|
|
|
|
},
|
2022-11-01 17:01:45 +05:30
|
|
|
getTranslatedTabName(tabName) {
|
|
|
|
let translatedTabName = tabName;
|
|
|
|
switch (tabName) {
|
2022-11-16 03:05:56 +05:30
|
|
|
case "livestreams":
|
2022-11-01 17:01:45 +05:30
|
|
|
translatedTabName = this.$t("titles.livestreams");
|
|
|
|
break;
|
2022-11-16 03:05:56 +05:30
|
|
|
case "playlists":
|
2022-11-01 17:01:45 +05:30
|
|
|
translatedTabName = this.$t("titles.playlists");
|
|
|
|
break;
|
2022-11-16 03:05:56 +05:30
|
|
|
case "channels":
|
2022-11-01 17:01:45 +05:30
|
|
|
translatedTabName = this.$t("titles.channels");
|
|
|
|
break;
|
2022-11-16 03:05:56 +05:30
|
|
|
case "shorts":
|
2022-11-01 17:01:45 +05:30
|
|
|
translatedTabName = this.$t("video.shorts");
|
|
|
|
break;
|
2022-11-01 17:52:23 +05:30
|
|
|
default:
|
|
|
|
console.error(`Tab name "${tabName}" is not translated yet!`);
|
|
|
|
break;
|
2022-11-01 17:01:45 +05:30
|
|
|
}
|
|
|
|
return translatedTabName;
|
|
|
|
},
|
|
|
|
loadTab(index) {
|
2022-11-01 17:09:01 +05:30
|
|
|
this.selectedTab = index;
|
2023-01-27 21:12:20 +05:30
|
|
|
|
|
|
|
// update the tab query in the url path
|
|
|
|
const url = new URL(window.location);
|
|
|
|
url.searchParams.set("tab", this.tabs[index].name ?? "videos");
|
|
|
|
window.history.replaceState(window.history.state, "", url);
|
2023-01-27 00:13:07 +05:30
|
|
|
|
2022-11-01 17:01:45 +05:30
|
|
|
if (index == 0) {
|
|
|
|
this.contentItems = this.channel.relatedStreams;
|
|
|
|
return;
|
|
|
|
}
|
2023-01-27 00:13:07 +05:30
|
|
|
|
2022-11-01 20:45:12 +05:30
|
|
|
if (this.tabs[index].content) {
|
|
|
|
this.contentItems = this.tabs[index].content;
|
|
|
|
return;
|
|
|
|
}
|
2022-11-01 17:01:45 +05:30
|
|
|
this.fetchJson(this.apiUrl() + "/channels/tabs", {
|
|
|
|
data: this.tabs[index].data,
|
|
|
|
}).then(tab => {
|
2022-11-01 20:45:12 +05:30
|
|
|
this.contentItems = this.tabs[index].content = tab.content;
|
2023-07-22 01:37:53 +05:30
|
|
|
this.fetchDeArrowContent(this.contentItems);
|
2022-11-01 20:45:12 +05:30
|
|
|
this.tabs[this.selectedTab].tabNextPage = tab.nextpage;
|
2022-11-01 17:01:45 +05:30
|
|
|
});
|
|
|
|
},
|
2021-04-07 17:15:40 +05:30
|
|
|
},
|
2020-11-27 12:16:36 +05:30
|
|
|
};
|
|
|
|
</script>
|
2022-11-01 17:37:31 +05:30
|
|
|
|
|
|
|
<style>
|
|
|
|
.active {
|
|
|
|
border: 0.1rem outset red;
|
|
|
|
}
|
|
|
|
</style>
|