mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-03 03:10:05 -05:00
Add more types to extractor
This commit is contained in:
parent
3cf1536236
commit
65a6c62b38
4 changed files with 45 additions and 6 deletions
11
types/scraping/Category.ts
Normal file
11
types/scraping/Category.ts
Normal file
|
@ -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
|
||||||
|
}
|
25
types/scraping/CategoryData.ts
Normal file
25
types/scraping/CategoryData.ts
Normal file
|
@ -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[]
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ export interface StreamData {
|
||||||
startedAt: number
|
startedAt: number
|
||||||
viewers: number
|
viewers: number
|
||||||
preview: string
|
preview: string
|
||||||
|
cursor?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StreamerData {
|
export interface StreamerData {
|
||||||
|
@ -21,7 +22,7 @@ export interface StreamerData {
|
||||||
about: string
|
about: string
|
||||||
socials?: Social[]
|
socials?: Social[]
|
||||||
pfp: string
|
pfp: string
|
||||||
stream: StreamData | null
|
stream?: StreamData | null
|
||||||
isPartner: boolean
|
isPartner: boolean
|
||||||
colorHex: string
|
colorHex: string
|
||||||
id: number
|
id: number
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { LooseObject } from "../../../types/looseTypes"
|
import { LooseObject } from "../../../types/looseTypes"
|
||||||
import { StreamerData, StreamData, Social, Badge } from "../../../types/scraping/Streamer"
|
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) => {
|
const base64 = (data: String) => {
|
||||||
return Buffer.from(data).toString('base64url')
|
return Buffer.from(data).toString('base64url')
|
||||||
|
@ -302,10 +304,10 @@ export class TwitchAPI {
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
const categories = data[0].data.directoriesWithTags.edges
|
const categories = data[0].data.directoriesWithTags.edges
|
||||||
let formattedCategories = []
|
let formattedCategories: Category[] = []
|
||||||
|
|
||||||
for (let category of categories) {
|
for (let category of categories) {
|
||||||
let tags = []
|
let tags: Tag[] = []
|
||||||
for (let tag of category.node.tags) {
|
for (let tag of category.node.tags) {
|
||||||
tags.push(tag.tagName)
|
tags.push(tag.tagName)
|
||||||
}
|
}
|
||||||
|
@ -380,7 +382,7 @@ export class TwitchAPI {
|
||||||
let streams = []
|
let streams = []
|
||||||
if(data[0].data.game.streams)
|
if(data[0].data.game.streams)
|
||||||
streams = data[0].data.game.streams.edges
|
streams = data[0].data.game.streams.edges
|
||||||
let formatedStreams = []
|
let formatedStreams: CategoryMinifiedStream[] = []
|
||||||
|
|
||||||
for(let stream of streams) {
|
for(let stream of streams) {
|
||||||
let tags = []
|
let tags = []
|
||||||
|
@ -403,12 +405,12 @@ export class TwitchAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawGameData = data[1].data.game;
|
const rawGameData = data[1].data.game;
|
||||||
let tags = []
|
let tags: Tag[] = []
|
||||||
for(let tag of rawGameData.tags) {
|
for(let tag of rawGameData.tags) {
|
||||||
tags.push(tag.tagName)
|
tags.push(tag.tagName)
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatedGameData = {
|
const formatedGameData: CategoryData = {
|
||||||
name: rawGameData.name,
|
name: rawGameData.name,
|
||||||
cover: `${process.env.URL}/proxy/img/${base64(rawGameData.avatarURL)}`,
|
cover: `${process.env.URL}/proxy/img/${base64(rawGameData.avatarURL)}`,
|
||||||
description: rawGameData.description,
|
description: rawGameData.description,
|
||||||
|
|
Loading…
Reference in a new issue