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

53 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-05-14 04:16:15 +00:00
export const state = () => ({
avatar: null,
banner: null,
title: null,
subscribe: null,
subscribeAlt: null,
descriptionPreview: null,
subscribers: null,
videos: null,
});
export const actions = {
fetchChannel({ state }, channelUrl) {
2022-05-14 05:10:38 +00:00
console.log(
"%c getChannel ",
"color: black; font-weight: bold; background: #f00; padding: .5rem .25rem; border-radius: .25rem;"
);
console.log(
`%c${channelUrl}`,
"color: black; font-weight: bold; background: #0f0; padding: .5rem .25rem; border-radius: .25rem;"
);
console.log(channelUrl.substring(channelUrl.lastIndexOf("/") + 1));
2022-05-14 05:10:38 +00:00
// substring removes /channel/ from the url if called from watch page, but keeps string intact if called from search page
2022-05-14 04:16:15 +00:00
this.$youtube
2022-05-14 05:10:38 +00:00
.getChannel(
`https://youtube.com/channel/${channelUrl.substring(
channelUrl.lastIndexOf("/") + 1
2022-05-14 05:10:38 +00:00
)}`
)
2022-05-14 04:16:15 +00:00
.then((channel) => {
// console.log(channel);
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;
state.videos =
channel.header.channelMobileHeaderRenderer.channelHeader.elementRenderer.newElement.type.componentType.model.channelHeaderModel.channelProfile.metadata.videosCountText;
})
.catch((err) => {
console.error(err);
2022-05-14 04:16:15 +00:00
});
},
};