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

68 lines
3.1 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-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-18 21:51:33 +00:00
const channelRequest = channelUrl.includes("/c/")
? `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;
}
);
console.log("CHANNEL INDEX");
console.log(featuredSection);
state.featuredChannels =
featuredSection.shelfRenderer.content.horizontalListRenderer.items;
console.log("ITEMS ITEMS");
console.log(state.featuredChannels);
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
});
},
};