From 20acb4bc9fc7db840a3858a566edf36e6a57a08b Mon Sep 17 00:00:00 2001 From: SumGuyV5 Date: Tue, 1 Sep 2026 04:30:07 +0000 Subject: [PATCH] add new files import_vod and move_vod for use on old vods before this program was created --- import_vod.py | 115 +++++++++++++++++++++++++++++++++++++++++++ main.py | 4 ++ move_vod.py | 57 +++++++++++++++++++++ twitch_video_info.py | 14 ++++++ 4 files changed, 190 insertions(+) create mode 100644 import_vod.py create mode 100644 move_vod.py diff --git a/import_vod.py b/import_vod.py new file mode 100644 index 0000000..a65768c --- /dev/null +++ b/import_vod.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +import os +import json +import asyncio +from pathlib import Path + +import database +import twitch_video_info + +DB = None +def format_to_hms(total_seconds): + # Calculate hours, minutes, and seconds + hours, remainder = divmod(int(total_seconds), 3600) + minutes, seconds = divmod(remainder, 60) + + # Return formatted string: e.g., 4h27m12s + return f"{hours}h{minutes}m{seconds}s" + +def read_json(file_path: str): + try: + with open(file_path, "r", encoding="utf-8") as file: + data = json.load(file) + + # Extracting streamer info + streamer_name = data.get("streamer", {}).get("name") + + # Extracting video core details + video_data = data.get("video", {}) + video_title = video_data.get("title") + video_id = video_data.get("id") + video_created_at = video_data.get("created_at") + video_length_seconds = video_data.get("length") + video_views = video_data.get("viewCount") + video_game = video_data.get("game") + + # Printing variables to verify + print(f"Streamer: {streamer_name}") + print(f"Title: {video_title}") + print(f"Video ID: {video_id}") + print(f"Created At: {video_created_at}") + print(f"Duration: {video_length_seconds} seconds") + print(f"Views: {video_views}") + print(f"Game: {video_game}") + + video_length = format_to_hms(video_length_seconds) + + game_id = asyncio.run(twitch_video_info.get_game_id_by_name(video_game)) + + DB.insert_video_record( + video_id, + video_title, + video_created_at, + int(video_views), + video_length, + "", + "", + game_id, + video_game, + "", + "", + False + ) + + id = video_id + + source = Path(f"download/saveold/{id}") + destination = Path(f"download/videos/{id}") + + if source.exists() and source.is_dir(): + source.rename(destination) + print("====================================================") + print(f"šŸš€ VOD to moved: {video_title}") + print("====================================================") + + except FileNotFoundError: + print(f"Error: The file at {file_path} was not found.") + except json.JSONDecodeError: + print( + "Error: Failed to parse JSON. Make sure trailing cut-off text is removed." + ) + +def main(): + global DB + DB = database.Database() + + + + # Set the path of the directory you want to walk through + # Use "." for the current folder, or a full path like "C:/Users/Name/Documents" + root_directory = "./download/saveold" + + # os.walk yields a 3-item tuple for every single folder it finds + for current_folder, subfolders, files in os.walk(root_directory): + + print(f"\nšŸ“‚ Current Folder: {current_folder}") + + # List all subfolders inside the current folder + if subfolders: + print(f" šŸ“ Subfolders found: {', '.join(subfolders)}") + + # List all files inside the current folder + for file_name in files: + # Construct the full absolute or relative path to the file + full_file_path = os.path.join(current_folder, file_name) + print(f" šŸ“„ File: {file_name} ({full_file_path})") + + if file_name.endswith(".json"): + read_json(full_file_path) + + + + + +if __name__ == "__main__": + main() diff --git a/main.py b/main.py index b30d4d4..32bc6f2 100644 --- a/main.py +++ b/main.py @@ -18,3 +18,7 @@ if __name__ == "__main__": #Build build_videos.main() + + print("====================================================") + print(f"āœ… Done.") + print("====================================================") \ No newline at end of file diff --git a/move_vod.py b/move_vod.py new file mode 100644 index 0000000..f4cb0a5 --- /dev/null +++ b/move_vod.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +import database +from pathlib import Path + +DB = None + +def remove_vods(): + chats = DB.get_vods() + #chats = DB.get_clips() + + for chat in chats: + ( + id, + title, + created_at, + view_count, + duration, + url, + thumbnail_url, + game_id, + game_name, + stream_id, + creator_name, + clip_is, + downloaded, + uploaded_yt, + uploaded_yt_chats, + uploaded_yt_shorts, + ) = chat + + #shutil.rmtree(f"", ignore_errors=True) + + if clip_is: + source = Path(f"../saveoldold/clips/{id}") + destination = Path(f"../savedup/clips/{id}") + else: + source = Path(f"../saveoldold/{id}") + destination = Path(f"../savedup/{id}") + + if source.exists() and source.is_dir(): + source.rename(destination) + print("====================================================") + print(f"šŸš€ VOD to remove: {title}") + print("====================================================") + + print("====================================================") + print(f"āœ… Processing: VOD removal Done.") + print("====================================================") + +def main(): + global DB + DB = database.Database() + + remove_vods() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/twitch_video_info.py b/twitch_video_info.py index b0a73f2..1964973 100755 --- a/twitch_video_info.py +++ b/twitch_video_info.py @@ -14,6 +14,20 @@ GAME_CACHE = {} # Local cache dictionary to store game_id -> game_name mapping CHANNEL_NAME = "teampgp" +async def get_game_id_by_name(game_name: str) -> str: + if SECRETS is None: + await get_twitch() + # Query the 'get_games' endpoint using the names parameter + # The API expects a list, even for a single game name + async for game in TWITCH.get_games(names=[game_name]): + print(f"Game Name: {game.name}") + print(f"Game ID: {game.id}") + print(f"IGDB ID: {game.igdb_id}") + return game.id + + print(f"No game found with the exact name: '{game_name}'") + return None + async def get_twitch(): global SECRETS, TWITCH, USER if SECRETS is None: