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