Merge branch 'develop' into ux-changes
This commit is contained in:
5 files changed
+57
-25
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
@@ -115,6 +115,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)
|
||||
+6
-4
@@ -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,8 +64,8 @@ def get_subreddit_threads():
|
||||
|
||||
threads = subreddit.hot(limit=25)
|
||||
submission = list(threads)[random.randrange(0, 25)]
|
||||
|
||||
upvotes=submission.score
|
||||
|
||||
upvotes=submission.score
|
||||
ratio=submission.upvote_ratio * 100
|
||||
num_comments=submission.num_comments
|
||||
|
||||
@@ -74,6 +74,8 @@ def get_subreddit_threads():
|
||||
console.log(f"[bold blue] Thread has a upvote ratio of " + str(ratio) + "%")
|
||||
console.log(f"[bold blue] Thread has " + str(num_comments) + " comments")
|
||||
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
|
||||
@@ -15,7 +15,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)
|
||||
@@ -26,10 +26,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()
|
||||
|
||||
Reference in new issue
Block a user