I forgot what I chanagerd
This commit is contained in:
1 parent
24081e1576
commit
c4f5018833
20 files changed
+678
-77
No files matched your search
+41
-1
@@ -1,10 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
import csv
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import json
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
def write_csv(data, file_name):
|
||||
def get_chapters(json_path):
|
||||
"""Loads the JSON file and returns all chapters."""
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# The chapters are under video -> chapters
|
||||
video = data.get('video', {})
|
||||
chapters = video.get('chapters', [])
|
||||
|
||||
if not chapters:
|
||||
print("No chapters found.")
|
||||
return []
|
||||
|
||||
print(f"Found {len(chapters)} chapter(s) in video '{video.get('title')}':\n")
|
||||
|
||||
for i, chapter in enumerate(chapters, 1):
|
||||
start_sec = chapter.get('startMilliseconds', 0) / 1000
|
||||
length_sec = chapter.get('lengthMilliseconds', 0) / 1000
|
||||
|
||||
#print(f"{i}. {chapter.get('description', 'No Title')}")
|
||||
#print(f" - Type: {chapter.get('type')}")
|
||||
#print(f" - Start: {start_sec}s ({chapter.get('startMilliseconds')}ms)")
|
||||
#print(f" - Length: {length_sec}s ({chapter.get('lengthMilliseconds')}ms)")
|
||||
#print(f" - Game: {chapter.get('gameDisplayName')} (ID: {chapter.get('gameId')})")
|
||||
#print()
|
||||
|
||||
return chapters
|
||||
|
||||
def get_video_id_from_chat(json_path: str | Path) -> str | None:
|
||||
"""Gets the id inside video:{ } - from the chat json you download"""
|
||||
try:
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
return data.get("video", {}).get("id")
|
||||
except Exception as e:
|
||||
print(f"Could not read video.id from {json_path}: {e}")
|
||||
return None
|
||||
|
||||
def write_csv(data: list, file_name: str):
|
||||
# Open file with newline='' to prevent extra blank rows across platforms
|
||||
with open(file_name, "w", newline="", encoding="utf-8") as file:
|
||||
writer = csv.writer(file)
|
||||
|
||||
Reference in new issue
Block a user