0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-13 06:55:08 +00:00
VueTube/NUXT/store/channel/index.js

51 lines
2.4 KiB
JavaScript

const getDefaultState = () => {
return {
loading: null,
error: null,
avatar: null,
banner: null,
title: null,
subscribe: null,
subscribeAlt: null,
descriptionPreview: null,
subscribers: null,
videos: null,
};
};
export const state = getDefaultState();
export const actions = {
fetchChannel({ state }, channelUrl) {
Object.assign(state, getDefaultState());
state.loading = true;
this.$youtube
.getChannel(
`https://youtube.com/channel/${channelUrl.substring(
channelUrl.lastIndexOf("/") + 1
)}`
)
.then((channel) => {
state.loading = false;
state.banner =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelBanner?.image.sources[0].url;
state.avatar =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.avatarData.avatar?.image.sources[0].url;
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;
state.videos =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.metadata.videosCountText;
})
.catch((err) => {
state.loading = false;
state.error = err;
console.error(err);
});
},
};