diff --git a/types/scraping/Category.ts b/types/scraping/Category.ts new file mode 100644 index 0000000..769d5b0 --- /dev/null +++ b/types/scraping/Category.ts @@ -0,0 +1,11 @@ +export type Tag = string + +export interface Category { + name: string + displayName: string + viewers: number + tags: Tag[] + createdAt: Date + cursor: string + image: string +} \ No newline at end of file diff --git a/types/scraping/CategoryData.ts b/types/scraping/CategoryData.ts new file mode 100644 index 0000000..5962849 --- /dev/null +++ b/types/scraping/CategoryData.ts @@ -0,0 +1,25 @@ +import { Tag } from "./Category" +import { StreamData } from "./Streamer" + +export interface CategoryMinifiedStream { + title: string + viewers: number + preview: string + tags: Tag[] + cursor: string + streamer: { + name: string + pfp: string + colorHex: string + } + } + +export interface CategoryData { + name: string + cover: string + description: string + viewers: number + followers: number + tags: Tag[] + streams: CategoryMinifiedStream[] + } \ No newline at end of file diff --git a/types/scraping/Streamer.ts b/types/scraping/Streamer.ts index 968e18d..94b0e6a 100644 --- a/types/scraping/Streamer.ts +++ b/types/scraping/Streamer.ts @@ -11,6 +11,7 @@ export interface StreamData { startedAt: number viewers: number preview: string + cursor?: string } export interface StreamerData { @@ -21,7 +22,7 @@ export interface StreamerData { about: string socials?: Social[] pfp: string - stream: StreamData | null + stream?: StreamData | null isPartner: boolean colorHex: string id: number diff --git a/util/scraping/extractor/index.ts b/util/scraping/extractor/index.ts index 07df38a..df558c9 100644 --- a/util/scraping/extractor/index.ts +++ b/util/scraping/extractor/index.ts @@ -1,5 +1,7 @@ import { LooseObject } from "../../../types/looseTypes" import { StreamerData, StreamData, Social, Badge } from "../../../types/scraping/Streamer" +import { Category, Tag } from "../../../types/scraping/Category" +import { CategoryData, CategoryMinifiedStream } from "../../../types/scraping/CategoryData" const base64 = (data: String) => { return Buffer.from(data).toString('base64url') @@ -302,10 +304,10 @@ export class TwitchAPI { }) const data = await res.json() const categories = data[0].data.directoriesWithTags.edges - let formattedCategories = [] + let formattedCategories: Category[] = [] for (let category of categories) { - let tags = [] + let tags: Tag[] = [] for (let tag of category.node.tags) { tags.push(tag.tagName) } @@ -380,7 +382,7 @@ export class TwitchAPI { let streams = [] if(data[0].data.game.streams) streams = data[0].data.game.streams.edges - let formatedStreams = [] + let formatedStreams: CategoryMinifiedStream[] = [] for(let stream of streams) { let tags = [] @@ -403,12 +405,12 @@ export class TwitchAPI { } const rawGameData = data[1].data.game; - let tags = [] + let tags: Tag[] = [] for(let tag of rawGameData.tags) { tags.push(tag.tagName) } - const formatedGameData = { + const formatedGameData: CategoryData = { name: rawGameData.name, cover: `${process.env.URL}/proxy/img/${base64(rawGameData.avatarURL)}`, description: rawGameData.description,