and reformatted project with the black formatter
pull/418/head
Jason 2 years ago
parent 9ba4500c27
commit dbf68477a6

@ -11,19 +11,20 @@ from video_creation.final_video import make_final_video
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.voices import save_text_to_mp3 from video_creation.voices import save_text_to_mp3
banner = ''' banner = """
''' """
print(banner) print(banner)
load_dotenv() load_dotenv()
# base code by elebumm # base code by elebumm
print_markdown( print_markdown(
"### Thanks for using this tool! 😊 Feel free to contribute to this project on GitHub! (JasonLovesDoggo/RedditVideoMakerBot). If you have any questions, feel free to reach out to me on Twitter @JasonLovesDoggo or submit a GitHub issue.") "### Thanks for using this tool! 😊 Feel free to contribute to this project on GitHub! (JasonLovesDoggo/RedditVideoMakerBot). If you have any questions, feel free to reach out to me on Twitter @JasonLovesDoggo or submit a GitHub issue."
)
time.sleep(2) time.sleep(2)
@ -47,15 +48,16 @@ def run_many(times):
for x in range(times): for x in range(times):
x = x + 1 x = x + 1
print_step( print_step(
f'on the {x}{("st" if x == 1 else ("nd" if x == 2 else ("rd" if x == 3 else "th")))} iteration of {times}') # correct 1st 2nd 3rd 4th 5th.... f'on the {x}{("st" if x == 1 else ("nd" if x == 2 else ("rd" if x == 3 else "th")))} iteration of {times}'
) # correct 1st 2nd 3rd 4th 5th....
main() main()
Popen('cls' if name == 'nt' else 'clear', shell=True).wait() Popen("cls" if name == "nt" else "clear", shell=True).wait()
if __name__ == '__main__': if __name__ == "__main__":
try: try:
if getenv('TIMES_TO_RUN'): if getenv("TIMES_TO_RUN"):
run_many(int(getenv('TIMES_TO_RUN'))) run_many(int(getenv("TIMES_TO_RUN")))
else: else:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:

@ -6,11 +6,11 @@ import praw
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.videos import check_done from utils.videos import check_done
TEXT_WHITELIST = set('abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890') TEXT_WHITELIST = set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890")
def textify(text): def textify(text):
return ''.join(filter(TEXT_WHITELIST.__contains__, text)) return "".join(filter(TEXT_WHITELIST.__contains__, text))
def get_subreddit_threads(): def get_subreddit_threads():
@ -22,29 +22,40 @@ def get_subreddit_threads():
content = {} content = {}
if getenv("REDDIT_2FA").casefold() == "yes": if getenv("REDDIT_2FA").casefold() == "yes":
print("\nEnter your two-factor authentication code from your authenticator app.\n") print(
"\nEnter your two-factor authentication code from your authenticator app.\n"
)
code = input("> ") code = input("> ")
print() print()
pw = getenv("REDDIT_PASSWORD") pw = getenv("REDDIT_PASSWORD")
passkey = f"{pw}:{code}" passkey = f"{pw}:{code}"
else: else:
passkey = getenv("REDDIT_PASSWORD") passkey = getenv("REDDIT_PASSWORD")
reddit = praw.Reddit(client_id=getenv("REDDIT_CLIENT_ID"), client_secret=getenv("REDDIT_CLIENT_SECRET"), reddit = praw.Reddit(
user_agent="Accessing Reddit threads", username=getenv("REDDIT_USERNAME"), client_id=getenv("REDDIT_CLIENT_ID"),
passkey=passkey, check_for_async=False,) client_secret=getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing Reddit threads",
username=getenv("REDDIT_USERNAME"),
passkey=passkey,
check_for_async=False,
)
""" """
Ask user for subreddit input Ask user for subreddit input
""" """
if not getenv("SUBREDDIT"): if not getenv("SUBREDDIT"):
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
input("What subreddit would you like to pull from? ")) # if the env isnt set, ask user input("What subreddit would you like to pull from? ")
) # if the env isnt set, ask user
else: else:
print_substep(f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config") print_substep(
f"Using subreddit: r/{getenv('SUBREDDIT')} from environment variable config"
)
subreddit = reddit.subreddit( subreddit = reddit.subreddit(
getenv("SUBREDDIT")) # Allows you to specify in .env. Done for automation purposes. getenv("SUBREDDIT")
) # Allows you to specify in .env. Done for automation purposes.
if getenv('POST_ID'): if getenv("POST_ID"):
submission = reddit.submission(id=getenv('POST_ID')) submission = reddit.submission(id=getenv("POST_ID"))
else: else:
threads = subreddit.hot(limit=25) threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)] submission = list(threads)[random.randrange(0, 25)]
@ -55,11 +66,15 @@ def get_subreddit_threads():
ratio = submission.upvote_ratio * 100 ratio = submission.upvote_ratio * 100
num_comments = submission.num_comments num_comments = submission.num_comments
print_substep(f"Video will be: {submission.title} :thumbsup:", style='bold green') print_substep(f"Video will be: {submission.title} :thumbsup:", style="bold green")
print_substep(f"Thread has " + str(upvotes) + " upvotes", style='bold blue') print_substep(f"Thread has " + str(upvotes) + " upvotes", style="bold blue")
print_substep(f"Thread has a upvote ratio of " + str(ratio) + "%", style='bold blue') print_substep(
print_substep(f"Thread has " + str(num_comments) + " comments", style='bold blue') f"Thread has a upvote ratio of " + str(ratio) + "%", style="bold blue"
environ["VIDEO_TITLE"] = str(textify(submission.title)) # todo use global instend of env vars )
print_substep(f"Thread has " + str(num_comments) + " comments", style="bold blue")
environ["VIDEO_TITLE"] = str(
textify(submission.title)
) # todo use global instend of env vars
environ["VIDEO_ID"] = str(textify(submission.id)) environ["VIDEO_ID"] = str(textify(submission.id))
try: try:
@ -71,8 +86,12 @@ def get_subreddit_threads():
if not top_level_comment.stickied: if not top_level_comment.stickied:
if len(top_level_comment.body) <= int(environ["MAX_COMMENT_LENGTH"]): if len(top_level_comment.body) <= int(environ["MAX_COMMENT_LENGTH"]):
content["comments"].append( content["comments"].append(
{"comment_body": top_level_comment.body, "comment_url": top_level_comment.permalink, {
"comment_id": top_level_comment.id, }) "comment_body": top_level_comment.body,
"comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id,
}
)
except AttributeError as e: except AttributeError as e:
pass pass
print_substep("Received subreddit threads Successfully.", style="bold green") print_substep("Received subreddit threads Successfully.", style="bold green")

@ -3,20 +3,22 @@ from os.path import exists
def cleanup() -> int: def cleanup() -> int:
if exists('./assets/temp'): if exists("./assets/temp"):
count = 0 count = 0
files = [f for f in os.listdir('.') if f.endswith('.mp4') and 'temp' in f.lower()] files = [
f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower()
]
count += len(files) count += len(files)
for f in files: for f in files:
os.remove(f) os.remove(f)
try: try:
for file in os.listdir('./assets/temp/mp4'): for file in os.listdir("./assets/temp/mp4"):
count += 1 count += 1
os.remove('./assets/temp/mp4/' + file) os.remove("./assets/temp/mp4/" + file)
except FileNotFoundError: except FileNotFoundError:
pass pass
for file in os.listdir('./assets/temp/mp3'): for file in os.listdir("./assets/temp/mp3"):
count += 1 count += 1
os.remove('./assets/temp/mp3/' + file) os.remove("./assets/temp/mp3/" + file)
return count return count
return 0 return 0

@ -4,17 +4,20 @@ from os import getenv
from utils.console import print_step from utils.console import print_step
def check_done(redditobj): # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack def check_done(
redditobj,
): # don't set this to be run anyplace that isn't subreddit.py bc of inspect stack
"""params: """params:
reddit_object: The Reddit Object you received in askreddit.py""" reddit_object: The Reddit Object you received in askreddit.py"""
with open('./video_creation/data/videos.json', 'r') as done_vids_raw: with open("./video_creation/data/videos.json", "r") as done_vids_raw:
done_videos = json.load(done_vids_raw) done_videos = json.load(done_vids_raw)
for video in done_videos: for video in done_videos:
if video['id'] == str(redditobj): if video["id"] == str(redditobj):
if getenv('POST_ID'): if getenv("POST_ID"):
print_step( print_step(
'You already have done this video but since it was declared specifically in the .env file the program will continue') "You already have done this video but since it was declared specifically in the .env file the program will continue"
)
return redditobj return redditobj
print_step('Getting new post as the current one has already been done') print_step("Getting new post as the current one has already been done")
return None return None
return redditobj return redditobj

@ -10,7 +10,7 @@ def sanitize_text(text):
""" """
# remove any urls from the text # remove any urls from the text
regex_urls = r'((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*' regex_urls = r"((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*"
result = re.sub(regex_urls, " ", text) result = re.sub(regex_urls, " ", text)

@ -5,55 +5,55 @@ import os
import random import random
import requests import requests
from moviepy.editor import AudioFileClip, concatenate_audioclips, CompositeAudioClip from moviepy.editor import AudioFileClip, concatenate_audioclips, CompositeAudioClip
#from profanity_filter import ProfanityFilter
#pf = ProfanityFilter() # from profanity_filter import ProfanityFilter
# pf = ProfanityFilter()
# Code by @JasonLovesDoggo # Code by @JasonLovesDoggo
# https://twitter.com/scanlime/status/1512598559769702406 # https://twitter.com/scanlime/status/1512598559769702406
nonhuman = [ # DISNEY VOICES nonhuman = [ # DISNEY VOICES
'en_us_ghostface', # Ghost Face "en_us_ghostface", # Ghost Face
'en_us_chewbacca', # Chewbacca "en_us_chewbacca", # Chewbacca
'en_us_c3po', # C3PO "en_us_c3po", # C3PO
'en_us_stitch', # Stitch "en_us_stitch", # Stitch
'en_us_stormtrooper', # Stormtrooper "en_us_stormtrooper", # Stormtrooper
'en_us_rocket', # Rocket "en_us_rocket", # Rocket
# ENGLISH VOICES # ENGLISH VOICES
] ]
human = ['en_au_001', # English AU - Female human = [
'en_au_002', # English AU - Male "en_au_001", # English AU - Female
'en_uk_001', # English UK - Male 1 "en_au_002", # English AU - Male
'en_uk_003', # English UK - Male 2 "en_uk_001", # English UK - Male 1
'en_us_001', # English US - Female (Int. 1) "en_uk_003", # English UK - Male 2
'en_us_002', # English US - Female (Int. 2) "en_us_001", # English US - Female (Int. 1)
'en_us_006', # English US - Male 1 "en_us_002", # English US - Female (Int. 2)
'en_us_007', # English US - Male 2 "en_us_006", # English US - Male 1
'en_us_009', # English US - Male 3 "en_us_007", # English US - Male 2
'en_us_010'] "en_us_009", # English US - Male 3
"en_us_010",
]
voices = nonhuman + human voices = nonhuman + human
noneng = [ noneng = [
'fr_001', # French - Male 1 "fr_001", # French - Male 1
'fr_002', # French - Male 2 "fr_002", # French - Male 2
'de_001', # German - Female "de_001", # German - Female
'de_002', # German - Male "de_002", # German - Male
'es_002', # Spanish - Male "es_002", # Spanish - Male
# AMERICA VOICES # AMERICA VOICES
'es_mx_002', # Spanish MX - Male "es_mx_002", # Spanish MX - Male
'br_001', # Portuguese BR - Female 1 "br_001", # Portuguese BR - Female 1
'br_003', # Portuguese BR - Female 2 "br_003", # Portuguese BR - Female 2
'br_004', # Portuguese BR - Female 3 "br_004", # Portuguese BR - Female 3
'br_005', # Portuguese BR - Male "br_005", # Portuguese BR - Male
# ASIA VOICES # ASIA VOICES
'id_001', # Indonesian - Female "id_001", # Indonesian - Female
'jp_001', # Japanese - Female 1 "jp_001", # Japanese - Female 1
'jp_003', # Japanese - Female 2 "jp_003", # Japanese - Female 2
'jp_005', # Japanese - Female 3 "jp_005", # Japanese - Female 3
'jp_006', # Japanese - Male "jp_006", # Japanese - Male
'kr_002', # Korean - Male 1 "kr_002", # Korean - Male 1
'kr_003', # Korean - Female "kr_003", # Korean - Female
'kr_004', # Korean - Male 2 "kr_004", # Korean - Male 2
] ]
@ -63,22 +63,36 @@ noneng = [
class TTTTSWrapper: # TikTok Text-to-Speech Wrapper class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
def __init__(self): def __init__(self):
self.URI_BASE = 'https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=' self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker="
def tts(self, req_text: str = "TikTok Text To Speech", filename: str = 'title.mp3', random_speaker: bool = False, censer=False): def tts(
self,
req_text: str = "TikTok Text To Speech",
filename: str = "title.mp3",
random_speaker: bool = False,
censer=False,
):
req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and") req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and")
if censer: if censer:
#req_text = pf.censor(req_text) # req_text = pf.censor(req_text)
pass pass
voice = self.randomvoice() if random_speaker else (os.getenv('VOICE') or random.choice(human)) voice = (
self.randomvoice()
if random_speaker
else (os.getenv("VOICE") or random.choice(human))
)
chunks = [m.group().strip() for m in re.finditer(r' *((.{0,200})(\.|.$))', req_text)] chunks = [
m.group().strip() for m in re.finditer(r" *((.{0,200})(\.|.$))", req_text)
]
audio_clips = [] audio_clips = []
chunkId = 0 chunkId = 0
for chunk in chunks: for chunk in chunks:
r = requests.post(f"{self.URI_BASE}{voice}&req_text={chunk}&speaker_map_type=0") r = requests.post(
f"{self.URI_BASE}{voice}&req_text={chunk}&speaker_map_type=0"
)
vstr = [r.json()["data"]["v_str"]][0] vstr = [r.json()["data"]["v_str"]][0]
b64d = base64.b64decode(vstr) b64d = base64.b64decode(vstr)

@ -14,34 +14,47 @@ def get_start_and_end_times(video_length, length_of_clip):
def download_background(): def download_background():
"""Downloads the backgrounds/s video from youtube. """Downloads the backgrounds/s video from youtube."""
"""
Path("./assets/backgrounds/").mkdir(parents=True, exist_ok=True) Path("./assets/backgrounds/").mkdir(parents=True, exist_ok=True)
background_options = [ # uri , filename , credit background_options = [ # uri , filename , credit
("https://www.youtube.com/watch?v=n_Dv4JMiwK8", "parkour.mp4", 'bbswitzer'), ("https://www.youtube.com/watch?v=n_Dv4JMiwK8", "parkour.mp4", "bbswitzer"),
("https://www.youtube.com/watch?v=2X9QGY__0II", "rocket_league.mp4", 'Orbital Gameplay'), ] (
"https://www.youtube.com/watch?v=2X9QGY__0II",
"rocket_league.mp4",
"Orbital Gameplay",
),
]
# note: make sure the file name doesn't include a - in it # note: make sure the file name doesn't include a - in it
if len(listdir('./assets/backgrounds')) != len( if len(listdir("./assets/backgrounds")) != len(
background_options): # if there are any background videos not installed background_options
print_step("We need to download the backgnrounds videos. they are fairly large but it's only done once. 😎") ): # if there are any background videos not installed
print_step(
"We need to download the backgnrounds videos. they are fairly large but it's only done once. 😎"
)
print_substep("Downloading the backgrounds videos... please be patient 🙏 ") print_substep("Downloading the backgrounds videos... please be patient 🙏 ")
for uri, filename, credit in background_options: for uri, filename, credit in background_options:
print_substep(f"Downloading {filename} from {uri}") print_substep(f"Downloading {filename} from {uri}")
YouTube(uri).streams.filter(res="1080p").first().download("assets/backgrounds", YouTube(uri).streams.filter(res="1080p").first().download(
filename=f"{credit}-{filename}") "assets/backgrounds", filename=f"{credit}-{filename}"
)
print_substep("Background videos downloaded successfully! 🎉", style="bold green") print_substep(
"Background videos downloaded successfully! 🎉", style="bold green"
)
def chop_background_video(video_length): def chop_background_video(video_length):
print_step("Finding a spot in the backgrounds video to chop...✂️") print_step("Finding a spot in the backgrounds video to chop...✂️")
choice = random.choice(listdir('assets/backgrounds')) choice = random.choice(listdir("assets/backgrounds"))
environ["background_credit"] = choice.split('-')[0] environ["background_credit"] = choice.split("-")[0]
background = VideoFileClip(f"assets/backgrounds/{choice}") background = VideoFileClip(f"assets/backgrounds/{choice}")
start_time, end_time = get_start_and_end_times(video_length, background.duration) start_time, end_time = get_start_and_end_times(video_length, background.duration)
ffmpeg_extract_subclip(f'assets/backgrounds/{choice}', start_time, end_time, ffmpeg_extract_subclip(
targetname="assets/temp/background.mp4", ) f"assets/backgrounds/{choice}",
start_time,
end_time,
targetname="assets/temp/background.mp4",
)
print_substep("Background video chopped successfully! 🎉", style="bold green") print_substep("Background video chopped successfully! 🎉", style="bold green")

@ -3,8 +3,15 @@ import os
import time import time
from os.path import exists from os.path import exists
from moviepy.editor import VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, \ from moviepy.editor import (
CompositeAudioClip, CompositeVideoClip VideoFileClip,
AudioFileClip,
ImageClip,
concatenate_videoclips,
concatenate_audioclips,
CompositeAudioClip,
CompositeVideoClip,
)
from moviepy.video.io import ffmpeg_tools from moviepy.video.io import ffmpeg_tools
from reddit import subreddit from reddit import subreddit
@ -18,10 +25,13 @@ def make_final_video(number_of_clips, length):
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)
VideoFileClip.reH = lambda clip: clip.resize(width=H) VideoFileClip.reH = lambda clip: clip.resize(width=H)
opacity = os.getenv('OPACITY') opacity = os.getenv("OPACITY")
background_clip = ( background_clip = (
VideoFileClip("assets/temp/background.mp4").without_audio().resize(height=H).crop(x1=1166.6, y1=0, x2=2246.6, VideoFileClip("assets/temp/background.mp4")
y2=1920)) .without_audio()
.resize(height=H)
.crop(x1=1166.6, y1=0, x2=2246.6, y2=1920)
)
# Gather all audio clips # Gather all audio clips
audio_clips = [] audio_clips = []
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
@ -33,13 +43,41 @@ def make_final_video(number_of_clips, length):
# Gather all images # Gather all images
image_clips = [] image_clips = []
for i in range(0, number_of_clips): for i in range(0, number_of_clips):
image_clips.append( if opacity is None or opacity >= 1: # opacity not set or is set to one OR MORE
ImageClip(f"assets/temp/png/comment_{i}.png").set_duration(audio_clips[i + 1].duration).set_position( image_clips.append(
"center").resize(width=W - 100).set_opacity(float(opacity)), ) ImageClip(f"assets/temp/png/comment_{i}.png")
image_clips.insert(0, ImageClip(f"assets/temp/png/title.png").set_duration(audio_clips[0].duration).set_position( .set_duration(audio_clips[i + 1].duration)
"center").resize(width=W - 100).set_opacity(float(opacity)), .set_position("center")
) .resize(width=W - 100),
image_concat = concatenate_videoclips(image_clips).set_position(("center", "center")) )
else:
image_clips.append(
ImageClip(f"assets/temp/png/comment_{i}.png")
.set_duration(audio_clips[i + 1].duration)
.set_position("center")
.resize(width=W - 100)
.set_opacity(float(opacity)),
)
if opacity is None or opacity >= 1: # opacity not set or is set to one OR MORE
image_clips.insert(
0,
ImageClip(f"assets/temp/png/title.png")
.set_duration(audio_clips[0].duration)
.set_position("center")
.resize(width=W - 100),
)
else:
image_clips.insert(
0,
ImageClip(f"assets/temp/png/title.png")
.set_duration(audio_clips[0].duration)
.set_position("center")
.resize(width=W - 100)
.set_opacity(float(opacity)),
)
image_concat = concatenate_videoclips(image_clips).set_position(
("center", "center")
)
image_concat.audio = audio_composite image_concat.audio = audio_composite
final = CompositeVideoClip([background_clip, image_concat]) final = CompositeVideoClip([background_clip, image_concat])
@ -50,27 +88,35 @@ def make_final_video(number_of_clips, length):
else: else:
return title[0:30] + "..." return title[0:30] + "..."
filename = f'{get_video_title()}.mp4' filename = f"{get_video_title()}.mp4"
def save_data(): def save_data():
with open('./video_creation/data/videos.json', 'r+') as raw_vids: with open("./video_creation/data/videos.json", "r+") as raw_vids:
done_vids = json.load(raw_vids) done_vids = json.load(raw_vids)
if str(subreddit.submission.id) in [video['id'] for video in done_vids]: if str(subreddit.submission.id) in [video["id"] for video in done_vids]:
return # video already done but was specified to continue anyway in the .env file return # video already done but was specified to continue anyway in the .env file
payload = {"id": str(os.getenv("VIDEO_ID")), 'time': str(int(time.time())), payload = {
"background_credit": str(os.getenv('background_credit')), "id": str(os.getenv("VIDEO_ID")),
"reddit_title": str(os.getenv('VIDEO_TITLE')), "filename": filename} "time": str(int(time.time())),
"background_credit": str(os.getenv("background_credit")),
"reddit_title": str(os.getenv("VIDEO_TITLE")),
"filename": filename,
}
done_vids.append(payload) done_vids.append(payload)
raw_vids.seek(0) raw_vids.seek(0)
json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4) json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4)
save_data() save_data()
if not exists('./results'): if not exists("./results"):
print_substep('the results folder didn\'t exist so I made it') print_substep("the results folder didn't exist so I made it")
os.mkdir("./results") os.mkdir("./results")
final.write_videofile("assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k") final.write_videofile(
ffmpeg_tools.ffmpeg_extract_subclip("assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}") "assets/temp/temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k"
)
ffmpeg_tools.ffmpeg_extract_subclip(
"assets/temp/temp.mp4", 0, length, targetname=f"results/{filename}"
)
# os.remove("assets/temp/temp.mp4") # os.remove("assets/temp/temp.mp4")
print_step("Removing temporary files 🗑") print_step("Removing temporary files 🗑")
@ -78,4 +124,6 @@ def make_final_video(number_of_clips, length):
print_substep(f"Removed {cleanups} temporary files 🗑") print_substep(f"Removed {cleanups} temporary files 🗑")
print_substep(f"See result in the results folder!") print_substep(f"See result in the results folder!")
print_step(f"Reddit title: {os.getenv('VIDEO_TITLE')} \n Background Credit: {os.getenv('background_credit')}") print_step(
f"Reddit title: {os.getenv('VIDEO_TITLE')} \n Background Credit: {os.getenv('background_credit')}"
)

@ -28,9 +28,9 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
context = browser.new_context() context = browser.new_context()
if getenv("THEME").upper() == "DARK": if getenv("THEME").upper() == "DARK":
cookie_file = open('./video_creation/data/cookie-dark-mode.json') cookie_file = open("./video_creation/data/cookie-dark-mode.json")
else: else:
cookie_file = open('./video_creation/data/cookie-light-mode.json') cookie_file = open("./video_creation/data/cookie-light-mode.json")
cookies = json.load(cookie_file) cookies = json.load(cookie_file)
context.add_cookies(cookies) context.add_cookies(cookies)
# Get the thread screenshot # Get the thread screenshot
@ -43,14 +43,19 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
if getenv("ALLOW_NSFW").casefold() == "false": if getenv("ALLOW_NSFW").casefold() == "false":
print_substep("NSFW Post Detected. Skipping...") print_substep("NSFW Post Detected. Skipping...")
from main import main from main import main
main() main()
print_substep("Post is NSFW. You are spicy... :fire:") print_substep("Post is NSFW. You are spicy... :fire:")
page.locator('[data-testid="content-gate"] button').click() page.locator('[data-testid="content-gate"] button').click()
page.locator('[data-test-id="post-content"]').screenshot(path="assets/temp/png/title.png") page.locator('[data-test-id="post-content"]').screenshot(
path="assets/temp/png/title.png"
)
for idx, comment in track(enumerate(reddit_object["comments"]), "Downloading screenshots..."): for idx, comment in track(
enumerate(reddit_object["comments"]), "Downloading screenshots..."
):
# Stop if we have reached the screenshot_num # Stop if we have reached the screenshot_num
if idx >= screenshot_num: if idx >= screenshot_num:
@ -60,5 +65,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
page.locator('[data-testid="content-gate"] button').click() page.locator('[data-testid="content-gate"] button').click()
page.goto(f'https://reddit.com{comment["comment_url"]}') page.goto(f'https://reddit.com{comment["comment_url"]}')
page.locator(f"#t1_{comment['comment_id']}").screenshot(path=f"assets/temp/png/comment_{idx}.png") page.locator(f"#t1_{comment['comment_id']}").screenshot(
path=f"assets/temp/png/comment_{idx}.png"
)
print_substep("Screenshots downloaded Successfully.", style="bold green") print_substep("Screenshots downloaded Successfully.", style="bold green")

@ -25,7 +25,11 @@ def save_text_to_mp3(reddit_obj):
Path("assets/temp/mp3").mkdir(parents=True, exist_ok=True) Path("assets/temp/mp3").mkdir(parents=True, exist_ok=True)
ttttsw = TTTTSWrapper() # tiktok text to speech wrapper ttttsw = TTTTSWrapper() # tiktok text to speech wrapper
ttttsw.tts(sanitize_text(reddit_obj["thread_title"]), filename=f"assets/temp/mp3/title.mp3", random_speaker=False) ttttsw.tts(
sanitize_text(reddit_obj["thread_title"]),
filename=f"assets/temp/mp3/title.mp3",
random_speaker=False,
)
try: try:
length += MP3(f"assets/temp/mp3/title.mp3").info.length length += MP3(f"assets/temp/mp3/title.mp3").info.length
except HeaderNotFoundError: # note to self AudioFileClip except HeaderNotFoundError: # note to self AudioFileClip
@ -36,7 +40,11 @@ def save_text_to_mp3(reddit_obj):
if length > VIDEO_LENGTH: if length > VIDEO_LENGTH:
break break
ttttsw.tts(sanitize_text(comment["comment_body"]), filename=f"assets/temp/mp3/{com}.mp3", random_speaker=False) ttttsw.tts(
sanitize_text(comment["comment_body"]),
filename=f"assets/temp/mp3/{com}.mp3",
random_speaker=False,
)
try: try:
length += MP3(f"assets/temp/mp3/{com}.mp3").info.length length += MP3(f"assets/temp/mp3/{com}.mp3").info.length
com += 1 com += 1
@ -45,9 +53,11 @@ def save_text_to_mp3(reddit_obj):
length += sox.file_info.duration(f"assets/temp/mp3/{com}.mp3") length += sox.file_info.duration(f"assets/temp/mp3/{com}.mp3")
com += 1 com += 1
except (OSError, IOError): except (OSError, IOError):
print('would have removed' print(
f"assets/temp/mp3/{com}.mp3" "would have removed"
f"assets/temp/png/comment_{com}.png") f"assets/temp/mp3/{com}.mp3"
f"assets/temp/png/comment_{com}.png"
)
# remove(f"assets/temp/mp3/{com}.mp3") # remove(f"assets/temp/mp3/{com}.mp3")
# remove(f"assets/temp/png/comment_{com}.png")# todo might cause odd un-syncing # remove(f"assets/temp/png/comment_{com}.png")# todo might cause odd un-syncing

Loading…
Cancel
Save