add new files import_vod and move_vod for use on old vods before this program was created
This commit is contained in:
1 parent
7f1f1e7b4f
commit
20acb4bc9f
4 files changed
+190
No files matched your search
+115
@@ -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()
|
||||
@@ -18,3 +18,7 @@ if __name__ == "__main__":
|
||||
|
||||
#Build
|
||||
build_videos.main()
|
||||
|
||||
print("====================================================")
|
||||
print(f"✅ Done.")
|
||||
print("====================================================")
|
||||
+57
@@ -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()
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user