Merge pull request #51 from PatatjeMC/master

Fixed errors and glitchy ending
pull/418/head
Jason 3 years ago committed by GitHub
commit f583ea9608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,11 +19,6 @@ def main():
def get_obj(): def get_obj():
reddit_obj = get_subreddit_threads() reddit_obj = get_subreddit_threads()
for comment in (reddit_obj["comments"]):
if len(comment) > 250:
print(comment)
reddit_obj["comments"].remove(comment)
print(reddit_obj["comments"])
return reddit_obj return reddit_obj
reddit_object = get_obj() reddit_object = get_obj()
@ -31,7 +26,7 @@ def main():
download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background() download_background()
chop_background_video(length) chop_background_video(length)
final_video = make_final_video(number_of_comments) final_video = make_final_video(number_of_comments, length)
if __name__ == '__main__': if __name__ == '__main__':

@ -43,6 +43,8 @@ def get_subreddit_threads():
threads = subreddit.hot(limit=25) threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)] submission = list(threads)[random.randrange(0, 25)]
submission = check_done(submission) submission = check_done(submission)
if submission == None:
return get_subreddit_threads()
print_substep( print_substep(
f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)') f'subreddit thread is: {submission.title}\n(if you dont like this, you can change it by exiting and rerunning the program)')
@ -56,6 +58,7 @@ def get_subreddit_threads():
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
if len(top_level_comment.body) <= 250:
content["comments"].append( content["comments"].append(
{"comment_body": top_level_comment.body, "comment_url": top_level_comment.permalink, {"comment_body": top_level_comment.body, "comment_url": top_level_comment.permalink,
"comment_id": top_level_comment.id, }) "comment_id": top_level_comment.id, })

@ -17,6 +17,5 @@ def check_done(redditobj): # don't set this to be run anyplace that isn't subre
for video in done_videos: for video in done_videos:
if video['id'] == str(redditobj): if video['id'] == str(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')
from reddit.subreddit import get_subreddit_threads return None
return get_subreddit_threads() # recursive func
return redditobj return redditobj

@ -54,9 +54,6 @@ class TTTTSWrapper: # TikTok Text-to-Speech Wrapper
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): def tts(self, req_text: str = "TikTok Text To Speech", filename: str = 'title.mp3', random_speaker: bool = False):
if len(req_text) > 299:
return ValueError("Text too long must be under 299 characters")
if random_speaker:
req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and") req_text = req_text.replace("+", "plus").replace(" ", "+").replace("&", "and")
voice = self.randomvoice() if random_speaker else 'en_us_002' voice = self.randomvoice() if random_speaker else 'en_us_002'
r = requests.post(f"{self.URI_BASE}{voice}&req_text={req_text}&speaker_map_type=0") r = requests.post(f"{self.URI_BASE}{voice}&req_text={req_text}&speaker_map_type=0")

@ -36,7 +36,7 @@ def download_background():
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="720p").first().download("assets/backgrounds", YouTube(uri).streams.filter(res="1080p").first().download("assets/backgrounds",
filename=f"{credit}-{filename}") filename=f"{credit}-{filename}")
progress.update(download_task, advance=1) progress.update(download_task, advance=1)

@ -3,8 +3,8 @@ 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 VideoFileClip, AudioFileClip, ImageClip, concatenate_videoclips, concatenate_audioclips, CompositeAudioClip, CompositeVideoClip
CompositeAudioClip, CompositeVideoClip) from moviepy.video import io
from utils.cleanup import cleanup from utils.cleanup import cleanup
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
@ -12,7 +12,7 @@ from utils.console import print_step, print_substep
W, H = 1080, 1920 W, H = 1080, 1920
def make_final_video(number_of_clips): 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)
@ -65,7 +65,11 @@ def make_final_video(number_of_clips):
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(f"results/{filename}", fps=30, audio_codec="aac", audio_bitrate="192k")
final.write_videofile("temp.mp4", fps=30, audio_codec="aac", audio_bitrate="192k")
io.ffmpeg_tools.ffmpeg_extract_subclip("temp.mp4", 0, length, targetname=f"results/{filename}")
os.remove("temp.mp4")
print_step("Removing temporary files 🗑") print_step("Removing temporary files 🗑")
cleanups = cleanup() cleanups = cleanup()
print_substep(f"Removed {cleanups} temporary files 🗑") print_substep(f"Removed {cleanups} temporary files 🗑")

Loading…
Cancel
Save