Merge remote-tracking branch 'upstream/1.1'

pull/139/head
Kamushy 3 years ago
commit 2d0ef4e53c

@ -2,3 +2,5 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
SUBREDDIT=""

@ -33,18 +33,19 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p
1. Clone this repository 1. Clone this repository
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. 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.
3. Run `pip3 install -r requirements.txt` 3. Run `pip3 install -r requirements.txt`
4. Run `python3 main.py` 4. Run `playwright install` and `playwright install-deps`.
5. ... 5. Run `python3 main.py`
6. Enjoy 😎 6. ...
7. Enjoy 😎
## Contributing & Ways to improve 📈 ## Contributing & Ways to improve 📈
In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made.
I have tried to simplify the code so anyone can read it and start contibuting at any skill level. Don't be shy :) contribute! I have tried to simplify the code so anyone can read it and start contributing at any skill level. Don't be shy :) contribute!
- [ ] Allowing users to choose a reddit thread instead of being randomized. - [ ] 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. - [ ] Allowing users to choose a background that is picked instead of the Minecraft one.
- [ ] Allowing users to choose between any subreddit. - [x] Allowing users to choose between any subreddit.
- [ ] Allowing users to change voice. - [ ] Allowing users to change voice.
- [ ] Creating better documentation and adding a command line interface. - [ ] Creating better documentation and adding a command line interface.

@ -1,6 +1,6 @@
from utils.console import print_markdown from utils.console import print_markdown
import time import time
from reddit.askreddit import get_askreddit_threads from reddit.subreddit import get_subreddit_threads
from video_creation.background import download_background, chop_background_video 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
@ -13,7 +13,7 @@ print_markdown(
time.sleep(3) time.sleep(3)
reddit_object = get_askreddit_threads() reddit_object = get_subreddit_threads()
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)

@ -10,7 +10,7 @@ def get_askreddit_threads():
Returns a list of threads from the AskReddit subreddit. Returns a list of threads from the AskReddit subreddit.
""" """
print_step("Getting AskReddit threads...") print_step("Getting subreddit threads...")
content = {} content = {}
load_dotenv() load_dotenv()
@ -21,8 +21,20 @@ 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")
threads = askreddit.hot(limit=25) if os.getenv("SUBREDDIT"):
subreddit = reddit.subreddit(os.getenv("SUBREDDIT"))
else:
# ! Prompt the user to enter a subreddit
try:
subreddit = reddit.subreddit(
input("What subreddit would you like to pull from? ")
)
except ValueError:
subreddit = reddit.subreddit("askreddit")
print_substep("Subreddit not defined. Using AskReddit.")
threads = subreddit.hot(limit=25)
submission = list(threads)[random.randrange(0, 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:
@ -42,5 +54,5 @@ def get_askreddit_threads():
except AttributeError as e: except AttributeError as e:
pass pass
print_substep("Received AskReddit threads Successfully.", style="bold green") print_substep("Received subreddit threads Successfully.", style="bold green")
return content return content

@ -28,13 +28,13 @@ pyflakes==2.2.0
Pygments==2.12.0 Pygments==2.12.0
python-dotenv==0.20.0 python-dotenv==0.20.0
pytube==12.1.0 pytube==12.1.0
regex==2020.10.15 regex==2022.4.24
requests==2.27.1 requests==2.27.1
rich==12.4.4 rich==12.4.4
six==1.16.0 six==1.16.0
toml==0.10.1 toml==0.10.1
tqdm==4.64.0 tqdm==4.64.0
typed-ast==1.4.1 typed-ast==1.5.4
typing_extensions==4.2.0 typing_extensions==4.2.0
update-checker==0.18.0 update-checker==0.18.0
urllib3==1.26.9 urllib3==1.26.9

@ -1,5 +1,6 @@
from random import randrange from random import randrange
from pytube import YouTube from pytube import YouTube
from pytube.cli import on_progress
from pathlib import Path from pathlib import Path
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.editor import VideoFileClip from moviepy.editor import VideoFileClip
@ -11,7 +12,6 @@ def get_start_and_end_times(video_length, length_of_clip):
random_time = randrange(180, int(length_of_clip) - int(video_length)) random_time = randrange(180, int(length_of_clip) - int(video_length))
return random_time, random_time + video_length return random_time, random_time + video_length
def download_background(): def download_background():
"""Downloads the background video from youtube. """Downloads the background video from youtube.
@ -23,7 +23,7 @@ def download_background():
"We need to download the Minecraft background video. This is fairly large but it's only done once. 😎" "We need to download the Minecraft 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("https://www.youtube.com/watch?v=n_Dv4JMiwK8", on_progress_callback=on_progress).streams.filter(
res="720p" res="720p"
).first().download( ).first().download(
"assets/mp4", "assets/mp4",

Loading…
Cancel
Save