Skip to content

Commit 6fc5d2a

Browse files
authored
Merge pull request #157 from reoccurcat/master
overhaul of the functions and QoL improvements
2 parents 4e49340 + 49c1a89 commit 6fc5d2a

File tree

11 files changed

+59
-31
lines changed

11 files changed

+59
-31
lines changed

.env.template

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ REDDIT_CLIENT_SECRET=""
33
REDDIT_USERNAME=""
44
REDDIT_PASSWORD=""
55

6-
SUBREDDIT=""
6+
# Valid options are "yes" and "no" for the variable below
7+
REDDIT_2FA=""
8+
9+
10+
SUBREDDIT=""

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
assets/
22
.env
3-
reddit-bot-351418-5560ebc49cac.json
3+
reddit-bot-351418-5560ebc49cac.json
4+
__pycache__

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
2626
## Requirements
2727

2828
- Python 3.6+
29-
- Playwright (this should install automatically in installation)
29+
- Playwright (this should install automatically during installation)
3030

3131
## Installation 👩‍💻
3232

3333
1. Clone this repository
34-
2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` files.
34+
2. Rename `.env.template` to `.env` and replace all values with the appropriate fields. To get Reddit keys (**required**), visit [the Reddit Apps page.](https://www.reddit.com/prefs/apps) TL;DR set up an app that is a "script". Copy your keys into the `.env` file, along with whether your account uses two-factor authentication.
3535
3. Run `pip3 install -r requirements.txt`
3636
4. Run `playwright install` and `playwright install-deps`.
3737
5. Run `python3 main.py`

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from utils.console import print_markdown
22
import time
3+
34
from reddit.subreddit import get_subreddit_threads
45
from video_creation.background import download_background, chop_background_video
56
from video_creation.voices import save_text_to_mp3
67
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
78
from video_creation.final_video import make_final_video
89

910
print_markdown(
10-
"### 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."
11+
"### 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."
1112
)
1213

1314
time.sleep(3)

reddit/subreddit.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,34 @@
66

77

88
def get_subreddit_threads():
9+
910
"""
1011
Returns a list of threads from the AskReddit subreddit.
1112
"""
1213

13-
print_step("Getting subreddit threads...")
14+
load_dotenv()
15+
16+
print_step("Getting AskReddit threads...")
17+
18+
if os.getenv("REDDIT_2FA").lower() == "yes":
19+
print(
20+
"\nEnter your two-factor authentication code from your authenticator app.\n"
21+
)
22+
code = input("> ")
23+
print()
24+
pw = os.getenv("REDDIT_PASSWORD")
25+
passkey = f"{pw}:{code}"
26+
else:
27+
passkey = os.getenv("REDDIT_PASSWORD")
1428

1529
content = {}
16-
load_dotenv()
30+
1731
reddit = praw.Reddit(
1832
client_id=os.getenv("REDDIT_CLIENT_ID"),
1933
client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
2034
user_agent="Accessing AskReddit threads",
2135
username=os.getenv("REDDIT_USERNAME"),
22-
password=os.getenv("REDDIT_PASSWORD"),
36+
password=passkey,
2337
)
2438

2539
if os.getenv("SUBREDDIT"):
@@ -54,5 +68,6 @@ def get_subreddit_threads():
5468

5569
except AttributeError as e:
5670
pass
57-
print_substep("Received subreddit threads Successfully.", style="bold green")
71+
print_substep("Received AskReddit threads successfully.", style="bold green")
72+
5873
return content

requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ pyee==8.1.0
2727
pyflakes==2.2.0
2828
Pygments==2.12.0
2929
python-dotenv==0.20.0
30-
pytube==12.1.0
31-
regex==2022.4.24
30+
31+
regex==2020.10.15
32+
3233
requests==2.27.1
3334
rich==12.4.4
3435
six==1.16.0
@@ -40,3 +41,4 @@ update-checker==0.18.0
4041
urllib3==1.26.9
4142
websocket-client==1.3.2
4243
websockets==10.1
44+
yt-dlp==2022.5.18

video_creation/background.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from random import randrange
2-
from pytube import YouTube
3-
from pytube.cli import on_progress
2+
3+
from yt_dlp import YoutubeDL
4+
45
from pathlib import Path
56
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
67
from moviepy.editor import VideoFileClip
@@ -20,20 +21,24 @@ def download_background():
2021

2122
if not Path("assets/mp4/background.mp4").is_file():
2223
print_step(
23-
"We need to download the Minecraft background video. This is fairly large but it's only done once. 😎"
24+
"We need to download the Minecraft background video. This is fairly large but it's only done once."
2425
)
25-
print_substep("Downloading the background video... please be patient 🙏")
26-
YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8", on_progress_callback=on_progress).streams.filter(
27-
res="720p"
28-
).first().download(
29-
"assets/mp4",
30-
filename="background.mp4",
31-
)
32-
print_substep("Background video downloaded successfully! 🎉", style="bold green")
26+
27+
print_substep("Downloading the background video... please be patient.")
28+
29+
ydl_opts = {
30+
"outtmpl": "assets/mp4/background.mp4",
31+
"merge_output_format": "mp4",
32+
}
33+
34+
with YoutubeDL(ydl_opts) as ydl:
35+
ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8")
36+
37+
print_substep("Background video downloaded successfully!", style="bold green")
3338

3439

3540
def chop_background_video(video_length):
36-
print_step("Finding a spot in the background video to chop...✂️")
41+
print_step("Finding a spot in the background video to chop...")
3742
background = VideoFileClip("assets/mp4/background.mp4")
3843

3944
start_time, end_time = get_start_and_end_times(video_length, background.duration)
@@ -43,4 +48,4 @@ def chop_background_video(video_length):
4348
end_time,
4449
targetname="assets/mp4/clip.mp4",
4550
)
46-
print_substep("Background video chopped successfully! 🎉", style="bold green")
51+
print_substep("Background video chopped successfully!", style="bold green")

video_creation/final_video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def make_final_video(number_of_clips):
17-
print_step("Creating the final video 🎥")
17+
print_step("Creating the final video...")
1818
VideoFileClip.reW = lambda clip: clip.resize(width=W)
1919
VideoFileClip.reH = lambda clip: clip.resize(width=H)
2020

video_creation/screenshot_downloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
2828
if page.locator('[data-testid="content-gate"]').is_visible():
2929
# This means the post is NSFW and requires to click the proceed button.
3030

31-
print_substep("Post is NSFW. You are spicy... :fire:")
31+
print_substep("Post is NSFW. You are spicy...")
3232
page.locator('[data-testid="content-gate"] button').click()
3333

3434
page.locator('[data-test-id="post-content"]').screenshot(
@@ -50,4 +50,4 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num):
5050
page.locator(f"#t1_{comment['comment_id']}").screenshot(
5151
path=f"assets/png/comment_{idx}.png"
5252
)
53-
print_substep("Screenshots downloaded Successfully.", style="bold green")
53+
print_substep("Screenshots downloaded successfully.", style="bold green")

video_creation/test.py

Whitespace-only changes.

0 commit comments

Comments
 (0)