From b2bcb28f8f227ab86cecf6cdf29b37fbd1a86a83 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 13:30:04 -0500 Subject: [PATCH 01/19] Subreddit chooser (TEST) Allows user to choose a subreddit to pull from by taking user input. I will work on adding it to the .env file. --- main.py | 4 +- reddit/__pycache__/subreddit.cpython-310.pyc | Bin 0 -> 1489 bytes reddit/subreddit.py | 46 +++++++++++++++++++ utils/__pycache__/console.cpython-310.pyc | Bin 0 -> 1021 bytes 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 reddit/__pycache__/subreddit.cpython-310.pyc create mode 100644 reddit/subreddit.py create mode 100644 utils/__pycache__/console.cpython-310.pyc diff --git a/main.py b/main.py index 8fb3d50..02a0c65 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from utils.console import print_markdown 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.voices import save_text_to_mp3 from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts @@ -13,7 +13,7 @@ print_markdown( time.sleep(3) -reddit_object = get_askreddit_threads() +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) diff --git a/reddit/__pycache__/subreddit.cpython-310.pyc b/reddit/__pycache__/subreddit.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c166acac28375576942b299ac9b5c0f8482dd91c GIT binary patch literal 1489 zcmZuxOK&SR6t?G;$uvnHx4lvYf?2R25=!<}1vfO|Qi)q2DO6axM3dM}r=1xOwx>~| z1|gMgw`>5ZUGgXRA>OjOe}RX}@g%K^ghxIv+sEH|czC@YAQ+Wze;WPnBJ_t*o(>C? z7cgZP2t^bpD8&S)7O_&B*x1;t#34?}UE%__6ECfh%4*FgK6R-3BO+C54N%j21D;UR z){R`mnHr{%xS)KR>0qf##d2L=$;HU1M@_8P5+2bZ<%(sOW8>jrR6s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$jMd!Q# literal 0 HcmV?d00001 From 5f9bbfc22ceb919aa45a021f8123e9ef7fefa0cb Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 13:34:11 -0500 Subject: [PATCH 02/19] Fix misspellings --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c2dec66..33ef17b 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -22,7 +22,7 @@ def get_subreddit_threads(): password=os.getenv("REDDIT_PASSWORD"), ) subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) - threads = subreddot.hot(limit=25) + threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") try: From 8ec61b8fe24b0af64f2e94be96b02becdb01d500 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 13:40:44 -0500 Subject: [PATCH 03/19] Subreddit picker - .env Alternatively, you can specify which subreddit to pull from in the .env file. --- .env.template | 3 ++- reddit/subreddit.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index e00c242..e2c5798 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="" +SUBREDDIT="" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 33ef17b..6ddc661 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -10,7 +10,7 @@ def get_subreddit_threads(): Returns a list of threads from the AskReddit subreddit. """ - print_step("Getting AskReddit threads...") + print_step("Getting subreddit threads...") content = {} load_dotenv() @@ -21,7 +21,15 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=os.getenv("REDDIT_PASSWORD"), ) + """ + Ask user for subreddit input + """ subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) + + """ + Allow you to specify in .env. Done for automation purposes. + subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + """ threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") From 10ce9cac58323f03d1508a30cd4be14f56b90307 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 14:06:31 -0500 Subject: [PATCH 04/19] Polishing up Fixed misspelling. Issue appears differently in provided screenshot. --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 6ddc661..d71adb6 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -50,5 +50,5 @@ def get_subreddit_threads(): except AttributeError as e: pass - print_substep("Received subreddot threads Successfully.", style="bold green") + print_substep("Received subreddit threads Successfully.", style="bold green") return content From b1e1d07c8bf83db592e48928bc3973a53be10eb0 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 16:13:32 -0500 Subject: [PATCH 05/19] .env bool "ASK_EACH_TIME" Define whether or not you want to be asked each time what subreddit to pull from. Also, I ticked the box on the README. --- .env.template | 1 + README.md | 2 +- reddit/subreddit.py | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.env.template b/.env.template index e2c5798..c598b49 100644 --- a/.env.template +++ b/.env.template @@ -2,4 +2,5 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" +ASK_EACH_TIME=TRUE SUBREDDIT="" \ No newline at end of file diff --git a/README.md b/README.md index 26d8156..1d0507a 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,6 @@ I have tried to simplify the code so anyone can read it and start contibuting at - [ ] 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 between any subreddit. +- [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 d71adb6..c88220a 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -21,15 +21,20 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=os.getenv("REDDIT_PASSWORD"), ) - """ - Ask user for subreddit input - """ - subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) - - """ - Allow you to specify in .env. Done for automation purposes. - subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) - """ + + if os.getenv("ASK_EACH_TIME") == TRUE: + try: + subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) + except NameError: + subreddit = reddit.subreddit("askreddit") + print_substep("Subreddit not defined. Using AskReddit.") + else: + try: + subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + except NameError: + subreddit = reddit.subreddit("askreddit") + print_substep("Subreddit not defined. Using AskReddit.") + threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") From f12f0da76d848895528698357c5ea2db58e6af34 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 16:21:43 -0500 Subject: [PATCH 06/19] Change AET var to string, NameError to ValueError Python was giving errors with TRUE as a bool, so I changed it to a string. Giving an undefined name returned a different error than I put in the except, so I edited it and ran some tests which were successful. I will work on implementing something to detect if the subreddit exists and if it includes anything (e.g. special characters) which cannot be in subreddit names. --- .env.template | 2 +- reddit/subreddit.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.template b/.env.template index c598b49..68044bf 100644 --- a/.env.template +++ b/.env.template @@ -2,5 +2,5 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -ASK_EACH_TIME=TRUE +ASK_EACH_TIME="TRUE" SUBREDDIT="" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c88220a..53477d5 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -22,16 +22,16 @@ def get_subreddit_threads(): password=os.getenv("REDDIT_PASSWORD"), ) - if os.getenv("ASK_EACH_TIME") == TRUE: + if os.getenv("ASK_EACH_TIME") == "TRUE": try: subreddit = reddit.subreddit(input("What subreddit would you like to pull from? ")) - except NameError: + except ValueError: subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.") else: try: subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) - except NameError: + except ValueError: subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.") From d77dbaf0c0409da46750477e4c3c90e5bfe40aa7 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 16:37:30 -0500 Subject: [PATCH 07/19] Added playwright instructions I added instructions in the README to install playwright dependencies and fixed a misspelling in the Contributing section. --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d0507a..d7ae30a 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,16 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 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. 3. Run `pip3 install -r requirements.txt` -4. Run `python3 main.py` -5. ... -6. Enjoy 😎 +4. Run `playwright install` and `playwright install-deps`. +5. Run `python3 main.py` +6. ... +7. Enjoy 😎 ## Contributing & Ways to improve 📈 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 background that is picked instead of the Minecraft one. From e3eb67feeda06f66d4abb115eb90d027f83ca1db Mon Sep 17 00:00:00 2001 From: Ole <64090338+OlMi1@users.noreply.github.com> Date: Wed, 1 Jun 2022 09:37:06 +0200 Subject: [PATCH 08/19] Add download progress bar --- video_creation/background.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/video_creation/background.py b/video_creation/background.py index 20dbe73..302f815 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -1,5 +1,6 @@ from random import randrange from pytube import YouTube +from pytube.cli import on_progress from pathlib import Path from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.editor import VideoFileClip @@ -23,7 +24,7 @@ def download_background(): "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 🙏") - 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" ).first().download( "assets/mp4", From 810f297171865d402ccf51bc3be7509868e68d80 Mon Sep 17 00:00:00 2001 From: Ole <64090338+OlMi1@users.noreply.github.com> Date: Wed, 1 Jun 2022 09:37:57 +0200 Subject: [PATCH 09/19] and remove unnecessary line lol --- video_creation/background.py | 1 - 1 file changed, 1 deletion(-) diff --git a/video_creation/background.py b/video_creation/background.py index 302f815..d4b8e5f 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -12,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)) return random_time, random_time + video_length - def download_background(): """Downloads the background video from youtube. From 3d80e1016587e0825527842a7bbf907869b09678 Mon Sep 17 00:00:00 2001 From: Ole <64090338+OlMi1@users.noreply.github.com> Date: Wed, 1 Jun 2022 09:45:32 +0200 Subject: [PATCH 10/19] Update typed-ast version The one used (1.4.1) is long outdated and not recommended by maintainers. It can also lead to compile and installation errors. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index da87ca9..4aaff2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ rich==12.4.4 six==1.16.0 toml==0.10.1 tqdm==4.64.0 -typed-ast==1.4.1 +typed-ast==1.5.4 typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 From 0750673cc5658b2d6310b2bf50c80d05049bc83f Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Wed, 1 Jun 2022 13:19:33 +0100 Subject: [PATCH 11/19] Update regex version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4aaff2c..e464043 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,7 +28,7 @@ pyflakes==2.2.0 Pygments==2.12.0 python-dotenv==0.20.0 pytube==12.1.0 -regex==2020.10.15 +regex==2022.4.24 requests==2.27.1 rich==12.4.4 six==1.16.0 From 22b31bc71a39eb4160398d193fb54cc48e772e17 Mon Sep 17 00:00:00 2001 From: Owen Gaspard Date: Wed, 1 Jun 2022 07:46:55 -0500 Subject: [PATCH 12/19] Removed some files Removed unnecessary pycache files and askreddit.py Co-Authored-By: Aziz Mejri --- reddit/__pycache__/subreddit.cpython-310.pyc | Bin 1489 -> 0 bytes reddit/askreddit.py | 46 ------------------- utils/__pycache__/console.cpython-310.pyc | Bin 1021 -> 0 bytes 3 files changed, 46 deletions(-) delete mode 100644 reddit/__pycache__/subreddit.cpython-310.pyc delete mode 100644 reddit/askreddit.py delete mode 100644 utils/__pycache__/console.cpython-310.pyc diff --git a/reddit/__pycache__/subreddit.cpython-310.pyc b/reddit/__pycache__/subreddit.cpython-310.pyc deleted file mode 100644 index c166acac28375576942b299ac9b5c0f8482dd91c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1489 zcmZuxOK&SR6t?G;$uvnHx4lvYf?2R25=!<}1vfO|Qi)q2DO6axM3dM}r=1xOwx>~| z1|gMgw`>5Z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Och z-#vW(Z_d$qW|mcBBD0i{rIW)5O>l;^S>^HoxIW~qkk&)i;f8fHMdFVkLL<2yrjXV_ zOw~5*@tBWrjwYLqDU9Kvb=|eh&dVmO?nc_q5g*vFPBT=M_pJlR=$^pXV=I+Se2*s1 en6e57FN;bvxqO9x42}FoWJJ5C#{wtt$Nn$jMd!Q# From 4f4616a49f2723caf47d1f7c88d877ca1dff0bda Mon Sep 17 00:00:00 2001 From: Owen Gaspard Date: Wed, 1 Jun 2022 11:47:50 -0500 Subject: [PATCH 13/19] Console outputs subreddit Console will output the specified subreddit that you chose in .env if any --- reddit/subreddit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 53477d5..5814697 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -31,6 +31,7 @@ def get_subreddit_threads(): else: try: subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + print_substep(f"Using subreddit {os.getenv('SUBREDDIT')}") except ValueError: subreddit = reddit.subreddit("askreddit") print_substep("Subreddit not defined. Using AskReddit.") From 6742a53889bf9039a108067e03d732178ddd1d77 Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Thu, 2 Jun 2022 11:57:37 -0500 Subject: [PATCH 14/19] overhaul --- .env.template | 4 +++- .gitignore | 3 ++- README.md | 4 ++-- main.py | 2 +- reddit/askreddit.py | 18 +++++++++++++---- requirements.txt | 4 ++-- video_creation/background.py | 27 ++++++++++++++----------- video_creation/final_video.py | 2 +- video_creation/screenshot_downloader.py | 4 ++-- video_creation/test.py | 0 video_creation/voices.py | 8 ++++---- 11 files changed, 46 insertions(+), 30 deletions(-) delete mode 100644 video_creation/test.py diff --git a/.env.template b/.env.template index e00c242..ef95522 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,6 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" -REDDIT_PASSWORD="" \ No newline at end of file +REDDIT_PASSWORD="" +# Valid options are "yes" and "no" for the variable below +REDDIT_2FA="" \ No newline at end of file diff --git a/.gitignore b/.gitignore index a4589e5..b541305 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ assets/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +__pycache__ \ No newline at end of file diff --git a/README.md b/README.md index 26d8156..24a4d68 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Requirements - Python 3.6+ -- Playwright (this should install automatically in installation) +- Playwright (this should install automatically during installation) ## Installation 👩‍💻 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` file, along with whether your account uses two-factor authentication. 3. Run `pip3 install -r requirements.txt` 4. Run `python3 main.py` 5. ... diff --git a/main.py b/main.py index 8fb3d50..474a062 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ from video_creation.screenshot_downloader import download_screenshots_of_reddit_ from video_creation.final_video import make_final_video 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." + "### 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." ) time.sleep(3) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..a70fbe3 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -10,21 +10,31 @@ def get_askreddit_threads(): Returns a list of threads from the AskReddit subreddit. """ + load_dotenv() + print_step("Getting AskReddit threads...") + if os.getenv("REDDIT_2FA") == "yes" or "YES": + print("\nEnter your two-factor authentication code from your authenticator app.\n") + code = input("> ") + print() + pw = os.getenv("REDDIT_PASSWORD") + passkey = f'{pw}:{code}' + else: + passkey = os.getenv("REDDIT_PASSWORD") + content = {} - load_dotenv() reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), user_agent="Accessing AskReddit threads", username=os.getenv("REDDIT_USERNAME"), - password=os.getenv("REDDIT_PASSWORD"), + password=passkey, ) askreddit = reddit.subreddit("askreddit") threads = askreddit.hot(limit=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}") try: content["thread_url"] = submission.url @@ -42,5 +52,5 @@ def get_askreddit_threads(): except AttributeError as e: pass - print_substep("Received AskReddit threads Successfully.", style="bold green") + print_substep("Received AskReddit threads successfully.", style="bold green") return content diff --git a/requirements.txt b/requirements.txt index da87ca9..d9ffcf9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ mccabe==0.6.1 moviepy==1.0.3 mutagen==1.45.1 mypy-extensions==0.4.3 -numpy==1.22.3 +numpy pathspec==0.8.0 Pillow==9.1.1 playwright==1.22.0 @@ -27,7 +27,6 @@ pyee==8.1.0 pyflakes==2.2.0 Pygments==2.12.0 python-dotenv==0.20.0 -pytube==12.1.0 regex==2020.10.15 requests==2.27.1 rich==12.4.4 @@ -40,3 +39,4 @@ update-checker==0.18.0 urllib3==1.26.9 websocket-client==1.3.2 websockets==10.1 +yt-dlp \ No newline at end of file diff --git a/video_creation/background.py b/video_creation/background.py index 20dbe73..e917b70 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -1,5 +1,5 @@ from random import randrange -from pytube import YouTube +from yt_dlp import YoutubeDL from pathlib import Path from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip from moviepy.editor import VideoFileClip @@ -20,20 +20,23 @@ def download_background(): if not Path("assets/mp4/background.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 Minecraft background video. This is fairly large but it's only done once." ) - print_substep("Downloading the background video... please be patient 🙏") - YouTube("https://www.youtube.com/watch?v=n_Dv4JMiwK8").streams.filter( - res="720p" - ).first().download( - "assets/mp4", - filename="background.mp4", - ) - print_substep("Background video downloaded successfully! 🎉", style="bold green") + print_substep("Downloading the background video... please be patient.") + + ydl_opts = { + 'outtmpl': 'assets/mp4/background', + 'merge_output_format': 'mp4', + } + + with YoutubeDL(ydl_opts) as ydl: + ydl.download("https://www.youtube.com/watch?v=n_Dv4JMiwK8") + + print_substep("Background video downloaded successfully!", style="bold green") def chop_background_video(video_length): - print_step("Finding a spot in the background video to chop...✂️") + print_step("Finding a spot in the background video to chop...") background = VideoFileClip("assets/mp4/background.mp4") start_time, end_time = get_start_and_end_times(video_length, background.duration) @@ -43,4 +46,4 @@ def chop_background_video(video_length): end_time, targetname="assets/mp4/clip.mp4", ) - print_substep("Background video chopped successfully! 🎉", style="bold green") + print_substep("Background video chopped successfully!", style="bold green") diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 947ab04..e1f71ff 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -14,7 +14,7 @@ W, H = 1080, 1920 def make_final_video(number_of_clips): - print_step("Creating the final video 🎥") + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 66c96f1..91fed8a 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -28,7 +28,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. - print_substep("Post is NSFW. You are spicy... :fire:") + print_substep("Post is NSFW. You are spicy...") page.locator('[data-testid="content-gate"] button').click() page.locator('[data-test-id="post-content"]').screenshot( @@ -50,4 +50,4 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): page.locator(f"#t1_{comment['comment_id']}").screenshot( path=f"assets/png/comment_{idx}.png" ) - print_substep("Screenshots downloaded Successfully.", style="bold green") + print_substep("Screenshots downloaded successfully.", style="bold green") diff --git a/video_creation/test.py b/video_creation/test.py deleted file mode 100644 index e69de29..0000000 diff --git a/video_creation/voices.py b/video_creation/voices.py index d719ff9..e8d8e43 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -11,13 +11,13 @@ def save_text_to_mp3(reddit_obj): Args: reddit_obj : The reddit object you received from the reddit API in the askreddit.py file. """ - print_step("Saving Text to MP3 files 🎶") + print_step("Saving Text to MP3 files...") length = 0 # 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 = 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 @@ -25,10 +25,10 @@ def save_text_to_mp3(reddit_obj): # ! 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 = 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") + 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 From b05ac18476407285862a66d758050df90fd41038 Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Thu, 2 Jun 2022 12:15:34 -0500 Subject: [PATCH 15/19] finished requirements.txt --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index d9ffcf9..b2f5ee4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ mccabe==0.6.1 moviepy==1.0.3 mutagen==1.45.1 mypy-extensions==0.4.3 -numpy +numpy==1.15.1 pathspec==0.8.0 Pillow==9.1.1 playwright==1.22.0 @@ -39,4 +39,4 @@ update-checker==0.18.0 urllib3==1.26.9 websocket-client==1.3.2 websockets==10.1 -yt-dlp \ No newline at end of file +yt-dlp==2022.5.18 \ No newline at end of file From 9bb116793a3f0a209fbb61aecd228141c469ae02 Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Thu, 2 Jun 2022 14:11:32 -0400 Subject: [PATCH 16/19] Updated the .env.template to be a little easier to deal with. --- .env.template | 2 +- reddit/subreddit.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.env.template b/.env.template index 68044bf..dab64d3 100644 --- a/.env.template +++ b/.env.template @@ -2,5 +2,5 @@ REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -ASK_EACH_TIME="TRUE" + SUBREDDIT="" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5814697..27e21c2 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -22,16 +22,14 @@ def get_subreddit_threads(): password=os.getenv("REDDIT_PASSWORD"), ) - if os.getenv("ASK_EACH_TIME") == "TRUE": - 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.") + if os.getenv("SUBREDDIT"): + subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) else: + # ! Prompt the user to enter a subreddit try: - subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) - print_substep(f"Using subreddit {os.getenv('SUBREDDIT')}") + 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.") From 45e3a1144012b1dc5b9a1ced9402812ee0e5d52c Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Thu, 2 Jun 2022 14:51:34 -0400 Subject: [PATCH 17/19] Refactored for easier merging and fixed dependencies. --- main.py | 2 +- reddit/{askreddit.py => subreddit.py} | 10 ++++++---- requirements.txt | 2 +- video_creation/background.py | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) rename reddit/{askreddit.py => subreddit.py} (86%) diff --git a/main.py b/main.py index 474a062..1aa85d2 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from utils.console import print_markdown import time -from reddit.askreddit import get_askreddit_threads +from reddit.subreddit import get_askreddit_threads 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 diff --git a/reddit/askreddit.py b/reddit/subreddit.py similarity index 86% rename from reddit/askreddit.py rename to reddit/subreddit.py index a70fbe3..8c79ed9 100644 --- a/reddit/askreddit.py +++ b/reddit/subreddit.py @@ -13,13 +13,15 @@ def get_askreddit_threads(): load_dotenv() print_step("Getting AskReddit threads...") - - if os.getenv("REDDIT_2FA") == "yes" or "YES": - print("\nEnter your two-factor authentication code from your authenticator app.\n") + print(os.getenv("REDDIT_2FA")) + if os.getenv("REDDIT_2FA").lower() == "yes": + print( + "\nEnter your two-factor authentication code from your authenticator app.\n" + ) code = input("> ") print() pw = os.getenv("REDDIT_PASSWORD") - passkey = f'{pw}:{code}' + passkey = f"{pw}:{code}" else: passkey = os.getenv("REDDIT_PASSWORD") diff --git a/requirements.txt b/requirements.txt index b2f5ee4..8c5cc8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ mccabe==0.6.1 moviepy==1.0.3 mutagen==1.45.1 mypy-extensions==0.4.3 -numpy==1.15.1 +numpy==1.22.3 pathspec==0.8.0 Pillow==9.1.1 playwright==1.22.0 diff --git a/video_creation/background.py b/video_creation/background.py index e917b70..6884221 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -25,8 +25,8 @@ def download_background(): print_substep("Downloading the background video... please be patient.") ydl_opts = { - 'outtmpl': 'assets/mp4/background', - 'merge_output_format': 'mp4', + "outtmpl": "assets/mp4/background.mp4", + "merge_output_format": "mp4", } with YoutubeDL(ydl_opts) as ydl: From 49c1a8965801d059abb3cdf8bf48a610277f9fae Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Thu, 2 Jun 2022 14:57:53 -0400 Subject: [PATCH 18/19] Fixed merge Issues --- reddit/subreddit.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index cd18f6c..5d020fe 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -5,18 +5,16 @@ from dotenv import load_dotenv import os - def get_subreddit_threads(): """ Returns a list of threads from the AskReddit subreddit. """ - load_dotenv() print_step("Getting AskReddit threads...") - print(os.getenv("REDDIT_2FA")) + if os.getenv("REDDIT_2FA").lower() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" @@ -37,10 +35,6 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) - askreddit = reddit.subreddit("askreddit") - threads = askreddit.hot(limit=25) - submission = list(threads)[random.randrange(0, 25)] - print_substep(f"Video will be: {submission.title}") if os.getenv("SUBREDDIT"): subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) From 374ece3915126e8d5d11987fd7085961c5390d6f Mon Sep 17 00:00:00 2001 From: Vardhaman <83634399+cyai@users.noreply.github.com> Date: Fri, 3 Jun 2022 19:32:59 +0530 Subject: [PATCH 19/19] Removed extra installation step I removed the extra installation step which was not necessary! --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 00e30da..1d292a8 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 3. Run `pip3 install -r requirements.txt` 4. Run `playwright install` and `playwright install-deps`. 5. Run `python3 main.py` -6. ... -7. Enjoy 😎 +6. Enjoy 😎 ## Contributing & Ways to improve 📈