123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import { ref } from "vue";
- import Toast from "toasters";
- import { useWebsocketsStore } from "@/stores/websockets";
- // type YoutubeChannel = {
- // _id: string;
- // channelId: string;
- // title: string;
- // customUrl?: string;
- // rawData: {
- // kind: string;
- // etag: string;
- // id: string;
- // snippet: {
- // title: string;
- // description: string;
- // customUrl?: string;
- // publishedAt: string;
- // thumbnails: {
- // default: {
- // url: string;
- // width: number;
- // height: number;
- // };
- // medium: {
- // url: string;
- // width: number;
- // height: number;
- // };
- // high: {
- // url: string;
- // width: number;
- // height: number;
- // };
- // };
- // defaultLanguage?: string;
- // localized: {
- // title: string;
- // description: string;
- // };
- // };
- // contentDetails: {
- // relatedPlaylists: {
- // likes: string;
- // uploads: string;
- // };
- // };
- // statistics: {
- // viewCount: string;
- // subscriberCount: string;
- // hiddenSubscriberCount: boolean;
- // videoCount: string;
- // };
- // topicDetails: {
- // topicIds: string[];
- // topicCategories: string[];
- // };
- // status: {
- // privacyStatus: string;
- // isLinked: boolean;
- // longUploadsStatus: string;
- // madeForKids?: boolean;
- // };
- // brandingSettings: {
- // channel: {
- // title: string;
- // keywords?: string;
- // description?: string;
- // unsubscribedTrailer?: string;
- // defaultLanguage?: string;
- // };
- // image?: {
- // bannerExternalUrl: string;
- // };
- // };
- // };
- // documentVersion: number;
- // createdAt: Date;
- // updatedAt: Date;
- // };
- const youtubeChannelIDRegex = /(?<youtubeChannelID>UC[A-Za-z0-9-_]+)/;
- export const useYoutubeChannel = () => {
- const youtubeChannelURLOrID = ref("");
- const { socket } = useWebsocketsStore();
- const getYoutubeChannel = async () => {
- const youtubeChannelURLOrIDTrimmed = youtubeChannelURLOrID.value.trim();
- if (youtubeChannelURLOrIDTrimmed.length === 0)
- return new Toast(
- "No YouTube channel ID found in the supplied value."
- );
- const youtubeChannelIDRegexResult = youtubeChannelIDRegex.exec(
- youtubeChannelURLOrIDTrimmed
- );
- if (!youtubeChannelIDRegexResult)
- return new Toast(
- "No YouTube channel ID found in the supplied value."
- );
- return new Promise((resolve, reject) => {
- socket.dispatch(
- "youtube.getChannel",
- youtubeChannelIDRegexResult.groups.youtubeChannelID,
- res => {
- if (res.status === "success") {
- const { data } = res;
- resolve(data);
- youtubeChannelURLOrID.value = "";
- } else if (res.status === "error") {
- new Toast(res.message);
- reject();
- }
- }
- );
- });
- };
- const getYoutubeChannelVideos = async channelId =>
- new Promise((resolve, reject) => {
- socket.dispatch("youtube.getChannelVideos", channelId, res => {
- if (res.status === "success") {
- const { data } = res;
- resolve(data);
- } else if (res.status === "error") {
- new Toast(res.message);
- reject();
- }
- });
- });
- return {
- youtubeChannelURLOrID,
- getYoutubeChannel,
- getYoutubeChannelVideos
- };
- };
|