From c03bd2ae82f9b19b8f9bfd039b06dedbac657c7b Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Wed, 1 Jun 2022 13:42:22 -0400 Subject: [PATCH 01/20] Add male voice --- .env.template | 3 ++- main.py | 5 ++++- video_creation/voices.py | 29 ++++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.env.template b/.env.template index e00c242..baf9d46 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,5 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" -REDDIT_PASSWORD="" \ No newline at end of file +REDDIT_PASSWORD="" +VOICE="female" \ No newline at end of file diff --git a/main.py b/main.py index 8fb3d50..a394dc0 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,8 @@ from video_creation.background import download_background, chop_background_video from video_creation.voices import save_text_to_mp3 from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts from video_creation.final_video import make_final_video +from dotenv import load_dotenv +import os 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." @@ -15,7 +17,8 @@ time.sleep(3) reddit_object = get_askreddit_threads() -length, number_of_comments = save_text_to_mp3(reddit_object) +load_dotenv() +length, number_of_comments = save_text_to_mp3(reddit_object, os.getenv("VOICE")) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) diff --git a/video_creation/voices.py b/video_creation/voices.py index d719ff9..4000245 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,9 +3,10 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track +import requests -def save_text_to_mp3(reddit_obj): +def save_text_to_mp3(reddit_obj, voice): """Saves Text to MP3 files. Args: @@ -17,16 +18,34 @@ def save_text_to_mp3(reddit_obj): # Create a folder for the mp3 files. Path("assets/mp3").mkdir(parents=True, exist_ok=True) - tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="co.uk") - tts.save(f"assets/mp3/title.mp3") + if voice == "female": + tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="co.uk") + tts.save(f"assets/mp3/title.mp3") + elif voice == "male": + url = 'https://streamlabs.com/polly/speak' + body = {'voice': 'Brian', 'text': reddit_obj["thread_title"]} + response = requests.post(url, data = body) + voice_data = requests.get(response.json()['speak_url']) + f = open('assets/mp3/title.mp3', 'wb') + f.write(voice_data.content) + length += MP3(f"assets/mp3/title.mp3").info.length for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point if length > 50: break - tts = gTTS(text=comment["comment_body"], lang="en") - tts.save(f"assets/mp3/{idx}.mp3") + + if voice == "female": + tts = gTTS(text=comment["comment_body"], lang="en") + tts.save(f"assets/mp3/{idx}.mp3") + elif voice == "male": + body = {'voice': 'Brian', 'text': comment["comment_body"]} + response = requests.post(url, data = body) + voice_data = requests.get(response.json()['speak_url']) + f = open(f"assets/mp3/{idx}.mp3", 'wb') + f.write(voice_data.content) + length += MP3(f"assets/mp3/{idx}.mp3").info.length print_substep("Saved Text to MP3 files Successfully.", style="bold green") From 21c8da3648cb1024448f35cd6b6f51b6370d82f2 Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Thu, 2 Jun 2022 21:57:32 +1000 Subject: [PATCH 02/20] Made submission global --- reddit/askreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..21b2277 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -4,8 +4,8 @@ import random from dotenv import load_dotenv import os - def get_askreddit_threads(): + global submission """ Returns a list of threads from the AskReddit subreddit. """ From 9bb1aa351e222d10308ab16baacaea43575278b7 Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:00:24 +1000 Subject: [PATCH 03/20] made name change correctly line 59 is if any of characters cant be turned into a file remove them --- video_creation/final_video.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 947ab04..25f80f0 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -7,6 +7,8 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) +import reddit.askreddit +import re from utils.console import print_step @@ -14,6 +16,7 @@ W, H = 1080, 1920 def make_final_video(number_of_clips): + global submission print_step("Creating the final video ๐ŸŽฅ") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -53,9 +56,7 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - final.write_videofile( - "assets/final_video.mp4", fps=30, audio_codec="aac", audio_bitrate="192k" - ) - + filename = (re.sub('[?\"/%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) + final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass From 93bcd7be772d565be7e893f336fe5a4e3cce107d Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:57:02 +1000 Subject: [PATCH 04/20] file will now go to correct folder --- video_creation/final_video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 25f80f0..f711568 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -56,7 +56,7 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"/%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) + filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass From 757768be151e250390e4ff78dcfa82897f5fe6be Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Fri, 3 Jun 2022 11:50:54 +1000 Subject: [PATCH 05/20] Making it work with newer code version --- reddit/askreddit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 21b2277..78ec481 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -5,7 +5,6 @@ from dotenv import load_dotenv import os def get_askreddit_threads(): - global submission """ Returns a list of threads from the AskReddit subreddit. """ From 8546deac7d93cdda847e5941523320161533d645 Mon Sep 17 00:00:00 2001 From: Kamushy Date: Fri, 3 Jun 2022 11:59:36 +1000 Subject: [PATCH 06/20] Added it back Have no idea how do this --- reddit/askreddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 78ec481..21b2277 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -5,6 +5,7 @@ from dotenv import load_dotenv import os def get_askreddit_threads(): + global submission """ Returns a list of threads from the AskReddit subreddit. """ From 3f32feaa2466cd1136e6c2a1875654032e6ee14c Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Fri, 3 Jun 2022 13:51:43 -0400 Subject: [PATCH 07/20] add character limit for male voice --- main.py | 4 ++-- reddit/askreddit.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index a394dc0..872362c 100644 --- a/main.py +++ b/main.py @@ -15,9 +15,9 @@ print_markdown( time.sleep(3) -reddit_object = get_askreddit_threads() - load_dotenv() +reddit_object = get_askreddit_threads(os.getenv("VOICE")) + length, number_of_comments = save_text_to_mp3(reddit_object, os.getenv("VOICE")) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..1e3b3b3 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -5,7 +5,7 @@ from dotenv import load_dotenv import os -def get_askreddit_threads(): +def get_askreddit_threads(voice): """ Returns a list of threads from the AskReddit subreddit. """ @@ -32,6 +32,8 @@ def get_askreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: + if voice == "male" and len(top_level_comment.body) > 550: + continue content["comments"].append( { "comment_body": top_level_comment.body, From b9b46774ff25ae256291ec7307d333ea9b585ab9 Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Fri, 3 Jun 2022 13:57:20 -0400 Subject: [PATCH 08/20] Create function for generating and saving TTS --- video_creation/voices.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index 4000245..27e5c6d 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -18,17 +18,7 @@ def save_text_to_mp3(reddit_obj, voice): # Create a folder for the mp3 files. Path("assets/mp3").mkdir(parents=True, exist_ok=True) - if voice == "female": - tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="co.uk") - tts.save(f"assets/mp3/title.mp3") - elif voice == "male": - url = 'https://streamlabs.com/polly/speak' - body = {'voice': 'Brian', 'text': reddit_obj["thread_title"]} - response = requests.post(url, data = body) - voice_data = requests.get(response.json()['speak_url']) - f = open('assets/mp3/title.mp3', 'wb') - f.write(voice_data.content) - + generate_and_save_tts(voice, reddit_obj["thread_title"], "assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): @@ -36,18 +26,21 @@ def save_text_to_mp3(reddit_obj, voice): if length > 50: break - if voice == "female": - tts = gTTS(text=comment["comment_body"], lang="en") - tts.save(f"assets/mp3/{idx}.mp3") - elif voice == "male": - body = {'voice': 'Brian', 'text': comment["comment_body"]} - response = requests.post(url, data = body) - voice_data = requests.get(response.json()['speak_url']) - f = open(f"assets/mp3/{idx}.mp3", 'wb') - f.write(voice_data.content) - + generate_and_save_tts(voice, comment["comment_body"], f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length print_substep("Saved Text to MP3 files Successfully.", style="bold green") # ! Return the index so we know how many screenshots of comments we need to make. return length, idx + +def generate_and_save_tts(voice, text, file_name): + if voice == "female": + tts = gTTS(text=text, lang="en") + tts.save(file_name) + elif voice == "male": + url = 'https://streamlabs.com/polly/speak' + body = {'voice': 'Brian', 'text': text} + response = requests.post(url, data = body) + voice_data = requests.get(response.json()['speak_url']) + f = open(file_name, 'wb') + f.write(voice_data.content) \ No newline at end of file From d858c1ca5f0365b000e7ddd114ac050d5229de23 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Fri, 3 Jun 2022 23:42:41 +0200 Subject: [PATCH 09/20] Allowing the user to choose a thread by inserting the thread link --- .DS_Store | Bin 0 -> 6148 bytes .env.template | 6 ++- .idea/.gitignore | 3 ++ .idea/RedditVideoMakerBot.iml | 14 +++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ reddit/subreddit.py | 39 +++++++++++------- 9 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/RedditVideoMakerBot.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d9fbee9a2d2bee2e47c875e2dc0b7508612c6686 GIT binary patch literal 6148 zcmeHK%}T>S5Z<-5Nhm@N3OxqA7OX+k;w8lT0!H+pQWFw17_+5G?V%KM))(?gd>&_Z zH-})rn~0q$yWi~m>}Edb{xHV4zlaYRvl(M1G(?U{i=esHwWWg*xtyb9MYJqtQ6{36 ziTU6hzhG7|f<34y2%b*O)Md63@TO3^pkwvv0 zM%QVwoZ7qRA}_-J%3)ciHMIw;m3urII_~Modg!di zF6c*NcfGdEz5Ro;%jt9Wl8ZM*BnQr=>}agv9h62*ufaUeME(f&I;V~$BnF59Vt^Rf zJO=bxVD>k!bgGybAO?P50QUz68ltDMQYg0$=km;3^&Lj*jy*Rti-*<8oz~N3UEzUbtKx?2Zg)+*3$BF+dD78R)2?jpzRb{AF4n z`OOp>5d*})KVyJ*C&9#rqV(DNtvozy9cT~GP%y4S1qAfQB>)Dvj|`+!`5n|D&eK>a V#97cT(*fxsAPJ$482AMSz5umqOj-Z{ literal 0 HcmV?d00001 diff --git a/.env.template b/.env.template index f00c2ac..9e2218f 100644 --- a/.env.template +++ b/.env.template @@ -1,10 +1,14 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" + REDDIT_USERNAME="" REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" +SUBREDDIT="askReddit" -SUBREDDIT="" +# Link of the thread +# (e.g. https://www.reddit.com/r/memes/comments/sbr31o/discordggrmemes_the_official_rmemes_discord_server/) +THREAD="" \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/RedditVideoMakerBot.iml b/.idea/RedditVideoMakerBot.iml new file mode 100644 index 0000000..8e5446a --- /dev/null +++ b/.idea/RedditVideoMakerBot.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..653ebc1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1fd5644 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..c2f6547 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -13,7 +13,6 @@ def get_subreddit_threads(): load_dotenv() - print_step("Getting AskReddit threads...") if os.getenv("REDDIT_2FA").lower() == "yes": print( @@ -35,24 +34,36 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) + # If the user inserts a thread link, pick that one + if os.getenv("THREAD_LINK"): - if os.getenv("SUBREDDIT"): - subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + print_step(f"Getting the inserted thread...") + + thread_id = os.getenv("THREAD_LINK").split("/")[6] + submission = reddit.submission(thread_id) 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.") + # Otherwise, picks a random thread from the inserted subreddit + if os.getenv("SUBREDDIT"): + subreddit_name = os.getenv("SUBREDDIT") + print_step(f"Getting a random thread from r/{subreddit_name}") + subreddit = reddit.subreddit(subreddit_name) + 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)] + + - threads = subreddit.hot(limit=25) - submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") try: - content["thread_url"] = submission.url content["thread_title"] = submission.title content["comments"] = [] From 5555b80bc8c39e90309e6edb8bb4f021f5bcc058 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 01:00:08 +0200 Subject: [PATCH 10/20] Removed IDE files from git tracking Removed IDE files from git tracking Removed IDE files from git tracking --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 4 +++- .idea/.gitignore | 3 --- .idea/RedditVideoMakerBot.iml | 14 -------------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 8 files changed, 3 insertions(+), 42 deletions(-) delete mode 100644 .DS_Store delete mode 100644 .idea/.gitignore delete mode 100644 .idea/RedditVideoMakerBot.iml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index d9fbee9a2d2bee2e47c875e2dc0b7508612c6686..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z<-5Nhm@N3OxqA7OX+k;w8lT0!H+pQWFw17_+5G?V%KM))(?gd>&_Z zH-})rn~0q$yWi~m>}Edb{xHV4zlaYRvl(M1G(?U{i=esHwWWg*xtyb9MYJqtQ6{36 ziTU6hzhG7|f<34y2%b*O)Md63@TO3^pkwvv0 zM%QVwoZ7qRA}_-J%3)ciHMIw;m3urII_~Modg!di zF6c*NcfGdEz5Ro;%jt9Wl8ZM*BnQr=>}agv9h62*ufaUeME(f&I;V~$BnF59Vt^Rf zJO=bxVD>k!bgGybAO?P50QUz68ltDMQYg0$=km;3^&Lj*jy*Rti-*<8oz~N3UEzUbtKx?2Zg)+*3$BF+dD78R)2?jpzRb{AF4n z`OOp>5d*})KVyJ*C&9#rqV(DNtvozy9cT~GP%y4S1qAfQB>)Dvj|`+!`5n|D&eK>a V#97cT(*fxsAPJ$482AMSz5umqOj-Z{ diff --git a/.gitignore b/.gitignore index b541305..28b6807 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ assets/ .env reddit-bot-351418-5560ebc49cac.json -__pycache__ \ No newline at end of file +__pycache__ +.idea/ +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/RedditVideoMakerBot.iml b/.idea/RedditVideoMakerBot.iml deleted file mode 100644 index 8e5446a..0000000 --- a/.idea/RedditVideoMakerBot.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 653ebc1..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 1fd5644..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From d3b288008fbe1f67f9fcddcbf17783493f339ddf Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:03:13 +1000 Subject: [PATCH 11/20] Changed function name to match new version --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 09f4477..1f49152 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -4,7 +4,7 @@ import random from dotenv import load_dotenv import os -def get_askreddit_threads(): +def get_subreddit_threads(): global submission """ Returns a list of threads from the AskReddit subreddit. From 367105fb2dd33cdbf1ae6730036509d82e00531e Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:04:30 +1000 Subject: [PATCH 12/20] Changed file import name and resolved conflicts --- video_creation/final_video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index ba169f0..366f61d 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -7,7 +7,7 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.askreddit +import reddit.subreddit import re from utils.console import print_step @@ -58,7 +58,7 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.askreddit.submission.title + ".mp4"))) + filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))) final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") for i in range(0, number_of_clips): pass From d59fb5bdf28b1158845f094cb25913262e3bea45 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 09:53:23 +0200 Subject: [PATCH 13/20] Changed THREAD to THREAD_LINK inside .env.template --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 9e2218f..c2a2fcf 100644 --- a/.env.template +++ b/.env.template @@ -11,4 +11,4 @@ SUBREDDIT="askReddit" # Link of the thread # (e.g. https://www.reddit.com/r/memes/comments/sbr31o/discordggrmemes_the_official_rmemes_discord_server/) -THREAD="" \ No newline at end of file +THREAD_LINK="" \ No newline at end of file From 0dc32154f2ccce46daf1d5751a9d4f5426e6c5bc Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:16:02 +0100 Subject: [PATCH 14/20] Code was placed in the wrong place --- main.py | 6 ++++++ video_creation/final_video.py | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index fc12206..3bc6c83 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,12 @@ for val in REQUIRED_VALUES: print(f"Please set the variable \"{val}\" in your .env file.") configured = False +try: + float(os.getenv("OPACITY")) +except: + print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file") + configured = False + if configured: reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 0a2afb0..1933db3 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -30,11 +30,7 @@ def make_final_video(number_of_clips): .resize(height=H) .crop(x1=1166.6, y1=0, x2=2246.6, y2=1920) ) - try: - float(os.getenv("OPACITY")) - except: - print(f"Please ensure that OPACITY is set between 0 and 1 in your .env file") - configured = False + # Gather all audio clips audio_clips = [] for i in range(0, number_of_clips): From 48688f18c642177cda0a9eb421ce0c3c126c0f42 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:19:58 +0100 Subject: [PATCH 15/20] Remove code duplication --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 3bc6c83..1b66e8c 100644 --- a/main.py +++ b/main.py @@ -7,8 +7,6 @@ from video_creation.final_video import make_final_video from dotenv import load_dotenv import os, time, shutil -REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD"] - REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] print_markdown( From 211b03e7f5cc4e8c92778f50d80cf9e82f83790c Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 00:31:59 +0200 Subject: [PATCH 16/20] stickied comments will no longer be used I made a video but it was taken up entirely by a post looking like this: https://imgur.com/a/1fwT94c This isn't a big deal because these serious tags are uncommon, but still a small annoyance. So I fixed it! In threads that are marked 'serious', there is an automatic stickied mod post. ex. (shorturl.at/I1346). My changes will skip any automatically stickied comments, so they won't make it into the final Video. --- reddit/subreddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 1d47974..063b862 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -56,6 +56,7 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: + if not top_level_comment.stickied: content["comments"].append( { "comment_body": top_level_comment.body, From f51cbbce4d95a3427eb14f22fe59f6135052f5c0 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 11:10:03 +0200 Subject: [PATCH 17/20] The script asks the user for the thread link in the console --- .env.template | 5 ++--- reddit/subreddit.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.env.template b/.env.template index 25936d2..9385e68 100644 --- a/.env.template +++ b/.env.template @@ -12,6 +12,5 @@ SUBREDDIT="askReddit" THEME="" -# Link of the thread -# (e.g. https://www.reddit.com/r/memes/comments/sbr31o/discordggrmemes_the_official_rmemes_discord_server/) -THREAD_LINK="" \ No newline at end of file +#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. +RANDOM_THREAD="no" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c2f6547..b83b0e3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,3 +1,6 @@ +from webbrowser import get + +from click import style from utils.console import print_markdown, print_step, print_substep import praw import random @@ -34,12 +37,12 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) - # If the user inserts a thread link, pick that one - if os.getenv("THREAD_LINK"): - + # If the user specifies that he doesnt want a random thread, or if he doesn't insert the "RANDOM_THREAD" variable at all, ask the thread link + if not os.getenv("RANDOM_THREAD") or os.getenv("RANDOM_THREAD") == "no": + print_substep("Insert the full thread link:", style="bold green") + thread_link = input() print_step(f"Getting the inserted thread...") - - thread_id = os.getenv("THREAD_LINK").split("/")[6] + thread_id = thread_link.split("/")[6] submission = reddit.submission(thread_id) else: # Otherwise, picks a random thread from the inserted subreddit From aa67002b903bf7db3c7ab933c6e9471481518b68 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 17:15:39 +0200 Subject: [PATCH 18/20] Modified readme and removed a useless line of code --- README.md | 21 +++++++++++---------- reddit/subreddit.py | 3 +-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index dbb0250..f9d8c12 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ All done WITHOUT video editing or asset compiling. Just pure โœจprogramming magi Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) [ + @@ -20,13 +21,13 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Disclaimers ๐Ÿšจ -- This is purely for fun purposes. -- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues. +- This is purely for fun purposes. +- **At the moment**, this repository won't attempt to upload this content through this bot. It will give you a file that you will then have to upload manually. This is for the sake of avoiding any sort of community guideline issues. ## Requirements -- Python 3.6+ -- Playwright (this should install automatically during installation) +- Python 3.6+ +- Playwright (this should install automatically during installation) ## Installation ๐Ÿ‘ฉโ€๐Ÿ’ป @@ -38,7 +39,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 6. Enjoy ๐Ÿ˜Ž If you want to see more detailed guide, please refer to the official [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). -*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! +\*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve ๐Ÿ“ˆ @@ -46,8 +47,8 @@ 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! -- [ ] 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. +- [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. diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e74b8a1..16bbb79 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -39,8 +39,7 @@ def get_subreddit_threads(): print_substep("Insert the full thread link:", style="bold green") thread_link = input() print_step(f"Getting the inserted thread...") - thread_id = thread_link.split("/")[6] - submission = reddit.submission(thread_id) + submission = reddit.submission(url=thread_link) else: # Otherwise, picks a random thread from the inserted subreddit if os.getenv("SUBREDDIT"): From 42f364d6227186253702e2aadd76aec29479631e Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 13:48:58 -0400 Subject: [PATCH 19/20] Revert "Add Option for Male Voice" --- .env.template | 5 +---- main.py | 4 ++-- reddit/subreddit.py | 20 +++++++++----------- video_creation/voices.py | 22 +++++----------------- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/.env.template b/.env.template index 5c66be2..cab265e 100644 --- a/.env.template +++ b/.env.template @@ -2,10 +2,7 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -# Valid options are "female" and "male" -VOICE="female" - -# Valid options are "yes" and "no" for the variable below +# Valid options are "yes" and "no" REDDIT_2FA="" # Valid options are "light" and "dark" diff --git a/main.py b/main.py index 32f55e9..1b66e8c 100644 --- a/main.py +++ b/main.py @@ -35,8 +35,8 @@ except: configured = False if configured: - reddit_object = get_subreddit_threads(os.getenv("VOICE")) - length, number_of_comments = save_text_to_mp3(reddit_object, os.getenv("VOICE")) + reddit_object = get_subreddit_threads() + length, number_of_comments = save_text_to_mp3(reddit_object) download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) download_background() chop_background_video(length) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e9518a5..61c909d 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -2,7 +2,7 @@ from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv import os, random, praw, re -def get_subreddit_threads(voice): +def get_subreddit_threads(): global submission """ Returns a list of threads from the AskReddit subreddit. @@ -55,16 +55,14 @@ def get_subreddit_threads(voice): content["comments"] = [] for top_level_comment in submission.comments: - if voice == "male" and len(top_level_comment.body) > 550: - continue - if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not top_level_comment.stickied: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass diff --git a/video_creation/voices.py b/video_creation/voices.py index bc14095..e8d8e43 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,10 +3,9 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track -import requests -def save_text_to_mp3(reddit_obj, voice): +def save_text_to_mp3(reddit_obj): """Saves Text to MP3 files. Args: @@ -18,29 +17,18 @@ def save_text_to_mp3(reddit_obj, voice): # Create a folder for the mp3 files. Path("assets/mp3").mkdir(parents=True, exist_ok=True) - generate_and_save_tts(voice, reddit_obj["thread_title"], "assets/mp3/title.mp3") + tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False) + tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point if length > 50: break - - generate_and_save_tts(voice, comment["comment_body"], f"assets/mp3/{idx}.mp3") + tts = gTTS(text=comment["comment_body"], lang="en", slow=False) + tts.save(f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length print_substep("Saved Text to MP3 files successfully.", style="bold green") # ! Return the index so we know how many screenshots of comments we need to make. return length, idx - -def generate_and_save_tts(voice, text, file_name): - if voice == "female": - tts = gTTS(text=text, lang="en") - tts.save(file_name) - elif voice == "male": - url = 'https://streamlabs.com/polly/speak' - body = {'voice': 'Brian', 'text': text} - response = requests.post(url, data = body) - voice_data = requests.get(response.json()['speak_url']) - f = open(file_name, 'wb') - f.write(voice_data.content) \ No newline at end of file From e86c2bce041db04aa0f5971fea0021e5c7568d1e Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 14:06:51 -0400 Subject: [PATCH 20/20] Removed unused imports. --- reddit/subreddit.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 16bbb79..a518d24 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,10 +1,8 @@ -from webbrowser import get - -from click import style from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv import os, random, praw, re + def get_subreddit_threads(): global submission """ @@ -13,7 +11,6 @@ def get_subreddit_threads(): load_dotenv() - if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" @@ -48,7 +45,11 @@ def get_subreddit_threads(): # ! Prompt the user to enter a subreddit try: subreddit = reddit.subreddit( - re.sub(r"r\/", "", input("What subreddit would you like to pull from? ")) + re.sub( + r"r\/", + "", + input("What subreddit would you like to pull from? "), + ) ) except ValueError: subreddit = reddit.subreddit("askreddit") @@ -64,14 +65,14 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: - if not top_level_comment.stickied: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + if not top_level_comment.stickied: + content["comments"].append( + { + "comment_body": top_level_comment.body, + "comment_url": top_level_comment.permalink, + "comment_id": top_level_comment.id, + } + ) except AttributeError as e: pass