|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
from moviepy.editor import (
|
|
|
|
from moviepy.editor import (
|
|
|
|
VideoFileClip,
|
|
|
|
VideoFileClip,
|
|
|
|
AudioFileClip,
|
|
|
|
AudioFileClip,
|
|
|
@ -7,25 +8,21 @@ from moviepy.editor import (
|
|
|
|
CompositeAudioClip,
|
|
|
|
CompositeAudioClip,
|
|
|
|
CompositeVideoClip,
|
|
|
|
CompositeVideoClip,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import reddit.subreddit
|
|
|
|
import reddit.subreddit
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
from utils.console import print_step
|
|
|
|
from utils.console import print_step, print_substep
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from rich.console import Console
|
|
|
|
|
|
|
|
console = Console()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
W, H = 1080, 1920
|
|
|
|
W, H = 1080, 1920
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_final_video(number_of_clips):
|
|
|
|
def make_final_video(number_of_clips):
|
|
|
|
|
|
|
|
|
|
|
|
# Calls opacity from the .env
|
|
|
|
# Calls opacity from the .env
|
|
|
|
load_dotenv()
|
|
|
|
load_dotenv()
|
|
|
|
opacity = os.getenv('OPACITY')
|
|
|
|
opacity = os.getenv("OPACITY")
|
|
|
|
|
|
|
|
|
|
|
|
print_step("Creating the final video...")
|
|
|
|
print_step("Creating the final video...")
|
|
|
|
|
|
|
|
|
|
|
|
VideoFileClip.reW = lambda clip: clip.resize(width=W)
|
|
|
|
VideoFileClip.reW = lambda clip: clip.resize(width=W)
|
|
|
@ -42,20 +39,21 @@ def make_final_video(number_of_clips):
|
|
|
|
audio_clips = []
|
|
|
|
audio_clips = []
|
|
|
|
for i in range(0, number_of_clips):
|
|
|
|
for i in range(0, number_of_clips):
|
|
|
|
audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3"))
|
|
|
|
audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3"))
|
|
|
|
audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3"))
|
|
|
|
audio_clips.insert(0, AudioFileClip("assets/mp3/title.mp3"))
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3"))
|
|
|
|
audio_clips.insert(1, AudioFileClip("assets/mp3/posttext.mp3"))
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
OSError()
|
|
|
|
OSError()
|
|
|
|
audio_concat = concatenate_audioclips(audio_clips)
|
|
|
|
audio_concat = concatenate_audioclips(audio_clips)
|
|
|
|
audio_composite = CompositeAudioClip([audio_concat])
|
|
|
|
audio_composite = CompositeAudioClip([audio_concat])
|
|
|
|
|
|
|
|
|
|
|
|
#Get sum of all clip lengths
|
|
|
|
#Get sum of all clip lengths
|
|
|
|
total_length = sum([clip.duration for clip in audio_clips])
|
|
|
|
total_length = sum([clip.duration for clip in audio_clips])
|
|
|
|
#round total_length to an integer
|
|
|
|
#round total_length to an integer
|
|
|
|
int_total_length=round(total_length)
|
|
|
|
int_total_length=round(total_length)
|
|
|
|
#Output Length
|
|
|
|
#Output Length
|
|
|
|
console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long")
|
|
|
|
console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Gather all images
|
|
|
|
# Gather all images
|
|
|
|
image_clips = []
|
|
|
|
image_clips = []
|
|
|
@ -67,30 +65,38 @@ def make_final_video(number_of_clips):
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if os.path.exists(f"assets/mp3/posttext.mp3"):
|
|
|
|
if os.path.exists("assets/mp3/posttext.mp3"):
|
|
|
|
image_clips.insert(
|
|
|
|
image_clips.insert(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
ImageClip(f"assets/png/title.png")
|
|
|
|
ImageClip("assets/png/title.png")
|
|
|
|
.set_duration(audio_clips[0].duration + audio_clips[1].duration)
|
|
|
|
.set_duration(audio_clips[0].duration + audio_clips[1].duration)
|
|
|
|
.set_position("center")
|
|
|
|
.set_position("center")
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
image_clips.insert(
|
|
|
|
image_clips.insert(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
ImageClip(f"assets/png/title.png")
|
|
|
|
ImageClip("assets/png/title.png")
|
|
|
|
.set_duration(audio_clips[0].duration)
|
|
|
|
.set_duration(audio_clips[0].duration)
|
|
|
|
.set_position("center")
|
|
|
|
.set_position("center")
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.resize(width=W - 100)
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
.set_opacity(float(opacity)),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
image_concat = concatenate_videoclips(image_clips).set_position(
|
|
|
|
image_concat = concatenate_videoclips(image_clips).set_position(
|
|
|
|
("center", "center")
|
|
|
|
("center", "center")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
image_concat.audio = audio_composite
|
|
|
|
image_concat.audio = audio_composite
|
|
|
|
final = CompositeVideoClip([background_clip, image_concat])
|
|
|
|
final = CompositeVideoClip([background_clip, image_concat])
|
|
|
|
filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4")))
|
|
|
|
final_video_path = "assets/"
|
|
|
|
final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k")
|
|
|
|
if os.getenv("FINAL_VIDEO_PATH"):
|
|
|
|
|
|
|
|
final_video_path = os.getenv("FINAL_VIDEO_PATH")
|
|
|
|
|
|
|
|
filename = (re.sub('[?\"%*:|<>]', '', (final_video_path + reddit.subreddit.submission.title + ".mp4")))
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k")
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
print_substep("Something's wrong with the path you inserted, the video will be saved in the default path (assets/)", style="bold red")
|
|
|
|
|
|
|
|
filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4")))
|
|
|
|
|
|
|
|
final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k")
|
|
|
|
for i in range(0, number_of_clips):
|
|
|
|
for i in range(0, number_of_clips):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|