Update Database to use new table fromat and twitch api

This commit is contained in:
2026-07-23 15:32:40 +00:00
parent 81e76b25d0
commit c8d12469e3
2 changed files with 100 additions and 114 deletions
+15 -9
View File
@@ -1,6 +1,7 @@
import asyncio
import json
import requests
import database
from twitchAPI.twitch import Twitch
from twitchAPI.helper import first
# Import the explicit VideoType Enum to prevent the AttributeError
@@ -86,27 +87,26 @@ async def get_streamer_vods():
print(f"Starting VOD extraction for {USER.display_name}...")
vod_generator = TWITCH.get_videos(user_id=USER.id, first=100, video_type=VideoType.ALL)
all_vods = []
async for v in vod_generator:
# FIXED: Resolving game category using the automatic stream markers
game_id, game_name = await get_vod_game_name(v.id)
#print(f"{v}")
vod_data = {
"id": v.id,
"title": v.title,
"created_at": str(v.published_at),
"view_count": v.view_count,
"view_count": int(v.view_count),
"duration": v.duration,
"url": v.url,
"thumbnail_url": v.thumbnail_url,
"game_id": game_id,
"game_id": int(game_id),
"game_name": game_name,
"stream_id": v.stream_id,
"creator_name": CHANNEL_NAME
"stream_id": str(v.stream_id) if v.stream_id else "0",
"creator_name": CHANNEL_NAME,
"clip_is": False,
}
all_vods.append(vod_data)
print(f"Collected VOD: {v.title} | Category: {game_name} ({v.duration})")
@@ -131,14 +131,15 @@ async def get_streamer_clips():
"id": c.id,
"title": c.title,
"created_at": str(c.created_at),
"view_count": c.view_count,
"view_count": int(c.view_count),
"duration": c.duration,
"url": c.url,
"thumbnail_url": c.thumbnail_url,
"game_id": c.game_id,
"game_id": int(c.game_id),
"game_name": game_name,
"stream_id": "0",
"creator_name": c.creator_name,
"clip_is": True,
}
all_clips.append(clip_data)
print(f"Collected clip: {c.title} | Category: {game_name} ({c.view_count} views)")
@@ -155,8 +156,13 @@ async def main():
#if clips_list:
# print(f"Top clip: '{clips_list[0]['title']}' (Game: {clips_list[0]['game_name']})")
db = database.Database()
# 2. Pull VODs (without categories)
vods_list = await get_streamer_vods()
for v in vods_list:
db.insert_video_record(v['id'], v['title'], v['created_at'], v['view_count'], v['duration'], v['url'], v['thumbnail_url'],
v['game_id'], v['game_name'], v['stream_id'], v['creator_name'], v['clip_is'])
#print(f"\nSuccessfully received a list of {len(vods_list)} VODs in main().")
if vods_list:
print(f"Recent VOD: '{vods_list[0]['title']}'")