0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-14 07:25:07 +00:00
VueTube/NUXT/store/channel/index.js

77 lines
3.7 KiB
JavaScript
Raw Normal View History

const getDefaultState = () => {
return {
loading: null,
error: null,
avatar: null,
banner: null,
title: null,
subscribe: null,
subscribeAlt: null,
descriptionPreview: null,
subscribers: null,
2022-05-18 21:51:33 +00:00
videosCount: null,
2022-05-18 23:36:27 +00:00
featuredChannels: null,
2022-05-19 17:52:08 +00:00
videoExample: null,
};
};
2022-05-14 22:48:43 +00:00
export const state = () => {
return getDefaultState();
};
2022-05-14 04:16:15 +00:00
export const actions = {
fetchChannel({ state }, channelUrl) {
Object.assign(state, getDefaultState());
state.loading = true;
2022-05-19 01:46:38 +00:00
console.log(channelUrl);
const channelRequest =
2022-05-21 02:01:39 +00:00
channelUrl.includes("/c/") ||
channelUrl.includes("/user/") ||
channelUrl.includes("/channel/")
2022-05-19 01:46:38 +00:00
? `https://youtube.com/${channelUrl}`
: `https://youtube.com/channel/${channelUrl}`;
2022-05-14 04:16:15 +00:00
this.$youtube
2022-05-18 21:51:33 +00:00
.getChannel(channelRequest)
2022-05-14 04:16:15 +00:00
.then((channel) => {
2022-05-18 23:36:27 +00:00
// console.log(channel);
state.loading = false;
2022-05-14 04:16:15 +00:00
state.banner =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelBanner?.image.sources[0].url;
2022-05-14 04:16:15 +00:00
state.avatar =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.avatarData.avatar?.image.sources[0].url;
2022-05-14 04:16:15 +00:00
state.title =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.title;
state.subscribe =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.subscribeButton.subscribeButtonContent.buttonText;
state.subscribeAlt =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.subscribeButton.subscribeButtonContent.accessibilityText;
state.descriptionPreview =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.descriptionPreview.description;
state.subscribers =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.metadata.subscriberCountText;
2022-05-18 21:51:33 +00:00
state.videosCount =
2022-05-14 04:16:15 +00:00
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.metadata.videosCountText;
2022-05-18 23:36:27 +00:00
const featuredSection =
channel.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents.find(
(i) => {
return !!i?.shelfRenderer?.content?.horizontalListRenderer
?.items[0].gridChannelRenderer;
}
);
state.featuredChannels =
featuredSection.shelfRenderer.content.horizontalListRenderer.items;
2022-05-19 17:52:08 +00:00
console.log(
channel.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer
.content.sectionListRenderer.contents[0].shelfRenderer.content
.verticalListRenderer.items[0].elementRenderer.newElement.type
.componentType.model
);
state.videoExample =
channel.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].shelfRenderer.content.verticalListRenderer.items[0].elementRenderer.newElement.type.componentType.model.videoWithContextModel.videoWithContextData.videoData;
2022-05-14 04:16:15 +00:00
})
.catch((err) => {
state.loading = false;
state.error = err;
console.error(err);
2022-05-14 04:16:15 +00:00
});
},
};