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;"
|
|
|
|
);
|
2022-05-14 18:23:45 +00:00
|
|
|
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(
|
2022-05-14 18:23:45 +00:00
|
|
|
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 =
|
2022-05-14 18:23:45 +00:00
|
|
|
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 =
|
2022-05-14 18:23:45 +00:00
|
|
|
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) => {
|
2022-05-14 18:23:45 +00:00
|
|
|
console.error(err);
|
2022-05-14 04:16:15 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|