Added optional arguments for specifying AskReddit threads and YouTube videos to be used

pull/73/head
Christopher Walley 3 years ago
parent 5b3989611f
commit 2bf2ccd7da

@ -5,6 +5,7 @@ from video_creation.background import download_background, chop_background_video
from video_creation.voices import save_text_to_mp3 from video_creation.voices import save_text_to_mp3
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.final_video import make_final_video from video_creation.final_video import make_final_video
import argparse
print_markdown( print_markdown(
"### Thanks for using this tool! 😊 [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com). If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue." "### Thanks for using this tool! 😊 [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com). If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue."
@ -12,11 +13,14 @@ print_markdown(
time.sleep(3) time.sleep(3)
parser = argparse.ArgumentParser()
parser.add_argument("--RedditID", help="ID of AskReddit thread to fetch") #This is an optional argument for specifiying the Reddit thread that you want
parser.add_argument("--VideoID", help="ID of Youtube video to fetch") #This is an optional argument for specifiying the YouTube video that you want
args = parser.parse_args()
reddit_object = get_askreddit_threads() reddit_object = get_askreddit_threads(args.RedditID)
length, number_of_comments = save_text_to_mp3(reddit_object) length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background() download_background(args.VideoID)
chop_background_video(length) chop_background_video(length, args.VideoID)
final_video = make_final_video(number_of_comments) final_video = make_final_video(number_of_comments)

@ -5,7 +5,7 @@ from dotenv import load_dotenv
import os import os
def get_askreddit_threads(): def get_askreddit_threads(threadID):
""" """
Returns a list of threads from the AskReddit subreddit. Returns a list of threads from the AskReddit subreddit.
""" """
@ -21,9 +21,12 @@ def get_askreddit_threads():
username=os.getenv("REDDIT_USERNAME"), username=os.getenv("REDDIT_USERNAME"),
password=os.getenv("REDDIT_PASSWORD"), password=os.getenv("REDDIT_PASSWORD"),
) )
askreddit = reddit.subreddit("askreddit") if threadID:
threads = askreddit.hot(limit=25) submission = reddit.submission(threadID)
submission = list(threads)[random.randrange(0, 25)] else:
askreddit = reddit.subreddit("askreddit")
threads = askreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title} :thumbsup:") print_substep(f"Video will be: {submission.title} :thumbsup:")
try: try:

@ -12,33 +12,41 @@ def get_start_and_end_times(video_length, length_of_clip):
return random_time, random_time + video_length return random_time, random_time + video_length
def download_background(): def download_background(videoID):
"""Downloads the background video from youtube. """Downloads the background video from youtube.
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8) Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
""" """
if not videoID:
print_step(
"Shoutout to bbswitzer for his Minecraft parkour "
)
videoID = "n_Dv4JMiwK8"
url = "https://www.youtube.com/watch?v={}".format(videoID)
if not Path("assets/mp4/background.mp4").is_file(): if not Path("assets/mp4/{}.mp4".format(videoID)).is_file():
print_step( print_step(
"We need to download the Minecraft background video. This is fairly large but it's only done once. 😎" "We need to download the background video. This is fairly large but it's only done once. 😎"
) )
print_substep("Downloading the background video... please be patient 🙏") print_substep("Downloading the background video... please be patient 🙏")
YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8").streams.filter( YouTube(url).streams.filter(
res="720p" res="720p"
).first().download( ).first().download(
"assets/mp4", "assets/mp4",
filename="background.mp4", filename="{}.mp4".format(videoID),
) )
print_substep("Background video downloaded successfully! 🎉", style="bold green") print_substep("Background video downloaded successfully! 🎉", style="bold green")
def chop_background_video(video_length): def chop_background_video(video_length, videoID):
print_step("Finding a spot in the background video to chop...✂️") print_step("Finding a spot in the background video to chop...✂️")
background = VideoFileClip("assets/mp4/background.mp4") if not videoID:
videoID = "n_Dv4JMiwK8"
background = VideoFileClip("assets/mp4/{}.mp4".format(videoID))
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( ffmpeg_extract_subclip(
"assets/mp4/background.mp4", "assets/mp4/{}.mp4".format(videoID),
start_time, start_time,
end_time, end_time,
targetname="assets/mp4/clip.mp4", targetname="assets/mp4/clip.mp4",

@ -17,7 +17,7 @@ def save_text_to_mp3(reddit_obj):
# Create a folder for the mp3 files. # Create a folder for the mp3 files.
Path("assets/mp3").mkdir(parents=True, exist_ok=True) Path("assets/mp3").mkdir(parents=True, exist_ok=True)
tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="co.uk") tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="com.au")
tts.save(f"assets/mp3/title.mp3") tts.save(f"assets/mp3/title.mp3")
length += MP3(f"assets/mp3/title.mp3").info.length length += MP3(f"assets/mp3/title.mp3").info.length

Loading…
Cancel
Save