add build_videos file
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
|||||||
|
import database
|
||||||
|
import youtube_short
|
||||||
|
import transcribe_video
|
||||||
|
import twitch_chat_vod
|
||||||
|
|
||||||
|
DB = None
|
||||||
|
|
||||||
|
def build_chat_video():
|
||||||
|
chats = DB.get_unuploaded_chats()
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
print("====================================================")
|
||||||
|
print(f"🚀 Transcribe: {title}")
|
||||||
|
print("====================================================")
|
||||||
|
|
||||||
|
twitch_chat_vod.combine_twitch_vod_and_chat(f"download/videos/{id}/{id}.mp4", "overlay")
|
||||||
|
|
||||||
|
|
||||||
|
def build_transcribe():
|
||||||
|
unuploadeds = DB.get_unuploaded()
|
||||||
|
|
||||||
|
for unuploaded in unuploadeds:
|
||||||
|
(
|
||||||
|
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,
|
||||||
|
) = unuploaded
|
||||||
|
|
||||||
|
if clip_is:
|
||||||
|
target_dir = f"download/clips"
|
||||||
|
else:
|
||||||
|
target_dir = f"download/videos"
|
||||||
|
|
||||||
|
print("====================================================")
|
||||||
|
print(f"🚀 Transcribe: {title}")
|
||||||
|
print("====================================================")
|
||||||
|
|
||||||
|
transcribe_video.transcribe_to_srt(f"{target_dir}/{id}/{id}.mp4")
|
||||||
|
|
||||||
|
|
||||||
|
def build_shorts():
|
||||||
|
shorts = DB.get_unuploaded_shorts()
|
||||||
|
|
||||||
|
top_txt = "TeamPGP Live on Twitch...\n Every Friday and Sunday @7:30 ET.\n twitch.tv/teampgp"
|
||||||
|
|
||||||
|
for short in shorts:
|
||||||
|
(
|
||||||
|
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,
|
||||||
|
) = short
|
||||||
|
|
||||||
|
target_dir = f"download/clips/{id}/{id}.mp4"
|
||||||
|
|
||||||
|
print("====================================================")
|
||||||
|
print(f"🚀 Processing: Clip to Youtube Short {title}")
|
||||||
|
print("====================================================")
|
||||||
|
|
||||||
|
youtube_short.fit_to_9_16_letterbox(target_dir, top_txt, f"Clipped By: {creator_name}.", True)
|
||||||
|
|
||||||
|
if __name__ =="__main__":
|
||||||
|
DB = database.Database()
|
||||||
|
build_shorts()
|
||||||
+1
-1
@@ -34,7 +34,7 @@ class Database:
|
|||||||
duration TEXT NOT NULL,
|
duration TEXT NOT NULL,
|
||||||
url TEXT NOT NULL,
|
url TEXT NOT NULL,
|
||||||
thumbnail_url TEXT NOT NULL,
|
thumbnail_url TEXT NOT NULL,
|
||||||
game_id INTEGER NOT NULL,
|
game_id TEXT NOT NULL,
|
||||||
game_name TEXT NOT NULL,
|
game_name TEXT NOT NULL,
|
||||||
stream_id TEXT NOT NULL,
|
stream_id TEXT NOT NULL,
|
||||||
creator_name TEXT NOT NULL,
|
creator_name TEXT NOT NULL,
|
||||||
|
|||||||
+12
-6
@@ -8,15 +8,16 @@ from whisper.utils import get_writer
|
|||||||
|
|
||||||
model = whisper.load_model("base")
|
model = whisper.load_model("base")
|
||||||
|
|
||||||
def extract_audio(video_path: str, audio_temp_path: str):
|
def extract_audio(video_path: str):
|
||||||
# Create a temporary path for a sanitized copy of the video
|
# Create a temporary path for a sanitized copy of the video
|
||||||
sanitized_video_path = video_path.replace(".mp4", "_clean.mp4")
|
sanitized_video_path = video_path.replace(".mp4", "_clean.mp4")
|
||||||
|
audio_temp_path = video_path.replace(".mp4", ".wav")
|
||||||
|
|
||||||
print("Sanitizing video metadata for MoviePy parser...")
|
print("Sanitizing video metadata for MoviePy parser...")
|
||||||
# -map_chapters -1 removes chapter layouts that break the parser.
|
# -map_chapters -1 removes chapter layouts that break the parser.
|
||||||
# -sn strips text/subtitle streams that crash MoviePy.
|
# -sn strips text/subtitle streams that crash MoviePy.
|
||||||
# -c copy copies video and audio instantly without quality loss.
|
# -c copy copies video and audio instantly without quality loss.
|
||||||
linux.run_command(f"ffmpeg -y -i {video_path} -map_chapters -1 -sn -c copy {sanitized_video_path}")
|
linux.run_command_ffmpeg(f"ffmpeg -y -i {video_path} -map_chapters -1 -sn -c copy {sanitized_video_path}")
|
||||||
|
|
||||||
print("Extracting uncompressed WAV audio...")
|
print("Extracting uncompressed WAV audio...")
|
||||||
try:
|
try:
|
||||||
@@ -34,15 +35,20 @@ def extract_audio(video_path: str, audio_temp_path: str):
|
|||||||
os.remove(sanitized_video_path)
|
os.remove(sanitized_video_path)
|
||||||
|
|
||||||
|
|
||||||
def transcribe_to_srt(audio_path: str, output_directory: str, output_filename: str):
|
def transcribe_to_srt(video_path: str):
|
||||||
|
|
||||||
|
extract_audio(video_path)
|
||||||
|
|
||||||
|
transcribe_path = video_path.replace(".mp4", ".str")
|
||||||
|
audio_path = video_path.replace(".mp4", ".wav")
|
||||||
print("Transcribing audio...")
|
print("Transcribing audio...")
|
||||||
result = model.transcribe(audio_path)
|
result = model.transcribe(audio_path)
|
||||||
|
|
||||||
print("Creating SRT file...")
|
print("Creating SRT file...")
|
||||||
srt_writer = get_writer("srt", output_directory)
|
srt_writer = get_writer("srt", transcribe_path)
|
||||||
srt_writer(result, output_filename, {})
|
srt_writer(result, transcribe_path, {})
|
||||||
|
|
||||||
print(f"SRT subtitle file saved in: {output_directory}")
|
print(f"SRT subtitle file saved in: {transcribe_path}")
|
||||||
if os.path.exists(audio_path):
|
if os.path.exists(audio_path):
|
||||||
os.remove(audio_path)
|
os.remove(audio_path)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user