Merge pull request #171 from reoccurcat/master

allow a custom background to be used instead of the Minecraft parkour
pull/456/head
Callum Leslie 2 years ago committed by GitHub
commit 54c6518906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -51,11 +51,13 @@ In its current state, this bot does exactly what it needs to do. However, lots o
I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute!
- [x] Allowing users to choose a reddit thread instead of being randomized.
- [ ] Allowing users to choose a background that is picked instead of the Minecraft one.
- [x] Allowing users to choose between any subreddit.
- [ ] Allowing users to change voice.
- [ ] Creating better documentation and adding a command line interface.
To-Do:
- [x] Allowing users to choose a reddit thread instead of being randomized.
- [x] Allowing users to choose a background that is picked instead of the Minecraft one.
- [x] Allowing users to choose between any subreddit.
- [ ] Allowing users to change voice.
- [ ] Creating better documentation and adding a command line interface.
Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed information.

@ -92,6 +92,9 @@ if configured:
download_screenshots_of_reddit_posts(
reddit_object, number_of_comments, os.getenv("THEME", "light")
)
download_background()
chop_background_video(length)
while True:
vidpath = download_background(length)
noerror = chop_background_video(length, vidpath)
if noerror is True:
break
final_video = make_final_video(number_of_comments)

@ -13,7 +13,7 @@ console = Console()
def get_subreddit_threads():
global submission
"""
Returns a list of threads from the AskReddit subreddit.
Returns a list of threads from the provided subreddit.
"""
load_dotenv()
@ -33,7 +33,7 @@ def get_subreddit_threads():
reddit = praw.Reddit(
client_id=os.getenv("REDDIT_CLIENT_ID"),
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
user_agent="Accessing AskReddit threads",
user_agent="Accessing subreddit threads",
username=os.getenv("REDDIT_USERNAME"),
password=passkey,
)
@ -64,9 +64,10 @@ def get_subreddit_threads():
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 25)]
print_substep(f"Video will be: {submission.title}")
print("Getting video comments...")
print_substep(f"Video will be: {submission.title} :thumbsup:")
console.log("Getting video comments...")
try:
content["thread_url"] = submission.url
content["thread_title"] = submission.title

@ -8,46 +8,68 @@ from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip
from utils.console import print_step, print_substep
import datetime
def get_start_and_end_times(video_length, length_of_clip):
random_time = randrange(180, int(length_of_clip) - int(video_length))
return random_time, random_time + video_length
def download_background(video_length):
def download_background():
"""Downloads the background video from youtube.
Shoutout to: bbswitzer (https://www.youtube.com/watch?v=n_Dv4JMiwK8)
"""
if not Path("assets/mp4/background.mp4").is_file():
print_substep("\nPut the URL of the video you want in the background.\nThe default video is a Minecraft parkour video.\n"
"Leave the input field blank to use the default.")
print_substep(f"Make sure the video is longer than {str(datetime.timedelta(seconds=round(video_length + 180)))}!\n", style="red")
inp = input("URL: ")
if not inp:
vidurl = "https://www.youtube.com/watch?v=n_Dv4JMiwK8"
else:
vidurl = inp
vidpath = vidurl.split("v=")[1]
if not Path(f"assets/mp4/{vidpath}.mp4").is_file():
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 may be fairly large but it's only done once per background."
)
print_substep("Downloading the background video... please be patient.")
ydl_opts = {
"outtmpl": "assets/mp4/background.mp4",
"outtmpl": f"assets/mp4/{vidpath}.mp4",
"merge_output_format": "mp4",
}
with YoutubeDL(ydl_opts) as ydl:
ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8")
ydl.download(vidurl)
print_substep("Background video downloaded successfully!", style="bold green")
return vidpath
def chop_background_video(video_length):
def chop_background_video(video_length, vidpath):
print_step("Finding a spot in the background video to chop...")
background = VideoFileClip("assets/mp4/background.mp4")
background = VideoFileClip(f"assets/mp4/{vidpath}.mp4")
if background.duration < video_length + 180:
print_substep("This video is too short.", style="red")
noerror = False
return noerror
start_time, end_time = get_start_and_end_times(video_length, background.duration)
ffmpeg_extract_subclip(
"assets/mp4/background.mp4",
f"assets/mp4/{vidpath}.mp4",
start_time,
end_time,
targetname="assets/mp4/clip.mp4",
)
print_substep("Background video chopped successfully!", style="bold green")
noerror = True
return noerror

@ -13,7 +13,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
reddit_object: The Reddit Object you received in askreddit.py
screenshot_num: The number of screenshots you want to download.
"""
print_step("Downloading Screenshots of Reddit Posts 📷")
print_step("Downloading screenshots of reddit posts...")
# ! Make sure the reddit screenshots folder exists
Path("assets/png").mkdir(parents=True, exist_ok=True)
@ -24,10 +24,13 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme):
browser = p.chromium.launch()
context = browser.new_context()
if theme.casefold() == "dark":
cookie_file = open("video_creation/cookies.json")
cookies = json.load(cookie_file)
context.add_cookies(cookies)
try:
if theme.casefold() == "dark":
cookie_file = open('video_creation/cookies.json')
cookies = json.load(cookie_file)
context.add_cookies(cookies)
except AttributeError:
pass
# Get the thread screenshot
page = context.new_page()

Loading…
Cancel
Save