From b2bcb28f8f227ab86cecf6cdf29b37fbd1a86a83 Mon Sep 17 00:00:00 2001 From: owengaspard Date: Tue, 31 May 2022 13:30:04 -0500 Subject: [PATCH 001/152] 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>jrR6sB>9Ke)+15tqT z8e%YP(M)UVTU%x`Mv5(9ONbCD(f`D(7 zmW?iYy|HkOzKd=*uiW!3n9pEt)6HK18AjiId4jSn2dSM|fziSPuigpz2GOmB_q~_7 zOFqR@1ouCq+jQr~!f*p*_xZdNgfRL{6(W;i6eh7$AwLb(nP3r>;i=#$C@k#Ai$0?? zR-r6LqLfQDDX`sX0Bu--` zFlh7juVc!1IE`V~i0y^*wQx_J73oM8`5pt>oc| z(-~QN(9EIWL5b@X{EXg=b__@qC!DOO^~*Y0{YehQvE?;?GaoXFO%?NhI?~&~}%Pi!$Hs zm$CY^7`2z7m(_a}T`=)6SMBAE?Z*tX@|oU&ybK>L!xau6u8=Q)_^xAl*ug%0R!P0T z8kHK}##^8VRsgoZ^08w%u*>fjN5Vf6Tll{oH^n?ULx#qGF5=Vq8iUgNd6|Fc}LNvSf?xxL`Y)9=@<+Q!_ z${CLQrCd4nFK}YU*`iVejxv6pop|27nXSTbKwzDG{4zaeg#5t6{pG-67hZh=Mi4=B zQczAQVwSVQ;f}>l?iL>REOzr=;d9?&FAs`7?^7b_n(%?>3ICe#p$J4D_K_Hip%`6L z9*XdY#9OzJg~YV=_o`A?xda&Or|L{p=OwxiQz5c)0nj^4OPK?3kL87#QT%YTpbmn( z_u$n}!5Cub6rfdCKN4oWDyf9|1Yk(VPh4@a?5JG&hgJ$#R`+?w-`Ec5JWzRBUv?25Mw6 zcE(hN0RB?L1E*Ev8Gud=K?S>EYx;*C4(Q=tKKYLxt((iai7EF_8*Q@r3MIhnRS!*o zrVl1&3VCs_#x~jFJ2L`rJLoFVM%ItuY}s!k`z`#H%uw6Ag&3=|{C5BtathtNf^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# 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 002/152] 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 003/152] 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 004/152] 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 005/152] .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 006/152] 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 007/152] 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 1f6eec71e0caedb11eda51d326faca0faad62969 Mon Sep 17 00:00:00 2001 From: Taras Chuiko Date: Wed, 1 Jun 2022 09:37:34 +0300 Subject: [PATCH 008/152] Added playwright install command to readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 26d8156..31351cb 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,10 @@ 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 `npx playwright install` +5. Run `python3 main.py` +6. ... +7. Enjoy 😎 ## Contributing & Ways to improve πŸ“ˆ 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 009/152] 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 010/152] 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 011/152] 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 012/152] 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 013/152] 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`>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>jrR6sB>9Ke)+15tqT z8e%YP(M)UVTU%x`Mv5(9ONbCD(f`D(7 zmW?iYy|HkOzKd=*uiW!3n9pEt)6HK18AjiId4jSn2dSM|fziSPuigpz2GOmB_q~_7 zOFqR@1ouCq+jQr~!f*p*_xZdNgfRL{6(W;i6eh7$AwLb(nP3r>;i=#$C@k#Ai$0?? zR-r6LqLfQDDX`sX0Bu--` zFlh7juVc!1IE`V~i0y^*wQx_J73oM8`5pt>oc| z(-~QN(9EIWL5b@X{EXg=b__@qC!DOO^~*Y0{YehQvE?;?GaoXFO%?NhI?~&~}%Pi!$Hs zm$CY^7`2z7m(_a}T`=)6SMBAE?Z*tX@|oU&ybK>L!xau6u8=Q)_^xAl*ug%0R!P0T z8kHK}##^8VRsgoZ^08w%u*>fjN5Vf6Tll{oH^n?ULx#qGF5=Vq8iUgNd6|Fc}LNvSf?xxL`Y)9=@<+Q!_ z${CLQrCd4nFK}YU*`iVejxv6pop|27nXSTbKwzDG{4zaeg#5t6{pG-67hZh=Mi4=B zQczAQVwSVQ;f}>l?iL>REOzr=;d9?&FAs`7?^7b_n(%?>3ICe#p$J4D_K_Hip%`6L z9*XdY#9OzJg~YV=_o`A?xda&Or|L{p=OwxiQz5c)0nj^4OPK?3kL87#QT%YTpbmn( z_u$n}!5Cub6rfdCKN4oWDyf9|1Yk(VPh4@a?5JG&hgJ$#R`+?w-`Ec5JWzRBUv?25Mw6 zcE(hN0RB?L1E*Ev8Gud=K?S>EYx;*C4(Q=tKKYLxt((iai7EF_8*Q@r3MIhnRS!*o zrVl1&3VCs_#x~jFJ2L`rJLoFVM%ItuY}s!k`z`#H%uw6Ag&3=|{C5BtathtNf^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 014/152] 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 c03bd2ae82f9b19b8f9bfd039b06dedbac657c7b Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Wed, 1 Jun 2022 13:42:22 -0400 Subject: [PATCH 015/152] 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 4f3dcaf6944cd060806c6ed3e5de92d5e825d1ef Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Wed, 1 Jun 2022 14:33:35 -0400 Subject: [PATCH 016/152] add dark mode --- .env.template | 3 ++- main.py | 5 ++++- video_creation/cookies.json | 8 ++++++++ video_creation/screenshot_downloader.py | 11 +++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 video_creation/cookies.json diff --git a/.env.template b/.env.template index e00c242..3f49f24 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="" +THEME="" \ No newline at end of file diff --git a/main.py b/main.py index 8fb3d50..3453f6d 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,8 +17,9 @@ time.sleep(3) reddit_object = get_askreddit_threads() +load_dotenv() 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, os.getenv("THEME")) download_background() chop_background_video(length) final_video = make_final_video(number_of_comments) diff --git a/video_creation/cookies.json b/video_creation/cookies.json new file mode 100644 index 0000000..2e4e116 --- /dev/null +++ b/video_creation/cookies.json @@ -0,0 +1,8 @@ +[ + { + "name": "USER", + "value": "eyJwcmVmcyI6eyJ0b3BDb250ZW50RGlzbWlzc2FsVGltZSI6MCwiZ2xvYmFsVGhlbWUiOiJSRURESVQiLCJuaWdodG1vZGUiOnRydWUsImNvbGxhcHNlZFRyYXlTZWN0aW9ucyI6eyJmYXZvcml0ZXMiOmZhbHNlLCJtdWx0aXMiOmZhbHNlLCJtb2RlcmF0aW5nIjpmYWxzZSwic3Vic2NyaXB0aW9ucyI6ZmFsc2UsInByb2ZpbGVzIjpmYWxzZX0sInRvcENvbnRlbnRUaW1lc0Rpc21pc3NlZCI6MH19", + "domain": ".reddit.com", + "path": "/" + } +] diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 66c96f1..5cedabb 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -2,9 +2,10 @@ from playwright.sync_api import sync_playwright from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep +import json -def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): +def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): """Downloads screenshots of reddit posts as they are seen on the web. Args: @@ -20,9 +21,15 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): print_substep("Launching Headless Browser...") browser = p.chromium.launch() + context = browser.new_context() + + if theme == "dark": + cookie_file = open('video_creation/cookies.json') + cookies = json.load(cookie_file) + context.add_cookies(cookies) # Get the thread screenshot - page = browser.new_page() + page = context.new_page() page.goto(reddit_object["thread_url"]) if page.locator('[data-testid="content-gate"]').is_visible(): From f4b7ff736f60ba50c79fe8c2618ffc5dc5581933 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 19:46:51 -0400 Subject: [PATCH 017/152] .gitignore: Add pycaches --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a4589e5..3b9b9a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ assets/ +reddit/__pycache__/ +utils/__pycache__/ .env reddit-bot-351418-5560ebc49cac.json \ No newline at end of file From 39a691887eaec73c4fb41214ed906a37f7db5eb1 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:44:54 -0400 Subject: [PATCH 018/152] Create setup TUI and improve overall UX --- main.py | 48 ++++++++++++++++++++++- reddit/askreddit.py | 7 +++- requirements.txt | 2 +- setup.py | 96 +++++++++++++++++++++++++++++++++++++++++++++ utils/loader.py | 53 +++++++++++++++++++++++++ 5 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 setup.py create mode 100644 utils/loader.py diff --git a/main.py b/main.py index 8fb3d50..7e16291 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,61 @@ +# Main from utils.console import print_markdown +from utils.console import print_step +from utils.console import print_substep +from rich.console import Console import time +import os from reddit.askreddit 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 from video_creation.final_video import make_final_video - +from utils.loader import Loader +from dotenv import load_dotenv +console = Console() 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." ) +""" + +Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. +If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. + +""" + +client_id=os.getenv("REDDIT_CLIENT_ID") +client_secret=os.getenv("REDDIT_CLIENT_SECRET") +username=os.getenv("REDDIT_USERNAME") +password=os.getenv("REDDIT_PASSWORD") + +console.log("[bold green]Checking environment variables...") +time.sleep(1) + +if client_id == "" or client_secret == "" or username == "" or password == "": + + console.log("[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up.") + time.sleep(0.5) + console.log("[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program.") + setup_ask = input("Launch setup wizard? > ") + if setup_ask=="yes": + console.log("[bold green]Here goes nothing! Launching setup wizard...") + time.sleep(0.5) + os.system("python3 setup.py") + else: + if setup_ask=="no": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() + else: + console.print("[red]I don't understand that. Exiting...") + time.sleep(0.5) + exit() + + + exit() + +console.log("[bold green]Enviroment Variables are set! Continuing...") time.sleep(3) diff --git a/reddit/askreddit.py b/reddit/askreddit.py index 7c7110a..42afab4 100644 --- a/reddit/askreddit.py +++ b/reddit/askreddit.py @@ -1,9 +1,10 @@ +from rich import Console from utils.console import print_markdown, print_step, print_substep import praw import random from dotenv import load_dotenv import os - +console = Console() def get_askreddit_threads(): """ @@ -14,6 +15,7 @@ def get_askreddit_threads(): content = {} load_dotenv() + console.log("Logging in to reddit...") reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), @@ -25,6 +27,7 @@ def get_askreddit_threads(): threads = askreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] print_substep(f"Video will be: {submission.title} :thumbsup:") + console.log("Getting video comments...") try: content["thread_url"] = submission.url @@ -43,4 +46,4 @@ def get_askreddit_threads(): except AttributeError as e: pass print_substep("Received AskReddit threads Successfully.", style="bold green") - return content + return content \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index da87ca9..e90970b 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 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8214f72 --- /dev/null +++ b/setup.py @@ -0,0 +1,96 @@ +""" + +Setup Script for RedditVideoMakerBot + +""" + +# Imports +import os +import time +from utils.console import print_markdown +from utils.console import print_step +from utils.console import print_substep +from rich.console import Console +from utils.loader import Loader +console = Console() + +# These lines ensure the user: +# - knows they are in setup mode +# - knows that they are about to erase any other setup files/data. + +print_step("Setup Assistant") + +print_markdown( + "### You're in the setup wizard. Ensure you're supposed to be here, then type yes to continue. If you're not sure, type no to quit." +) + +# This Input is used to ensure the user is sure they want to continue. +ensureSetupIsRequired = input("Are you sure you want to continue? > ") +if ensureSetupIsRequired != "yes": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() +else: + # Again, let them know they are about to erase all other setup data. + console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") + overwriteSettings = input("Are you sure you want to continue? > ") + if overwriteSettings != "yes": + console.print("[red]Abort mission! Exiting...") + time.sleep(0.5) + exit() + else: + # Once they confirm, move on with the script. + console.print("[bold green]Alright! Let's get started!") + time.sleep(1) + +console.log("Ensure you have the following ready to enter:") +console.log("[bold green]Reddit Client ID") +console.log("[bold green]Reddit Client Secret") +console.log("[bold green]Reddit Username") +console.log("[bold green]Reddit Password") +time.sleep(0.5) +console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") +console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") +confirmUserHasCredentials = input("Are you sure you have the credentials? > ") +if confirmUserHasCredentials != "yes": + console.print("[red]I don't understand that.") + console.print("[red]Exiting...") + exit() +else: + console.print("[bold green]Alright! Let's get started!") + time.sleep(1) + +""" + +Begin the setup process. + +""" + +console.log("Enter your credentials now.") +cliID = input("Client ID > ") +cliSec = input("Client Secret > ") +user = input("Username > ") +passw = input("Password > ") +console.log("Attempting to save your credentials...") +loader = Loader("Saving Credentials...", "Done!").start() + # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... +time.sleep(0.5) +console.log("Removing old .env file...") +os.remove(".env") +time.sleep(0.5) +console.log("Creating new .env file...") +with open('.env', 'a') as f: + f.write(f'REDDIT_CLIENT_ID="{cliID}"\n') + time.sleep(0.5) + f.write(f'REDDIT_CLIENT_SECRET="{cliSec}"\n') + time.sleep(0.5) + f.write(f'REDDIT_USERNAME="{user}"\n') + time.sleep(0.5) + f.write(f'REDDIT_PASSWORD="{passw}"\n') + +loader.stop() + +console.log("[bold green]Setup Complete! Returning...") + +# Post-Setup: send message and try to run main.py again. +os.system("python3 main.py") \ No newline at end of file diff --git a/utils/loader.py b/utils/loader.py new file mode 100644 index 0000000..58fd662 --- /dev/null +++ b/utils/loader.py @@ -0,0 +1,53 @@ +""" + +Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it. +Although, it is edited to use less threads. + +""" +from itertools import cycle +from shutil import get_terminal_size +from threading import Thread +from time import sleep + + +class Loader: + def __init__(self, desc="Loading...", end="Done!", timeout=0.1): + """ + A loader-like context manager + + Args: + desc (str, optional): The loader's description. Defaults to "Loading...". + end (str, optional): Final print. Defaults to "Done!". + timeout (float, optional): Sleep time between prints. Defaults to 0.1. + """ + self.desc = desc + self.end = end + self.timeout = timeout + + self._thread = Thread(target=self._animate, daemon=True) + self.steps = ["β’Ώ", "β£»", "β£½", "β£Ύ", "β£·", "β£―", "⣟", "β‘Ώ"] + self.done = False + + def start(self): + self._thread.start() + return self + + def _animate(self): + for c in cycle(self.steps): + if self.done: + break + print(f"\r{self.desc} {c}", flush=True, end="") + sleep(self.timeout) + + def __enter__(self): + self.start() + + def stop(self): + self.done = True + cols = get_terminal_size((80, 20)).columns + print("\r" + " " * cols, end="", flush=True) + print(f"\r{self.end}", flush=True) + + def __exit__(self, exc_type, exc_value, tb): + # handle exceptions with those variables ^ + self.stop() \ No newline at end of file From 74363f021e73a3cad3ee7d0a2f229d2915a27607 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:48:26 -0400 Subject: [PATCH 019/152] README Updates --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26d8156..3b3acce 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## 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. -3. Run `pip3 install -r requirements.txt` -4. Run `python3 main.py` -5. ... +2. Run `pip3 install -r requirements.txt` +3. + 2a. **Automatic Setup** Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup** 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. + +4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 ## Contributing & Ways to improve πŸ“ˆ From 1e42fd2a3d6ccdfecf620e1c206273149b5f2d26 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:49:23 -0400 Subject: [PATCH 020/152] make readme look better --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b3acce..708b5ad 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup** Run `python3 main.py`, it will automatically detect that you do not have variables set - 2b. **Manual Setup** 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. + 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup**: 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. 4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 From 3c4eac42c097a7c4fe7a54cab6699ae325052fdd Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:49:46 -0400 Subject: [PATCH 021/152] maybe a *little* bit better --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 708b5ad..82d047d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 2. Run `pip3 install -r requirements.txt` 3. 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2b. **Manual Setup**: 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. 4. (only if you did manual setup) Run `python3 main.py` From e4ed7aa69e75538e194d6e75b4cc5e409cd62806 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:51:01 -0400 Subject: [PATCH 022/152] Clarification for setup. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82d047d..6369b4f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup**: Run `python3 main.py`, it will automatically detect that you do not have variables set + 2a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. 2b. **Manual Setup**: 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. From e03f52988837745f3c583d31525fb6f6132f08b4 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Wed, 1 Jun 2022 20:55:20 -0400 Subject: [PATCH 023/152] README: got some of the stages mixed up. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6369b4f..8e7eec7 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` 3. - 2a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. + 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. - 2b. **Manual Setup**: 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. + 3b. **Manual Setup**: 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. 4. (only if you did manual setup) Run `python3 main.py` 6. Enjoy 😎 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 024/152] 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 025/152] 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 026/152] 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 6742a53889bf9039a108067e03d732178ddd1d77 Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Thu, 2 Jun 2022 11:57:37 -0500 Subject: [PATCH 027/152] 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 16664e010a8d57a89acef3ad576143e8580c8330 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 13:11:10 -0400 Subject: [PATCH 028/152] Reviews: Various Changes --- main.py | 2 +- setup.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 7e16291..2c026ae 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,7 @@ password=os.getenv("REDDIT_PASSWORD") console.log("[bold green]Checking environment variables...") time.sleep(1) -if client_id == "" or client_secret == "" or username == "" or password == "": +if not all(client_id, client_secret, username, password): console.log("[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up.") time.sleep(0.5) diff --git a/setup.py b/setup.py index 8214f72..7e4521f 100644 --- a/setup.py +++ b/setup.py @@ -12,8 +12,15 @@ from utils.console import print_step from utils.console import print_substep from rich.console import Console from utils.loader import Loader +from os.path import exists console = Console() +setup_done = exists(".setup-done-before") + +if setup_done == True: + console.log("[red]Setup was already completed! Please make sure you have to run this script again. If you have to, please delete the file .setup-done-before") + exit() + # These lines ensure the user: # - knows they are in setup mode # - knows that they are about to erase any other setup files/data. @@ -25,7 +32,7 @@ print_markdown( ) # This Input is used to ensure the user is sure they want to continue. -ensureSetupIsRequired = input("Are you sure you want to continue? > ") +ensureSetupIsRequired = input("Are you sure you want to continue? > ").casefold() if ensureSetupIsRequired != "yes": console.print("[red]Exiting...") time.sleep(0.5) @@ -33,7 +40,7 @@ if ensureSetupIsRequired != "yes": else: # Again, let them know they are about to erase all other setup data. console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") - overwriteSettings = input("Are you sure you want to continue? > ") + overwriteSettings = input("Are you sure you want to continue? > ").casefold() if overwriteSettings != "yes": console.print("[red]Abort mission! Exiting...") time.sleep(0.5) @@ -51,7 +58,7 @@ console.log("[bold green]Reddit Password") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") -confirmUserHasCredentials = input("Are you sure you have the credentials? > ") +confirmUserHasCredentials = input("Are you sure you have the credentials? > ").casefold() if confirmUserHasCredentials != "yes": console.print("[red]I don't understand that.") console.print("[red]Exiting...") @@ -88,6 +95,9 @@ with open('.env', 'a') as f: time.sleep(0.5) f.write(f'REDDIT_PASSWORD="{passw}"\n') +with open('.setup-done-before', 'a') as f: + f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") + loader.stop() console.log("[bold green]Setup Complete! Returning...") From b05ac18476407285862a66d758050df90fd41038 Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Thu, 2 Jun 2022 12:15:34 -0500 Subject: [PATCH 029/152] 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 030/152] 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 031/152] 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 032/152] 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 654fec94c7c0fe8a4191da2623b76916c477291a Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Thu, 2 Jun 2022 20:37:22 +0100 Subject: [PATCH 033/152] Update dependencies Removed all unnecessary dependencies from requirements.txt --- requirements.txt | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/requirements.txt b/requirements.txt index 59dc596..fd28b7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,44 +1,8 @@ -appdirs==1.4.4 -black==20.8b1 -certifi==2021.10.8 -charset-normalizer==2.0.12 -click==7.1.2 -commonmark==0.9.1 -decorator==4.4.2 -flake8==3.8.3 -greenlet==1.1.2 gTTS==2.2.4 -idna==3.3 -imageio==2.19.2 -imageio-ffmpeg==0.4.7 -mccabe==0.6.1 moviepy==1.0.3 mutagen==1.45.1 -mypy-extensions==0.4.3 -numpy==1.22.3 -pathspec==0.8.0 -Pillow==9.1.1 playwright==1.22.0 praw==7.6.0 -prawcore==2.3.0 -proglog==0.1.10 -pycodestyle==2.6.0 -pyee==8.1.0 -pyflakes==2.2.0 -Pygments==2.12.0 python-dotenv==0.20.0 - -regex==2020.10.15 - -requests==2.27.1 rich==12.4.4 -six==1.16.0 -toml==0.10.1 -tqdm==4.64.0 -typed-ast==1.5.4 -typing_extensions==4.2.0 -update-checker==0.18.0 -urllib3==1.26.9 -websocket-client==1.3.2 -websockets==10.1 -yt-dlp==2022.5.18 \ No newline at end of file +yt_dlp==2022.5.18 From 593094d14b075eec523382154a84f25c043237e1 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 21:49:38 +0200 Subject: [PATCH 034/152] add Docker support --- .dockerignore | 1 + .gitignore | 4 +++- Dockerfile | 14 ++++++++++++++ build.sh | 1 + run.sh | 1 + video_creation/screenshot_downloader.py | 7 ++++--- 6 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 build.sh create mode 100755 run.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1d1fe94 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore index a4589e5..52b1988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ assets/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +__pycache__ +out \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9d7f280 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/playwright + +RUN apt update +RUN apt install python3-pip -y + +RUN mkdir /app +ADD . /app +WORKDIR /app +RUN pip install -r requirements.txt + +# tricks for pytube : https://github.com/elebumm/RedditVideoMakerBot/issues/142 +RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py + +CMD ["python3", "main.py"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7d4dfc6 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +docker build -t rvmt . \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..f2a150f --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +docker run -v $(pwd)/out/:/app/assets -it rvmt \ No newline at end of file diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 66c96f1..e5a5dbf 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,4 +1,4 @@ -from playwright.sync_api import sync_playwright +from playwright.sync_api import sync_playwright, ViewportSize from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep @@ -24,7 +24,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): # Get the thread screenshot page = browser.new_page() page.goto(reddit_object["thread_url"]) - + page.set_viewport_size(ViewportSize(width=1920, height=1080)) if page.locator('[data-testid="content-gate"]').is_visible(): # This means the post is NSFW and requires to click the proceed button. @@ -50,4 +50,5 @@ 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") From 52302cc42d7e399ccfaf47c94f37381f32fadfb9 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:09:47 -0400 Subject: [PATCH 035/152] gitignore - new files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3b9b9a4..d6b5611 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env -reddit-bot-351418-5560ebc49cac.json \ No newline at end of file +reddit-bot-351418-5560ebc49cac.json +video_creation/__pycache__/ +.setup-done-before \ No newline at end of file From 49de46dd539c1d75f77691fa348b0c85cf66862c Mon Sep 17 00:00:00 2001 From: andronedev <31452517+andronedev@users.noreply.github.com> Date: Thu, 2 Jun 2022 22:14:17 +0200 Subject: [PATCH 036/152] Update Dockerfile --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d7f280..1f68ea0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ WORKDIR /app RUN pip install -r requirements.txt # tricks for pytube : https://github.com/elebumm/RedditVideoMakerBot/issues/142 -RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py +# (NOTE : This is no longer useful since pytube was removed from the dependencies) +# RUN sed -i 's/re.compile(r"^\\w+\\W")/re.compile(r"^\\$*\\w+\\W")/' /usr/local/lib/python3.8/dist-packages/pytube/cipher.py -CMD ["python3", "main.py"] \ No newline at end of file +CMD ["python3", "main.py"] From 4506339e21f673e911f8f5badaee4d20d53c1c07 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:16:15 -0400 Subject: [PATCH 037/152] ACCEPT: Incoming Change (main.py) --- main.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/main.py b/main.py index f1782b2..498d78f 100644 --- a/main.py +++ b/main.py @@ -4,15 +4,8 @@ from utils.console import print_step from utils.console import print_substep from rich.console import Console import time -<<<<<<< HEAD import os -from reddit.askreddit import get_askreddit_threads -||||||| 5b39896 -from reddit.askreddit import get_askreddit_threads -======= - from reddit.subreddit import get_subreddit_threads ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 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 d8def59e5d583071c47eb89cbf86241574eb2808 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:17:48 -0400 Subject: [PATCH 038/152] ACCEPT: Incoming change. (README.md) --- README.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/README.md b/README.md index 05ae2df..1dbec21 100644 --- a/README.md +++ b/README.md @@ -31,29 +31,12 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## Installation πŸ‘©β€πŸ’» 1. Clone this repository -<<<<<<< HEAD -2. Run `pip3 install -r requirements.txt` -3. - 3a. **Automatic Setup**: Run `python3 main.py` and type "yes" where it says "Setup Wizard". The Setup Wizard will guide you through the setup process. - - 3b. **Manual Setup**: 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. - -4. (only if you did manual setup) Run `python3 main.py` -6. Enjoy 😎 -||||||| 5b39896 -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 😎 -======= 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 `playwright install` and `playwright install-deps`. 5. Run `python3 main.py` 6. ... 7. Enjoy 😎 ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 ## Contributing & Ways to improve πŸ“ˆ @@ -65,4 +48,4 @@ I have tried to simplify the code so anyone can read it and start contributing a - [ ] 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. +- [ ] Creating better documentation and adding a command line interface. \ No newline at end of file From b1c98726eb8389553c78882717877b7cc28251ed Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:20:35 -0400 Subject: [PATCH 039/152] README: Automatic install --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1dbec21..630cca4 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,14 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p ## 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` file, along with whether your account uses two-factor authentication. -3. Run `pip3 install -r requirements.txt` -4. Run `playwright install` and `playwright install-deps`. -5. Run `python3 main.py` +2. Run `pip3 install -r requirements.txt` +3. Run `playwright install` and `playwright install-deps`. +4. + 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. + + 4b **Manual Install**: 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. + +5. Run `python3 main.py` (unless you chose automatic install, then the installer will automatically run main.py) 6. ... 7. Enjoy 😎 From 3b26c0e282fd3e9cbd344fb154d6c5034c0310fa Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:22:07 -0400 Subject: [PATCH 040/152] main.py: Add REDDIT_2FA to env variable check. --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 498d78f..07f2f13 100644 --- a/main.py +++ b/main.py @@ -28,6 +28,8 @@ client_id=os.getenv("REDDIT_CLIENT_ID") client_secret=os.getenv("REDDIT_CLIENT_SECRET") username=os.getenv("REDDIT_USERNAME") password=os.getenv("REDDIT_PASSWORD") +reddit2fa=os.getenv("REDDIT_2FA") + console.log("[bold green]Checking environment variables...") time.sleep(1) From e18bb1229ac19f166389c67cbc6e4ef361b9e058 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:23:09 -0400 Subject: [PATCH 041/152] REQUIREMENTS.TXT: Accept Incoming Change --- requirements.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6ae7cfe..59dc596 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,13 +35,7 @@ rich==12.4.4 six==1.16.0 toml==0.10.1 tqdm==4.64.0 -<<<<<<< HEAD -typed-ast==1.5.4 # Please see issue https://github.com/elebumm/RedditVideoMakerBot/issues/16 comment three. -||||||| 5b39896 -typed-ast==1.4.1 -======= typed-ast==1.5.4 ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 typing_extensions==4.2.0 update-checker==0.18.0 urllib3==1.26.9 From 51d561bc3e479bd6cb5b5791411a6459b028d4d2 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:25:39 -0400 Subject: [PATCH 042/152] Removed an extra line in main.py; added 2fa to setup.py --- main.py | 2 +- setup.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 07f2f13..1882039 100644 --- a/main.py +++ b/main.py @@ -67,4 +67,4 @@ length, number_of_comments = save_text_to_mp3(reddit_object) download_screenshots_of_reddit_posts(reddit_object, number_of_comments) download_background() chop_background_video(length) -final_video = make_final_video(number_of_comments) +final_video = make_final_video(number_of_comments) \ No newline at end of file diff --git a/setup.py b/setup.py index 7e4521f..f49b03b 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ console.log("[bold green]Reddit Client ID") console.log("[bold green]Reddit Client Secret") console.log("[bold green]Reddit Username") console.log("[bold green]Reddit Password") +console.log("[bold green]Reddit 2FA (yes or no)") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") @@ -78,6 +79,7 @@ cliID = input("Client ID > ") cliSec = input("Client Secret > ") user = input("Username > ") passw = input("Password > ") +twofactor = input("2fa Enabled? (yes/no) > ") console.log("Attempting to save your credentials...") loader = Loader("Saving Credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... @@ -94,6 +96,8 @@ with open('.env', 'a') as f: f.write(f'REDDIT_USERNAME="{user}"\n') time.sleep(0.5) f.write(f'REDDIT_PASSWORD="{passw}"\n') + time.sleep(0.5) + f.write(f'REDDIT_2FA="{twofactor}"\n') with open('.setup-done-before', 'a') as f: f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") From 6b8b96665cb411a0ba89d964e05c411ff8eed48b Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Thu, 2 Jun 2022 16:26:32 -0400 Subject: [PATCH 043/152] Accept Incoming Change --- reddit/subreddit.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index ce4e342..e4a6e69 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -28,14 +28,6 @@ def get_subreddit_threads(): passkey = os.getenv("REDDIT_PASSWORD") content = {} -<<<<<<< HEAD:reddit/askreddit.py - load_dotenv() - console.log("Logging in to reddit...") -||||||| 5b39896:reddit/askreddit.py - load_dotenv() -======= - ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py reddit = praw.Reddit( client_id=os.getenv("REDDIT_CLIENT_ID"), client_secret=os.getenv("REDDIT_CLIENT_SECRET"), @@ -77,14 +69,6 @@ def get_subreddit_threads(): except AttributeError as e: pass -<<<<<<< HEAD:reddit/askreddit.py - print_substep("Received AskReddit threads Successfully.", style="bold green") - return content -||||||| 5b39896:reddit/askreddit.py - print_substep("Received AskReddit threads Successfully.", style="bold green") - return content -======= print_substep("Received AskReddit threads successfully.", style="bold green") return content ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9:reddit/subreddit.py From 030c7706c69905952fbc0e382a312c35e2c85f41 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 22:56:32 +0200 Subject: [PATCH 044/152] =?UTF-8?q?=E2=9C=A8feature:=20possibility=20to=20?= =?UTF-8?q?use=20an=20external=20.env=20instead=20of=20having=20to=20build?= =?UTF-8?q?=20the=20container=20for=20each=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index f2a150f..4dcb69a 100755 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -docker run -v $(pwd)/out/:/app/assets -it rvmt \ No newline at end of file +docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt \ No newline at end of file From d4bdad4d0f04a75e47bcd0af4e3465b242648866 Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Thu, 2 Jun 2022 16:16:28 -0500 Subject: [PATCH 045/152] checks off the custom background todo --- .env.template | 1 - .gitignore | 2 +- README.md | 2 +- main.py | 7 +++-- reddit/subreddit.py | 6 ++-- video_creation/background.py | 40 +++++++++++++++++++------ video_creation/screenshot_downloader.py | 2 +- 7 files changed, 42 insertions(+), 18 deletions(-) diff --git a/.env.template b/.env.template index f00c2ac..bed59c6 100644 --- a/.env.template +++ b/.env.template @@ -6,5 +6,4 @@ REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" - SUBREDDIT="" diff --git a/.gitignore b/.gitignore index b541305..ed5aa04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ assets/ .env reddit-bot-351418-5560ebc49cac.json -__pycache__ \ No newline at end of file +__pycache__/ \ No newline at end of file diff --git a/README.md b/README.md index 00e30da..cfe46c0 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ 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 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/main.py b/main.py index a5b64c6..7d280ed 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,9 @@ 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) -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) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..75f1a0b 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -8,12 +8,12 @@ import os def get_subreddit_threads(): """ - Returns a list of threads from the AskReddit subreddit. + Returns a list of threads from the provided subreddit. """ load_dotenv() - print_step("Getting AskReddit threads...") + print_step("Getting subbreddit threads...") if os.getenv("REDDIT_2FA").lower() == "yes": print( @@ -50,7 +50,7 @@ def get_subreddit_threads(): threads = subreddit.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 diff --git a/video_creation/background.py b/video_creation/background.py index dce46bd..99a2d96 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -7,45 +7,67 @@ 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(): +def download_background(video_length): """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 diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 91fed8a..bc5c640 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -11,7 +11,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num): 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) From bed5dd2ab2737735ff24fb9b9523382c2429e40b Mon Sep 17 00:00:00 2001 From: Kamushy <92086533+Kamushy@users.noreply.github.com> Date: Fri, 3 Jun 2022 09:18:05 +1000 Subject: [PATCH 046/152] Made ENV make more sense A couple were submitting links into the subreddit field --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index f00c2ac..033c9d9 100644 --- a/.env.template +++ b/.env.template @@ -6,5 +6,5 @@ REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" - +# Enter a subreddit, e.g. "AskReddit" or "r/AskReddit" SUBREDDIT="" 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 047/152] 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 048/152] 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 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 049/152] 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 πŸ“ˆ From c4f32a3821317ae039dadd0043b265a2619cf49e Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 00:48:20 +1000 Subject: [PATCH 050/152] TTS reads text below the tittle of the post Added option for TTS to read the whole post if text apart from tittle is present (useful for such threads as r/maliciouscompliance) --- subreddit.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 subreddit.py diff --git a/subreddit.py b/subreddit.py new file mode 100644 index 0000000..e9ae4fe --- /dev/null +++ b/subreddit.py @@ -0,0 +1,73 @@ +from utils.console import print_markdown, print_step, print_substep +import praw +import random +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...") + + 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}" + else: + passkey = os.getenv("REDDIT_PASSWORD") + + content = {} + + 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=passkey, + ) + + 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)] + print_substep(f"Video will be: {submission.title} :thumbsup:") + try: + + content["thread_url"] = submission.url + content["thread_title"] = submission.title + submission.selftext + content["comments"] = [] + + for top_level_comment in submission.comments: + 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 + print_substep("Received AskReddit threads successfully.", style="bold green") + + return content From 310006a166974580645570b8103f88cec7e25db0 Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 00:50:36 +1000 Subject: [PATCH 051/152] Deleting becasue i commited in the wrong way, whoops --- subreddit.py | 73 ---------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 subreddit.py diff --git a/subreddit.py b/subreddit.py deleted file mode 100644 index e9ae4fe..0000000 --- a/subreddit.py +++ /dev/null @@ -1,73 +0,0 @@ -from utils.console import print_markdown, print_step, print_substep -import praw -import random -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...") - - 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}" - else: - passkey = os.getenv("REDDIT_PASSWORD") - - content = {} - - 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=passkey, - ) - - 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)] - print_substep(f"Video will be: {submission.title} :thumbsup:") - try: - - content["thread_url"] = submission.url - content["thread_title"] = submission.title + submission.selftext - content["comments"] = [] - - for top_level_comment in submission.comments: - 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 - print_substep("Received AskReddit threads successfully.", style="bold green") - - return content From 89d69ff0af09d5904406ae04096460e106a9a59b Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 00:53:14 +1000 Subject: [PATCH 052/152] TTS update to read the text below tittle if there is any --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..e9ae4fe 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -54,7 +54,7 @@ def get_subreddit_threads(): try: content["thread_url"] = submission.url - content["thread_title"] = submission.title + content["thread_title"] = submission.title + submission.selftext content["comments"] = [] for top_level_comment in submission.comments: From 16f57bf4775fc72fab7bbd0f035a49dc3fac91cb Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Fri, 3 Jun 2022 17:23:49 +0100 Subject: [PATCH 053/152] Add casefold to ignore case in env file for theme --- video_creation/screenshot_downloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 744fc3e..4c4380a 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -23,7 +23,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): browser = p.chromium.launch() context = browser.new_context() - if theme == "dark": + if theme.casefold() == "dark": cookie_file = open('video_creation/cookies.json') cookies = json.load(cookie_file) context.add_cookies(cookies) From 6d1d06b530a5fd821532920e8ceed69314b638e0 Mon Sep 17 00:00:00 2001 From: Taras Chuiko Date: Fri, 3 Jun 2022 19:25:20 +0300 Subject: [PATCH 054/152] Used python instead of npx to install playwright --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31351cb..b8b8887 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ 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 `npx playwright install` +4. Run `python3 -m playwright install` 5. Run `python3 main.py` 6. ... 7. Enjoy 😎 From d746fabb6bfc23f110386426c3cd89a922795c6d Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Fri, 3 Jun 2022 11:57:04 -0500 Subject: [PATCH 055/152] idk what happened here but fixed it --- .env.template | 3 --- 1 file changed, 3 deletions(-) diff --git a/.env.template b/.env.template index 602769c..5ab4ae4 100644 --- a/.env.template +++ b/.env.template @@ -6,9 +6,6 @@ REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" -<<<<<<< HEAD -======= THEME="" ->>>>>>> 64fa33fd482ef63e8a75cca1a438a37e078aee48 SUBREDDIT="" From 20217be743aad2b7e2d30e608304eb1fc921c9da Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Fri, 3 Jun 2022 13:22:23 -0400 Subject: [PATCH 056/152] resolve gitignore conflict --- .gitignore | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.gitignore b/.gitignore index b85be09..6cf136b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,7 @@ assets/ reddit/__pycache__/ utils/__pycache__/ .env -<<<<<<< HEAD reddit-bot-351418-5560ebc49cac.json video_creation/__pycache__/ .setup-done-before -||||||| 5b39896 -reddit-bot-351418-5560ebc49cac.json -======= -reddit-bot-351418-5560ebc49cac.json __pycache__ ->>>>>>> 6fc5d2a7377dfe9f65d0d011fc260602527847c9 From 77f68b847c400409a2f19d37cdc1108b4f1ac0bb Mon Sep 17 00:00:00 2001 From: reoccurcat Date: Fri, 3 Jun 2022 12:31:05 -0500 Subject: [PATCH 057/152] fixed dark mode bug --- video_creation/screenshot_downloader.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 9b06ae0..4b07bd7 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -22,11 +22,14 @@ 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() From e8aca757a742b8cd0a1b62d1ad92ada686390fe4 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Fri, 3 Jun 2022 20:36:25 +0300 Subject: [PATCH 058/152] Added link to documentation Added link to the official documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1d292a8..d9b09fa 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 5. Run `python3 main.py` 6. Enjoy 😎 +If you want to see more detailed guide, refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/) + ## Contributing & Ways to improve πŸ“ˆ In its current state, this bot does exactly what it needs to do. However, lots of improvements can be made. From 338c278eaf37263643128f3cb213211e0813e285 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Fri, 3 Jun 2022 20:37:23 +0300 Subject: [PATCH 059/152] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9b09fa..0046364 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 5. Run `python3 main.py` 6. Enjoy 😎 -If you want to see more detailed guide, refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/) +If you want to see more detailed guide, please refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/). ## Contributing & Ways to improve πŸ“ˆ From 9d0728624c12a00bd90282be46e627fc326bee0d Mon Sep 17 00:00:00 2001 From: Freebie <69956546+FreebieII@users.noreply.github.com> Date: Fri, 3 Jun 2022 19:41:12 +0200 Subject: [PATCH 060/152] Added a disclaimer. Documentation is not fully developed yet. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0046364..10e84e9 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,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://immaharry.gitbook.io/reddit-automated-video-bot/). +*The Documentation is still being developed and worked on, please be patient as we change / add new knowledge! ## Contributing & Ways to improve πŸ“ˆ From 3f32feaa2466cd1136e6c2a1875654032e6ee14c Mon Sep 17 00:00:00 2001 From: Arjun Dureja Date: Fri, 3 Jun 2022 13:51:43 -0400 Subject: [PATCH 061/152] 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 062/152] 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 46aedb6afa1958ec43a6113c10bd6809c36243fd Mon Sep 17 00:00:00 2001 From: Hayden Date: Fri, 3 Jun 2022 13:35:31 -0500 Subject: [PATCH 063/152] Update subreddit.py --- reddit/subreddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 75f1a0b..c3350bc 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -13,7 +13,7 @@ def get_subreddit_threads(): load_dotenv() - print_step("Getting subbreddit threads...") + print_step("Getting subreddit threads...") if os.getenv("REDDIT_2FA").lower() == "yes": print( @@ -31,7 +31,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, ) From d858c1ca5f0365b000e7ddd114ac050d5229de23 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Fri, 3 Jun 2022 23:42:41 +0200 Subject: [PATCH 064/152] 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 6ec947523273e7ba6c09be85b2cd37e76bbe72bb Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 08:47:24 +1000 Subject: [PATCH 065/152] First 2 files of requested changes --- video_creation/final_video.py | 3 ++- video_creation/voices.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e1f71ff..7dd8d02 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -29,6 +29,7 @@ def make_final_video(number_of_clips): for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -44,7 +45,7 @@ def make_final_video(number_of_clips): image_clips.insert( 0, ImageClip(f"assets/png/title.png") - .set_duration(audio_clips[0].duration) + .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100), ) diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..b4650e6 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,6 +21,10 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length + tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) + tts.save(f"assets/mp3/posttext.mp3") + length += MP3(f"assets/mp3/posttext.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: From 2fbb369f8a70905f98a5b2b055e1f8073927d57c Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 08:48:10 +1000 Subject: [PATCH 066/152] the 3rd file of requested changes --- reddit/subreddit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e9ae4fe..66148d5 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -54,7 +54,8 @@ def get_subreddit_threads(): try: content["thread_url"] = submission.url - content["thread_title"] = submission.title + submission.selftext + content["thread_title"] = submission.title + content["thread_post"] = submission.selftext content["comments"] = [] for top_level_comment in submission.comments: From 5555b80bc8c39e90309e6edb8bb4f021f5bcc058 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 01:00:08 +0200 Subject: [PATCH 067/152] 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 ccd0c60d874a97c0f0d0a092c8412c38e33967b7 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 00:31:56 +0100 Subject: [PATCH 068/152] Add default values for environment variables This should reduce errors by some values not being set in the .env file - namely 2FA and Theme --- main.py | 2 +- reddit/subreddit.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8cc3c9a..57256df 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ reddit_object = get_subreddit_threads() load_dotenv() length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME")) +download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) download_background() chop_background_video(length) final_video = make_final_video(number_of_comments) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..c7714ce 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -15,7 +15,7 @@ def get_subreddit_threads(): print_step("Getting AskReddit threads...") - if os.getenv("REDDIT_2FA").lower() == "yes": + if os.getenv("REDDIT_2FA", default="no").lower() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" ) From f05eff4f88402b53c1dc919c6e793dea628c3da3 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:30:10 +0100 Subject: [PATCH 069/152] Alert user if their .env is not configured properly --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 57256df..dff9645 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,13 @@ from utils.console import print_markdown -import time - 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 from video_creation.final_video import make_final_video from dotenv import load_dotenv -import os +import os, time + +REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD"] 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,10 +15,17 @@ print_markdown( time.sleep(3) +load_dotenv() -reddit_object = get_subreddit_threads() +configured = True -load_dotenv() +for val in REQUIRED_VALUES: + if val not in os.environ or not os.getenv(val): + print(f"Please set the variable \"{val}\" in your .env file.") + configured = False + +if configured: +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() From 87d211281220ea529e6b48008e884a2adb7cd5f9 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:40:55 +0100 Subject: [PATCH 070/152] Move to casefold --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c7714ce..c64db2b 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -15,7 +15,7 @@ def get_subreddit_threads(): print_step("Getting AskReddit threads...") - if os.getenv("REDDIT_2FA", default="no").lower() == "yes": + if os.getenv("REDDIT_2FA", default="no").casefold() == "yes": print( "\nEnter your two-factor authentication code from your authenticator app.\n" ) From 3a7d91f474de5bbfdab0113b8479b0378949c943 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:41:48 +0100 Subject: [PATCH 071/152] Create a .env file if none exists on run Should fix issues users have with creating their own .env file, by simply copying our template to a file for them. --- main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index dff9645..b813c01 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ 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, time +import os, time, shutil REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD"] @@ -19,15 +19,19 @@ load_dotenv() configured = True +if not os.path.exists(".env"): + shutil.copy(".env.template", ".env") + configured = False + for val in REQUIRED_VALUES: if val not in os.environ or not os.getenv(val): print(f"Please set the variable \"{val}\" in your .env file.") configured = False if configured: -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) -final_video = make_final_video(number_of_comments) + 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) + final_video = make_final_video(number_of_comments) From d39386178b254f7bb86837c728fec20cb1dd52de Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:53:34 +0100 Subject: [PATCH 072/152] Clean up imports --- reddit/subreddit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..95d26e7 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,8 +1,6 @@ from utils.console import print_markdown, print_step, print_substep -import praw -import random from dotenv import load_dotenv -import os +import os, random, praw, re def get_subreddit_threads(): From cd5924562f021fcd95c8313cf9b8ee5cfc01185c Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 01:57:09 +0100 Subject: [PATCH 073/152] Ignore r/ in subreddit names --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 95d26e7..e1be0c3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -40,7 +40,7 @@ def get_subreddit_threads(): # ! Prompt the user to enter a subreddit try: subreddit = reddit.subreddit( - 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") From 37f22b8b018dd85d3b8db1b4fa9df282a55133cc Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 02:00:19 +0100 Subject: [PATCH 074/152] Ignore r/ in environment subreddit names --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index e1be0c3..32bcba3 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -35,7 +35,7 @@ def get_subreddit_threads(): ) if os.getenv("SUBREDDIT"): - subreddit = reddit.subreddit(os.getenv("SUBREDDIT")) + subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) else: # ! Prompt the user to enter a subreddit try: 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 075/152] 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 076/152] 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 2ef606fe29d818cbb666fbddddf9aabd727cdf8b Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sat, 4 Jun 2022 16:52:37 +1000 Subject: [PATCH 077/152] Fixed a bug: an error if the thread has no selftext Had to implement a few checks for the thread having selftext and for selftext tts file to exist --- video_creation/final_video.py | 31 ++++++++++++++++++++++--------- video_creation/voices.py | 7 ++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 7dd8d02..6f2fbbf 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -8,7 +8,7 @@ from moviepy.editor import ( CompositeVideoClip, ) from utils.console import print_step - +from pathlib import Path W, H = 1080, 1920 @@ -29,7 +29,10 @@ def make_final_video(number_of_clips): for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) - audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + try: + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + except: + OSError() audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) @@ -42,13 +45,23 @@ def make_final_video(number_of_clips): .set_position("center") .resize(width=W - 100), ) - image_clips.insert( - 0, - ImageClip(f"assets/png/title.png") - .set_duration(audio_clips[0].duration + audio_clips[1].duration) - .set_position("center") - .resize(width=W - 100), - ) + + if Path(f"assets/mp3/posttext.mp3").is_file(): #audio_clips[1] == AudioFileClip(f"assets/mp3/0.mp3"): + image_clips.insert( + 0, + ImageClip(f"assets/png/title.png") + .set_duration(audio_clips[0].duration + audio_clips[1].duration) + .set_position("center") + .resize(width=W - 100), + ) + else: + image_clips.insert( + 0, + ImageClip(f"assets/png/title.png") + .set_duration(audio_clips[0].duration) + .set_position("center") + .resize(width=W - 100), + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) diff --git a/video_creation/voices.py b/video_creation/voices.py index b4650e6..56a2b23 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,9 +21,10 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length - tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) - tts.save(f"assets/mp3/posttext.mp3") - length += MP3(f"assets/mp3/posttext.mp3").info.length + if reddit_obj["thread_post"] != "": + tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) + tts.save(f"assets/mp3/posttext.mp3") + length += MP3(f"assets/mp3/posttext.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 From d59fb5bdf28b1158845f094cb25913262e3bea45 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 09:53:23 +0200 Subject: [PATCH 078/152] 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 5cfda324cb8a6766fd9bfc6ba45ecc49e32600b2 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 12:22:40 +0200 Subject: [PATCH 079/152] Comments can be filtered by lenght --- .env.template | 5 +++++ reddit/subreddit.py | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.env.template b/.env.template index 5ab4ae4..bd2cbe4 100644 --- a/.env.template +++ b/.env.template @@ -9,3 +9,8 @@ REDDIT_2FA="" THEME="" SUBREDDIT="" + +# Filters the comments by range of lenght (min and max characters) +# Min has to be less or equal to max +# DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES +COMMENT_LENGHT_RANGE = "min,max" \ No newline at end of file diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..5212375 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,3 +1,4 @@ +from numpy import Infinity from utils.console import print_markdown, print_step, print_substep import praw import random @@ -58,13 +59,17 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: - content["comments"].append( - { - "comment_body": top_level_comment.body, - "comment_url": top_level_comment.permalink, - "comment_id": top_level_comment.id, - } - ) + COMMENT_LENGHT_RANGE = [0, Infinity] + if os.getenv("COMMENT_LENGHT_RANGE"): + COMMENT_LENGHT_RANGE = [int(i) for i in os.getenv("COMMENT_LENGHT_RANGE").split(",")] + if COMMENT_LENGHT_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGHT_RANGE[1]: + 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 From 8c8b344881cf6847d6c1c9410e06d30e610f44c2 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 12:31:35 +0200 Subject: [PATCH 080/152] Typo correction --- reddit/subreddit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5212375..30f6b2f 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -59,10 +59,10 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: - COMMENT_LENGHT_RANGE = [0, Infinity] - if os.getenv("COMMENT_LENGHT_RANGE"): - COMMENT_LENGHT_RANGE = [int(i) for i in os.getenv("COMMENT_LENGHT_RANGE").split(",")] - if COMMENT_LENGHT_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGHT_RANGE[1]: + COMMENT_LENGTH_RANGE = [0, Infinity] + if os.getenv("COMMENT_LENGTH_RANGE"): + COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")] + if COMMENT_LENGTH_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGTH_RANGE[1]: content["comments"].append( { "comment_body": top_level_comment.body, From 0b161932ea0c5219ac8c7bc0957e78653abb1153 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sat, 4 Jun 2022 12:56:18 +0200 Subject: [PATCH 081/152] Typo correction --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index bd2cbe4..c3f32dc 100644 --- a/.env.template +++ b/.env.template @@ -13,4 +13,4 @@ SUBREDDIT="" # Filters the comments by range of lenght (min and max characters) # Min has to be less or equal to max # DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES -COMMENT_LENGHT_RANGE = "min,max" \ No newline at end of file +COMMENT_LENGTH_RANGE = "min,max" \ No newline at end of file From 03f96e7a89780fb3ec8d8df16ff9653fa6cfed79 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:48:13 +0300 Subject: [PATCH 082/152] Fixed link to documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 10e84e9..dbb0250 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 5. Run `python3 main.py` 6. Enjoy 😎 -If you want to see more detailed guide, please refer to the official [documentation](https://immaharry.gitbook.io/reddit-automated-video-bot/). +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! ## Contributing & Ways to improve πŸ“ˆ From 5f2070d34497d6e2bfa5716f4dffdf53a96c3fe8 Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 09:04:43 -0400 Subject: [PATCH 083/152] Added opacity setting to the screen shots --- .env.template | 3 +++ video_creation/final_video.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index 5ab4ae4..43cb7d9 100644 --- a/.env.template +++ b/.env.template @@ -9,3 +9,6 @@ REDDIT_2FA="" THEME="" SUBREDDIT="" + +# Range is 0 -> 1 +OPACITY="" diff --git a/video_creation/final_video.py b/video_creation/final_video.py index e1f71ff..9db757e 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -8,12 +8,18 @@ from moviepy.editor import ( CompositeVideoClip, ) from utils.console import print_step - +from dotenv import load_dotenv +import os W, H = 1080, 1920 + def make_final_video(number_of_clips): + # Calls opacity from the .env + load_dotenv() + opacity = os.getenv('OPACITY') + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) VideoFileClip.reH = lambda clip: clip.resize(width=H) @@ -39,14 +45,16 @@ def make_final_video(number_of_clips): ImageClip(f"assets/png/comment_{i}.png") .set_duration(audio_clips[i + 1].duration) .set_position("center") - .resize(width=W - 100), + .resize(width=W - 100) + .set_opacity(float(opacity)), ) image_clips.insert( 0, ImageClip(f"assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") - .resize(width=W - 100), + .resize(width=W - 100) + .set_opacity(float(opacity)), ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") From 84c8eb25ce3a8735dfb9486330647006e4891a5f Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 10:02:01 -0400 Subject: [PATCH 084/152] updated .env to explain better --- .env.template | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index 43cb7d9..5115d89 100644 --- a/.env.template +++ b/.env.template @@ -3,12 +3,13 @@ REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -# Valid options are "yes" and "no" for the variable below +SUBREDDIT="" + +# Valid options are "yes" and "no" REDDIT_2FA="" +# Valid options are "light "dark" THEME="" -SUBREDDIT="" - # Range is 0 -> 1 OPACITY="" From 102f791684caddfdd3bb7de1b63c3391790e565b Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 15:43:21 +0100 Subject: [PATCH 085/152] Update .env.template --- .env.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index 5115d89..58f3fd3 100644 --- a/.env.template +++ b/.env.template @@ -8,8 +8,8 @@ SUBREDDIT="" # Valid options are "yes" and "no" REDDIT_2FA="" -# Valid options are "light "dark" +# Valid options are "light" and "dark" THEME="" # Range is 0 -> 1 -OPACITY="" +OPACITY="0.9" From fe92918823c0dbfc1dd03d7b675b0bfcb94b15b5 Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 10:59:07 -0400 Subject: [PATCH 086/152] updated --- .env.template | 2 +- main.py | 2 ++ video_creation/final_video.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 43cb7d9..d90bac7 100644 --- a/.env.template +++ b/.env.template @@ -11,4 +11,4 @@ THEME="" SUBREDDIT="" # Range is 0 -> 1 -OPACITY="" +OPACITY=".9" diff --git a/main.py b/main.py index 8cc3c9a..b0a4c28 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,8 @@ from video_creation.final_video import make_final_video from dotenv import load_dotenv import os +REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] + 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." ) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 9db757e..0a2afb0 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -30,6 +30,11 @@ 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 c318e4e0425f288a7189ea9ec6e2f2361367a973 Mon Sep 17 00:00:00 2001 From: jacesleeman <46321222+jacesleeman@users.noreply.github.com> Date: Sat, 4 Jun 2022 11:06:52 -0400 Subject: [PATCH 087/152] default OPACITY --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index a7f6dd3..3fc5e13 100644 --- a/.env.template +++ b/.env.template @@ -12,4 +12,4 @@ THEME="" SUBREDDIT="" # Range is 0 -> 1 -OPACITY="" \ No newline at end of file +OPACITY=".9" From b9ffdd186d1638da22d9d725a320afd5e795047c Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:09:26 +0100 Subject: [PATCH 088/152] Added a zero to make it clearer to users --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 3fc5e13..cab265e 100644 --- a/.env.template +++ b/.env.template @@ -12,4 +12,4 @@ THEME="" SUBREDDIT="" # Range is 0 -> 1 -OPACITY=".9" +OPACITY="0.9" From 0dc32154f2ccce46daf1d5751a9d4f5426e6c5bc Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sat, 4 Jun 2022 16:16:02 +0100 Subject: [PATCH 089/152] 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 090/152] 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 091/152] 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 3115155d894329a4e94bb82cd18e56d3a0c96289 Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Sun, 5 Jun 2022 08:59:26 +1000 Subject: [PATCH 092/152] Added a check for selftext if selftext file exists it gets deleted and recreated if it is present in the thread --- video_creation/voices.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/video_creation/voices.py b/video_creation/voices.py index 56a2b23..c0df8b7 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -21,6 +21,11 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length + try: + Path(f"assets/mp3/posttext.mp3").unlink() + except OSError as e: + pass + if reddit_obj["thread_post"] != "": tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) tts.save(f"assets/mp3/posttext.mp3") From f51cbbce4d95a3427eb14f22fe59f6135052f5c0 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 11:10:03 +0200 Subject: [PATCH 093/152] 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 49da171b55f562378d01f3bf2a8aa8decd45b2d8 Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Sun, 5 Jun 2022 07:35:45 -0400 Subject: [PATCH 094/152] Add OPACITY, SUBREDDIT, and THEME. --- setup.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f49b03b..feaa344 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,9 @@ console.log("[bold green]Reddit Client Secret") console.log("[bold green]Reddit Username") console.log("[bold green]Reddit Password") console.log("[bold green]Reddit 2FA (yes or no)") +console.log("[bold green]Opacity (range of 0-1, decimals are OK)") +console.log("[bold green]Subreddit (without r/ or /r/)") +console.log("[bold green]Theme (light or dark)") time.sleep(0.5) console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") @@ -80,6 +83,9 @@ cliSec = input("Client Secret > ") user = input("Username > ") passw = input("Password > ") twofactor = input("2fa Enabled? (yes/no) > ") +opacity = input("Opacity? (range of 0-1) > ") +subreddit = input("Subreddit (without r/) > ") +theme = input("Theme? (light or dark) > ") console.log("Attempting to save your credentials...") loader = Loader("Saving Credentials...", "Done!").start() # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... @@ -98,6 +104,12 @@ with open('.env', 'a') as f: f.write(f'REDDIT_PASSWORD="{passw}"\n') time.sleep(0.5) f.write(f'REDDIT_2FA="{twofactor}"\n') + time.sleep(0.5) + f.write(f'THEME="{theme}"\n') + time.sleep(0.5) + f.write(f'SUBREDDIT="{subreddit}"\n') + time.sleep(0.5) + f.write(f'OPACITY="{opacity}"\n') with open('.setup-done-before', 'a') as f: f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") @@ -107,4 +119,4 @@ loader.stop() console.log("[bold green]Setup Complete! Returning...") # Post-Setup: send message and try to run main.py again. -os.system("python3 main.py") \ No newline at end of file +os.system("python3 main.py") From f55dda166a17df9a1128cff3efd4836457c50c13 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 15:17:57 +0200 Subject: [PATCH 095/152] tts will no longer read aloud link There is an often issue where when commentators link to another site the tts will read out the link in its entirety. This PR uses Regex to filter that stuff out. --- video_creation/voices.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..55825eb 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,6 +3,7 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track +import re def save_text_to_mp3(reddit_obj): @@ -25,7 +26,9 @@ 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", slow=False) + comment=comment["comment_body"] + text=re.sub('((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*', '', comment) + tts = gTTS(text, lang="en", slow=False) tts.save(f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length From 4631d26391472c804f5e6088877602aceb60af2e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 15:28:04 +0200 Subject: [PATCH 096/152] tts links --- video_creation/voices.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..55825eb 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,6 +3,7 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track +import re def save_text_to_mp3(reddit_obj): @@ -25,7 +26,9 @@ 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", slow=False) + comment=comment["comment_body"] + text=re.sub('((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*', '', comment) + tts = gTTS(text, lang="en", slow=False) tts.save(f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length From 2ec2a496d2b804be0109d6aa2b2b8e59f33e83fb Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Sun, 5 Jun 2022 16:25:36 +0200 Subject: [PATCH 097/152] UI changes this mostly adds a nice banner to the terminal when main.py is run --- main.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 1b66e8c..e46bcba 100644 --- a/main.py +++ b/main.py @@ -9,11 +9,32 @@ import os, time, shutil REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] +banner = ''' + +β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β€ƒβ€ƒβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ +β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β€ƒβ€ƒβ–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— +β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ•šβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ +β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ–‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ +β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ–‘β–‘β•šβ–ˆβ–ˆβ•”β•β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• +β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β€ƒβ€ƒβ–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘ + +β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ +β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— +β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•β•β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• +β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— +β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ +β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β–‘β–‘β•šβ•β• + +''' +print(banner) + +time.sleep(1.5) + 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." ) -time.sleep(3) +time.sleep(1) load_dotenv() From aa67002b903bf7db3c7ab933c6e9471481518b68 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 17:15:39 +0200 Subject: [PATCH 098/152] 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 c6ab604c186e892b962f026e69997753edf8d83a Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 13:44:12 -0400 Subject: [PATCH 099/152] Fixed a couple of issues.. --- main.py | 84 +++++++++++++++++++++++++++------------------ reddit/subreddit.py | 25 ++++++++------ 2 files changed, 65 insertions(+), 44 deletions(-) diff --git a/main.py b/main.py index 689ca14..6ebb0ea 100644 --- a/main.py +++ b/main.py @@ -11,12 +11,19 @@ from video_creation.screenshot_downloader import download_screenshots_of_reddit_ from video_creation.final_video import make_final_video from utils.loader import Loader from dotenv import load_dotenv + console = Console() from dotenv import load_dotenv import os, time, shutil configured = True -REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] +REQUIRED_VALUES = [ + "REDDIT_CLIENT_ID", + "REDDIT_CLIENT_SECRET", + "REDDIT_USERNAME", + "REDDIT_PASSWORD", + "OPACITY", +] print_markdown( @@ -30,68 +37,77 @@ If there is a .env file, check if the required variables are set. If not, print """ -client_id=os.getenv("REDDIT_CLIENT_ID") -client_secret=os.getenv("REDDIT_CLIENT_SECRET") -username=os.getenv("REDDIT_USERNAME") -password=os.getenv("REDDIT_PASSWORD") -reddit2fa=os.getenv("REDDIT_2FA") +client_id = os.getenv("REDDIT_CLIENT_ID") +client_secret = os.getenv("REDDIT_CLIENT_SECRET") +username = os.getenv("REDDIT_USERNAME") +password = os.getenv("REDDIT_PASSWORD") +reddit2fa = os.getenv("REDDIT_2FA") +load_dotenv() console.log("[bold green]Checking environment variables...") time.sleep(1) + if not os.path.exists(".env"): shutil.copy(".env.template", ".env") configured = False console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: + print(os.getenv(val)) if val not in os.environ or not os.getenv(val): - console.log(f"[bold red]Missing Variable: \"{val}\"") + console.log(f'[bold red]Missing Variable: "{val}"') configured = False - console.log("[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up.") - time.sleep(0.5) - console.log("[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program.") - setup_ask = input("Launch setup wizard? > ") - if setup_ask=="yes": - console.log("[bold green]Here goes nothing! Launching setup wizard...") - time.sleep(0.5) - os.system("python3 setup.py") - else: - if setup_ask=="no": - console.print("[red]Exiting...") - time.sleep(0.5) - exit() - else: - console.print("[red]I don't understand that. Exiting...") - time.sleep(0.5) - exit() - - - exit() + console.log( + "[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up." + ) + time.sleep(0.5) + console.log( + "[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program." + ) + setup_ask = input("Launch setup wizard? > ") + if setup_ask == "yes": + console.log("[bold green]Here goes nothing! Launching setup wizard...") + time.sleep(0.5) + os.system("python3 setup.py") + else: + if setup_ask == "no": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() + else: + console.print("[red]I don't understand that. Exiting...") + time.sleep(0.5) + exit() + + exit() try: float(os.getenv("OPACITY")) except: - console.log(f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file") + console.log( + f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file" + ) configured = False exit() console.log("[bold green]Enviroment Variables are set! Continuing...") -load_dotenv() length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME")) +download_screenshots_of_reddit_posts( + reddit_object, number_of_comments, os.getenv("THEME") +) download_background() chop_background_video(length) final_video = make_final_video(number_of_comments) - - if configured: 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_screenshots_of_reddit_posts( + reddit_object, number_of_comments, os.getenv("THEME", "light") + ) download_background() chop_background_video(length) - final_video = make_final_video(number_of_comments) \ No newline at end of file + final_video = make_final_video(number_of_comments) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 9624e35..58ada57 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,8 +1,11 @@ -from rich import Console +from rich.console import Console from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv + console = Console() import os, random, praw, re + + def get_subreddit_threads(): global submission """ @@ -39,7 +42,9 @@ 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") @@ -56,14 +61,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 From 42f364d6227186253702e2aadd76aec29479631e Mon Sep 17 00:00:00 2001 From: Lewis Menelaws Date: Sun, 5 Jun 2022 13:48:58 -0400 Subject: [PATCH 100/152] 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 101/152] 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 From 20f087ea930e3e0a00811a487592b048d5950dec Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Sun, 5 Jun 2022 20:20:35 +0200 Subject: [PATCH 102/152] Merge conficts --- .env.template | 8 -------- reddit/subreddit.py | 19 ++++++++----------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/.env.template b/.env.template index 3c38548..7ae0ac6 100644 --- a/.env.template +++ b/.env.template @@ -16,10 +16,6 @@ THEME="" # Enter a subreddit, e.g. "AskReddit" SUBREDDIT="" -<<<<<<< HEAD -======= - ->>>>>>> b5393694ca852b5b29d6acb7779af1efd2f345db # Filters the comments by range of lenght (min and max characters) # Min has to be less or equal to max # DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES @@ -27,7 +23,3 @@ COMMENT_LENGTH_RANGE = "min,max" # Range is 0 -> 1 OPACITY="0.9" -<<<<<<< HEAD -======= - ->>>>>>> b5393694ca852b5b29d6acb7779af1efd2f345db diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 190dc8a..a84dffc 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -66,21 +66,18 @@ def get_subreddit_threads(): content["comments"] = [] for top_level_comment in submission.comments: -<<<<<<< HEAD COMMENT_LENGTH_RANGE = [0, Infinity] if os.getenv("COMMENT_LENGTH_RANGE"): COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")] if COMMENT_LENGTH_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGTH_RANGE[1]: -======= - if not top_level_comment.stickied: ->>>>>>> upstream/master - 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 From fea66a465c0bd406c698fb44fa5cf78d3ca8e0ab Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 20:03:30 +0100 Subject: [PATCH 103/152] Add contributing guidelines --- CONTRIBUTING.md | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..643ea4c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,109 @@ +# Contributing to Reddit Video Maker Bot πŸŽ₯ + +Thanks for taking the time to contribute! ❀️ + +All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for the maintainers and smooth out the experience for all involved. We are looking forward to your contributions. πŸŽ‰ + +> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: +> +> - Star the project +> - Tweet about it +> - Refer this project in your project's readme + +## Table of Contents + +- [I Have a Question](#i-have-a-question) +- [I Want To Contribute](#i-want-to-contribute) +- [Reporting Bugs](#reporting-bugs) +- [Suggesting Enhancements](#suggesting-enhancements) +- [Your First Code Contribution](#your-first-code-contribution) +- [Improving The Documentation](#improving-the-documentation) + +## I Have a Question + +> If you want to ask a question, we assume that you have read the available [Documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). + +Before you ask a question, it is best to search for existing [Issues](https://github.com/elebumm/RedditVideoMakerBot/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first. + +If you then still feel the need to ask a question and need clarification, we recommend the following: + +- Open an [Issue](https://github.com/elebumm/RedditVideoMakerBot/issues/new). +- Provide as much context as you can about what you're running into. +- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant. + +We will then take care of the issue as soon as possible. + +Additionally, there is a [discord channel](https://discord.gg/swqtb7AsNQ) for any questions you may have + +## I Want To Contribute + +### Reporting Bugs + +#### Before Submitting a Bug Report + +A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. + +- Make sure that you are using the latest version. +- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). If you are looking for support, you might want to check [this section](#i-have-a-question)). +- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [issues](https://github.com/elebumm/RedditVideoMakerBot/). +- Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue - you probably aren't the first to get the error! +- Collect information about the bug: + - Stack trace (Traceback) - preferably formatted in a code block. + - OS, Platform and Version (Windows, Linux, macOS, x86, ARM) + - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. + - Your input and the output + - Is the issue reproducable? Does it exist in previous versions? + +#### How Do I Submit a Good Bug Report? + +We use GitHub issues to track bugs and errors. If you run into an issue with the project: + +- Open an [Issue](https://github.com/elebumm/RedditVideoMakerBot/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.) +- Explain the behavior you would expect and the actual behavior. +- Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case. +- Provide the information you collected in the previous section. + +Once it's filed: + +- The project team will label the issue accordingly. +- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will try to support you as best as they can, but you may not recieve an instant. +- If the team discovers that this is an issue it will be marked `bug` or `error`, as well as possibly other tags relating to the nature of the error), and the issue will be left to be [implemented by someone](#your-first-code-contribution). + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion for Reddit Video Maker Bot, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions. + +#### Before Submitting an Enhancement + +- Make sure that you are using the latest version. +- Read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) carefully and find out if the functionality is already covered, maybe by an individual configuration. +- Perform a [search](https://github.com/elebumm/RedditVideoMakerBot/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one. +- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. + +#### How Do I Submit a Good Enhancement Suggestion? + +Enhancement suggestions are tracked as [GitHub issues](https://github.com/elebumm/RedditVideoMakerBot/issues). + +- Use a **clear and descriptive title** for the issue to identify the suggestion. +- Provide a **step-by-step description of the suggested enhancement** in as many details as possible. +- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you. +- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. +- **Explain why this enhancement would be useful** to most users. You may also want to point out the other projects that solved it better and which could serve as inspiration. + +### Your First Code Contribution + +#### Your environment + +You development environment should follow the requirements stated in the [README file](README.md). If you are not using the specified versions, **please reference this in your pull request**, so reviewers can test your code on both versions. + +#### Making your first PR + +When making your PR, follow these guidelines: + +- Your branch has a base of _develop_ **not** _master_ +- You are merging your branch into the _develop_ branch +- You link any issues that are resolved or fixed by your changes. (this is done by typing "Fixes #\") in your pull request. + +### Improving The Documentation + +All updates to the documentation should be made in a pull request to [this repo](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) From 39ac0c7bc24150ca4c1ffae62e93389b41c58cca Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 20:03:43 +0100 Subject: [PATCH 104/152] Link contributing guidelines in README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dbb0250..a79da04 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) [ + @@ -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 πŸ“ˆ @@ -51,3 +52,5 @@ I have tried to simplify the code so anyone can read it and start contributing a - [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. From f088c482ba8755732f421cfbc39c7e4e5ce36482 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 20:16:07 +0100 Subject: [PATCH 105/152] Add PR template --- .../pull_request_template.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 0000000..7fc8f80 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,21 @@ +# Description + + + +# Issue Fixes + + + +None + +# Checklist: + +- [ ] I am pushing to the **develop** branch +- [ ] I am using the recommended development environment +- [ ] I have performed a self-review of my own code +- [ ] My changes generate no new warnings +- [ ] I have commented my code, particularly in hard-to-understand areas + +# Any other information (e.g how to test the changes) + +None From 1dca1995f2b4a30828306f20f60defe31b4bde12 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Sun, 5 Jun 2022 23:21:36 +0300 Subject: [PATCH 106/152] Fixed the link to the documentation repository. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 643ea4c..244c711 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,4 +106,4 @@ When making your PR, follow these guidelines: ### Improving The Documentation -All updates to the documentation should be made in a pull request to [this repo](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) +All updates to the documentation should be made in a pull request to [this repo]([https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/](https://github.com/LukaHietala/reddit-bot-docs)) From ea328ba908b02a0e642550d133e701a8c8865b41 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 21:23:57 +0100 Subject: [PATCH 107/152] Make link work --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 244c711..e17be29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,4 +106,4 @@ When making your PR, follow these guidelines: ### Improving The Documentation -All updates to the documentation should be made in a pull request to [this repo]([https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/](https://github.com/LukaHietala/reddit-bot-docs)) +All updates to the documentation should be made in a pull request to [this repo](https://github.com/LukaHietala/reddit-bot-docs) From 156c9884202e529a141f1c3a9075981be95b82d7 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 21:26:22 +0100 Subject: [PATCH 108/152] Fix PR Template --- .../pull_request_template.md | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/PULL_REQUEST_TEMPLATE/pull_request_template.md diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md deleted file mode 100644 index 7fc8f80..0000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ /dev/null @@ -1,21 +0,0 @@ -# Description - - - -# Issue Fixes - - - -None - -# Checklist: - -- [ ] I am pushing to the **develop** branch -- [ ] I am using the recommended development environment -- [ ] I have performed a self-review of my own code -- [ ] My changes generate no new warnings -- [ ] I have commented my code, particularly in hard-to-understand areas - -# Any other information (e.g how to test the changes) - -None From 3693dce2cad58315b0a1462ee182207880cecfbc Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Sun, 5 Jun 2022 16:37:17 -0400 Subject: [PATCH 109/152] Update main.py --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 6ebb0ea..61ccbbb 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,6 @@ time.sleep(1) if not os.path.exists(".env"): - shutil.copy(".env.template", ".env") configured = False console.log("[red] Your .env file is invalid, or was never created. Standby.") From 72a4bdabaf898619f92db2d2a5beb3ce5369526f Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Sun, 5 Jun 2022 22:27:04 +0100 Subject: [PATCH 110/152] Fix merge errors from other PR's --- .env.template | 6 +++--- main.py | 18 +++--------------- reddit/subreddit.py | 2 +- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.env.template b/.env.template index 6b55f99..e95c209 100644 --- a/.env.template +++ b/.env.template @@ -4,11 +4,11 @@ REDDIT_CLIENT_SECRET="" REDDIT_USERNAME="" REDDIT_PASSWORD="" -# Valid options are "yes" and "no" +# Valid options are "yes" and "no" REDDIT_2FA="" -#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. -RANDOM_THREAD="no" +#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. +RANDOM_THREAD="yes" # Valid options are "light" and "dark" THEME="" diff --git a/main.py b/main.py index 61ccbbb..9aabe78 100644 --- a/main.py +++ b/main.py @@ -54,7 +54,7 @@ if not os.path.exists(".env"): console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: - print(os.getenv(val)) + #print(os.getenv(val)) if val not in os.environ or not os.getenv(val): console.log(f'[bold red]Missing Variable: "{val}"') configured = False @@ -70,8 +70,8 @@ for val in REQUIRED_VALUES: console.log("[bold green]Here goes nothing! Launching setup wizard...") time.sleep(0.5) os.system("python3 setup.py") - else: - if setup_ask == "no": + + elif setup_ask == "no": console.print("[red]Exiting...") time.sleep(0.5) exit() @@ -79,8 +79,6 @@ for val in REQUIRED_VALUES: console.print("[red]I don't understand that. Exiting...") time.sleep(0.5) exit() - - exit() try: float(os.getenv("OPACITY")) except: @@ -91,16 +89,6 @@ except: exit() console.log("[bold green]Enviroment Variables are set! Continuing...") - -length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts( - reddit_object, number_of_comments, os.getenv("THEME") -) -download_background() -chop_background_video(length) -final_video = make_final_video(number_of_comments) - - if configured: reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 6d5fa7a..c560293 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -33,7 +33,7 @@ def get_subreddit_threads(): username=os.getenv("REDDIT_USERNAME"), password=passkey, ) - + # 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") From 7ff6739fee0b694437e6464c5f9f160254cad36d Mon Sep 17 00:00:00 2001 From: MeDBeD1 <82283979+MeDBeD1@users.noreply.github.com> Date: Mon, 6 Jun 2022 07:29:00 +1000 Subject: [PATCH 111/152] Uploaded file with requested changes via DMs --- main.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/main.py b/main.py index 61ccbbb..0727e20 100644 --- a/main.py +++ b/main.py @@ -91,16 +91,6 @@ except: exit() console.log("[bold green]Enviroment Variables are set! Continuing...") - -length, number_of_comments = save_text_to_mp3(reddit_object) -download_screenshots_of_reddit_posts( - reddit_object, number_of_comments, os.getenv("THEME") -) -download_background() -chop_background_video(length) -final_video = make_final_video(number_of_comments) - - if configured: reddit_object = get_subreddit_threads() length, number_of_comments = save_text_to_mp3(reddit_object) From b5c6e8f60b0fef48d950ac84c0edb2b3d36e3472 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Mon, 6 Jun 2022 11:11:44 +0200 Subject: [PATCH 112/152] Added a .env variable to change the save location of the final video --- .env.template | 3 +++ video_creation/final_video.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.env.template b/.env.template index e95c209..56f60d0 100644 --- a/.env.template +++ b/.env.template @@ -18,3 +18,6 @@ SUBREDDIT="" # Range is 0 -> 1 OPACITY="0.9" + +#The absolute path of the folder you want to save the final video +FINAL_VIDEO_PATH="" \ No newline at end of file diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 93bac6f..d9463bb 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,3 +1,4 @@ +from click import style from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -9,7 +10,7 @@ from moviepy.editor import ( ) import reddit.subreddit import re -from utils.console import print_step +from utils.console import print_step, print_substep from dotenv import load_dotenv import os @@ -80,7 +81,16 @@ def make_final_video(number_of_clips): ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))) - final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") + + final_video_path = "assets/" + if os.getenv("FINAL_VIDEO_PATH"): + final_video_path = os.getenv("FINAL_VIDEO_PATH") + filename = (re.sub('[?\"%*:|<>]', '', (final_video_path + reddit.subreddit.submission.title + ".mp4"))) + try: + final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") + except: + print_substep("Something's wrong with the path you inserted, the video will be saved in the default path (assets/)", style="bold red") + 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 46b77cb7311b5b9ef7af652863b7e86668824503 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Mon, 6 Jun 2022 11:16:52 +0200 Subject: [PATCH 113/152] Edit .env.template --- .env.template | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 56f60d0..7469035 100644 --- a/.env.template +++ b/.env.template @@ -19,5 +19,6 @@ SUBREDDIT="" # Range is 0 -> 1 OPACITY="0.9" -#The absolute path of the folder you want to save the final video +# The absolute path of the folder where you want to save the final video +# If empty or wrong, the path will be 'assets/' FINAL_VIDEO_PATH="" \ No newline at end of file From 1f56c896920171591f7a6b494f636980cb54a9be Mon Sep 17 00:00:00 2001 From: Freebie <69956546+FreebieII@users.noreply.github.com> Date: Mon, 6 Jun 2022 12:14:53 +0200 Subject: [PATCH 114/152] Grammar-ized contributing.md Fixed grammar and misinterpretations in `contributing.md`, i.e., Discord channel -> Discord Server --- CONTRIBUTING.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e17be29..ad3adb0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,9 +6,9 @@ All types of contributions are encouraged and valued. See the [Table of Contents > And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: > -> - Star the project -> - Tweet about it -> - Refer this project in your project's readme +> - ⭐ Star the project +> - πŸ“£ Tweet about it +> - 🌲 Refer this project in your project's readme ## Table of Contents @@ -33,7 +33,7 @@ If you then still feel the need to ask a question and need clarification, we rec We will then take care of the issue as soon as possible. -Additionally, there is a [discord channel](https://discord.gg/swqtb7AsNQ) for any questions you may have +Additionally, there is a [Discord Server](https://discord.gg/swqtb7AsNQ) for any questions you may have ## I Want To Contribute @@ -44,7 +44,7 @@ Additionally, there is a [discord channel](https://discord.gg/swqtb7AsNQ) for an A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. - Make sure that you are using the latest version. -- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). If you are looking for support, you might want to check [this section](#i-have-a-question)). +- Determine if your bug is really a bug and not an error on your side e.g., using incompatible environment components/versions (Make sure that you have read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/). If you are looking for support, you might want to check [this section](#i-have-a-question)). - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [issues](https://github.com/elebumm/RedditVideoMakerBot/). - Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue - you probably aren't the first to get the error! - Collect information about the bug: @@ -100,7 +100,7 @@ You development environment should follow the requirements stated in the [README When making your PR, follow these guidelines: -- Your branch has a base of _develop_ **not** _master_ +- Your branch has a base of _develop_, **not** _master_ - You are merging your branch into the _develop_ branch - You link any issues that are resolved or fixed by your changes. (this is done by typing "Fixes #\") in your pull request. From cf094fa9ae6ba9162927c3e5ff2ea34e6482727a Mon Sep 17 00:00:00 2001 From: BlockArchitech Date: Mon, 6 Jun 2022 10:14:52 -0400 Subject: [PATCH 115/152] Create LICENSE --- LICENSE | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b477f17 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From beb1da81452c0ab2e91ece6bedf86842849fc6e3 Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:25:22 +0300 Subject: [PATCH 116/152] Added developers section. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index df52b59..8828654 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,11 @@ I have tried to simplify the code so anyone can read it and start contributing a - [ ] Creating better documentation and adding a command line interface. Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed information. + +## Developers and maintainers. + +Elebumm (Lewis#6305) - https://github.com/elebumm (Founder) +CallumIO - https://github.com/CallumIO +HarryDaDev (hrvyy#9677) - https://github.com/ImmaHarry +LukaHietala (Pix.#0001) - https://github.com/LukaHietala +Freebiell - https://github.com/FreebieII From 4a0f753fa2f683f65e4c32b13701a7f7b5eb571c Mon Sep 17 00:00:00 2001 From: Luka Hietala <95122845+LukaHietala@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:28:26 +0300 Subject: [PATCH 117/152] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8828654..56f4581 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,11 @@ Please read our [contributing guidelines](CONTRIBUTING.md) for more detailed inf ## Developers and maintainers. Elebumm (Lewis#6305) - https://github.com/elebumm (Founder) + CallumIO - https://github.com/CallumIO + HarryDaDev (hrvyy#9677) - https://github.com/ImmaHarry + LukaHietala (Pix.#0001) - https://github.com/LukaHietala + Freebiell - https://github.com/FreebieII From e41ad649ee07ea6e80f446557602fa07dcd6af8d Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:16:57 +0200 Subject: [PATCH 118/152] Update main.py --- main.py | 72 ++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/main.py b/main.py index e46bcba..3c236e4 100644 --- a/main.py +++ b/main.py @@ -1,64 +1,58 @@ +# Main from utils.console import print_markdown +from utils.console import print_step +from utils.console import print_substep +from rich.console import Console +import time 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 from video_creation.final_video import make_final_video +from utils.loader import Loader from dotenv import load_dotenv -import os, time, shutil - -REQUIRED_VALUES = ["REDDIT_CLIENT_ID","REDDIT_CLIENT_SECRET","REDDIT_USERNAME","REDDIT_PASSWORD", "OPACITY"] -banner = ''' - -β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β€ƒβ€ƒβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ -β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β€ƒβ€ƒβ–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— -β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ•šβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ -β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ–‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ -β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ–‘β–‘β•šβ–ˆβ–ˆβ•”β•β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• -β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β€ƒβ€ƒβ–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘ +console = Console() +from dotenv import load_dotenv +import os, time, shutil -β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ -β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— -β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•β•β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• -β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— -β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ -β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β–‘β–‘β•šβ•β• - -''' -print(banner) +configured = True +REQUIRED_VALUES = [ + "REDDIT_CLIENT_ID", + "REDDIT_CLIENT_SECRET", + "REDDIT_USERNAME", + "REDDIT_PASSWORD", + "OPACITY", +] -time.sleep(1.5) 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." ) -time.sleep(1) +""" +Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. +If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. +""" + +client_id = os.getenv("REDDIT_CLIENT_ID") +client_secret = os.getenv("REDDIT_CLIENT_SECRET") +username = os.getenv("REDDIT_USERNAME") +password = os.getenv("REDDIT_PASSWORD") +reddit2fa = os.getenv("REDDIT_2FA") load_dotenv() -configured = True +console.log("[bold green]Checking environment variables...") +time.sleep(1) + if not os.path.exists(".env"): - shutil.copy(".env.template", ".env") configured = False + console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: + #print(os.getenv(val)) if val not in os.environ or not os.getenv(val): - print(f"Please set the variable \"{val}\" in your .env file.") + console.log(f'[bold red]Missing Variable: "{val}"') 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) - download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) - download_background() - chop_background_video(length) - final_video = make_final_video(number_of_comments) From 45a296db802840be708b8679bc5ceb309b117249 Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 20:42:46 +0300 Subject: [PATCH 119/152] setup.py heavily refactored, all files formatted with python-BLACK and added shebang lines --- build.sh | 3 +- main.py | 3 +- reddit/subreddit.py | 7 +- run.sh | 3 +- setup.py | 247 ++++++++++++++++-------- utils/console.py | 1 + utils/loader.py | 9 +- video_creation/background.py | 2 + video_creation/final_video.py | 18 +- video_creation/screenshot_downloader.py | 6 +- video_creation/voices.py | 1 + 11 files changed, 200 insertions(+), 100 deletions(-) mode change 100644 => 100755 setup.py diff --git a/build.sh b/build.sh index 7d4dfc6..45ebd33 100755 --- a/build.sh +++ b/build.sh @@ -1 +1,2 @@ -docker build -t rvmt . \ No newline at end of file +#!/bin/sh +docker build -t rvmt . diff --git a/main.py b/main.py index 9aabe78..92cc886 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # Main from utils.console import print_markdown from utils.console import print_step @@ -54,7 +55,7 @@ if not os.path.exists(".env"): console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: - #print(os.getenv(val)) + # print(os.getenv(val)) if val not in os.environ or not os.getenv(val): console.log(f'[bold red]Missing Variable: "{val}"') configured = False diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c560293..a52a214 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from rich.console import Console from utils.console import print_markdown, print_step, print_substep from dotenv import load_dotenv @@ -48,7 +49,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") diff --git a/run.sh b/run.sh index 4dcb69a..3ee26db 100755 --- a/run.sh +++ b/run.sh @@ -1 +1,2 @@ -docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt \ No newline at end of file +#!/bin/sh +docker run -v "$(pwd)/out/:/app/assets" -v "$(pwd)/.env:/app/.env -it rvmt" diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index feaa344..0154ce9 --- a/setup.py +++ b/setup.py @@ -1,55 +1,98 @@ -""" - -Setup Script for RedditVideoMakerBot +#!/usr/bin/env python3 +# Setup Script for RedditVideoMakerBot -""" # Imports import os -import time +import subprocess +import re from utils.console import print_markdown from utils.console import print_step -from utils.console import print_substep from rich.console import Console from utils.loader import Loader -from os.path import exists + console = Console() -setup_done = exists(".setup-done-before") -if setup_done == True: - console.log("[red]Setup was already completed! Please make sure you have to run this script again. If you have to, please delete the file .setup-done-before") - exit() +def handle_input( + message: str = "", + check_type=False, + match: str = "", + err_message: str = "", + nmin=None, + nmax=None, + oob_error="", +): + match = re.compile(match) + while True: + user_input = input(message + "\n> ").strip() + if re.match(match, user_input) is not None: + if check_type is not False: + try: + user_input = check_type(user_input) + if nmin is not None and user_input < nmin: + console.log("[red]" + oob_error) # Input too low failstate + continue + if nmax is not None and user_input > nmax: + console.log("[red]" + oob_error) # Input too high + continue + break # Successful type conversion and number in bounds + except ValueError: + console.log("[red]" + err_message) # Type conversion failed + continue + if ( + nmin is not None and len(user_input) < nmin + ): # Check if string is long enough + console.log("[red]" + oob_error) + continue + if ( + nmax is not None and len(user_input) > nmax + ): # Check if string is not too long + console.log("[red]" + oob_error) + continue + break + console.log("[red]" + err_message) + + return user_input + + +if os.path.isfile(".setup-done-before"): + console.log( + "[red]Setup was already completed! Please make sure you have to run this script again. If that is such, delete the file .setup-done-before" + ) + exit() # These lines ensure the user: # - knows they are in setup mode # - knows that they are about to erase any other setup files/data. print_step("Setup Assistant") - print_markdown( - "### You're in the setup wizard. Ensure you're supposed to be here, then type yes to continue. If you're not sure, type no to quit." + "### You're in the setup wizard. Ensure you're supposed to be here, then type yes to continue. If you're not sure, type no to quit." ) + # This Input is used to ensure the user is sure they want to continue. -ensureSetupIsRequired = input("Are you sure you want to continue? > ").casefold() -if ensureSetupIsRequired != "yes": - console.print("[red]Exiting...") - time.sleep(0.5) - exit() -else: - # Again, let them know they are about to erase all other setup data. - console.print("[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no") - overwriteSettings = input("Are you sure you want to continue? > ").casefold() - if overwriteSettings != "yes": - console.print("[red]Abort mission! Exiting...") - time.sleep(0.5) - exit() - else: - # Once they confirm, move on with the script. - console.print("[bold green]Alright! Let's get started!") - time.sleep(1) +if input("Are you sure you want to continue? > ").strip().casefold() != "yes": + console.print("[red]Exiting...") + exit() +# This code is inaccessible if the prior check fails, and thus an else statement is unnecessary + +# Again, let them know they are about to erase all other setup data. +console.print( + "[bold red] This will overwrite your current settings. Are you sure you want to continue? [bold green]yes/no" +) + + +if input("Are you sure you want to continue? > ").strip().casefold() != "yes": + console.print("[red]Abort mission! Exiting...") + exit() +# This is once again inaccessible if the prior checks fail +# Once they confirm, move on with the script. +console.print("[bold green]Alright! Let's get started!") + +print("\n") console.log("Ensure you have the following ready to enter:") console.log("[bold green]Reddit Client ID") console.log("[bold green]Reddit Client Secret") @@ -59,64 +102,108 @@ console.log("[bold green]Reddit 2FA (yes or no)") console.log("[bold green]Opacity (range of 0-1, decimals are OK)") console.log("[bold green]Subreddit (without r/ or /r/)") console.log("[bold green]Theme (light or dark)") -time.sleep(0.5) -console.print("[green]If you don't have these, please follow the instructions in the README.md file to set them up.") -console.print("[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back.") -confirmUserHasCredentials = input("Are you sure you have the credentials? > ").casefold() -if confirmUserHasCredentials != "yes": - console.print("[red]I don't understand that.") - console.print("[red]Exiting...") - exit() -else: - console.print("[bold green]Alright! Let's get started!") - time.sleep(1) +console.print( + "[green]If you don't have these, please follow the instructions in the README.md file to set them up." +) +console.print( + "[green]If you do have these, type yes to continue. If you dont, go ahead and grab those quickly and come back." +) +print() -""" -Begin the setup process. +if input("Are you sure you have the credentials? > ").strip().casefold() != "yes": + console.print("[red]I don't understand that.") + console.print("[red]Exiting...") + exit() -""" + +console.print("[bold green]Alright! Let's get started!") + +# Begin the setup process. console.log("Enter your credentials now.") -cliID = input("Client ID > ") -cliSec = input("Client Secret > ") -user = input("Username > ") -passw = input("Password > ") -twofactor = input("2fa Enabled? (yes/no) > ") -opacity = input("Opacity? (range of 0-1) > ") -subreddit = input("Subreddit (without r/) > ") -theme = input("Theme? (light or dark) > ") -console.log("Attempting to save your credentials...") -loader = Loader("Saving Credentials...", "Done!").start() - # you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... -time.sleep(0.5) -console.log("Removing old .env file...") -os.remove(".env") -time.sleep(0.5) -console.log("Creating new .env file...") -with open('.env', 'a') as f: - f.write(f'REDDIT_CLIENT_ID="{cliID}"\n') - time.sleep(0.5) - f.write(f'REDDIT_CLIENT_SECRET="{cliSec}"\n') - time.sleep(0.5) - f.write(f'REDDIT_USERNAME="{user}"\n') - time.sleep(0.5) - f.write(f'REDDIT_PASSWORD="{passw}"\n') - time.sleep(0.5) - f.write(f'REDDIT_2FA="{twofactor}"\n') - time.sleep(0.5) - f.write(f'THEME="{theme}"\n') - time.sleep(0.5) - f.write(f'SUBREDDIT="{subreddit}"\n') - time.sleep(0.5) - f.write(f'OPACITY="{opacity}"\n') - -with open('.setup-done-before', 'a') as f: - f.write("This file blocks the setup assistant from running again. Delete this file to run setup again.") +client_id = handle_input( + "Client ID > ", + False, + "[-a-zA-Z0-9._~+/]+=*", + "That is somehow not a correct ID, try again.", + 20, + 40, + "The ID should be over 20 and under 40 characters, double check your input.", +) +client_sec = handle_input( + "Client Secret > ", + False, + "[-a-zA-Z0-9._~+/]+=*", + "That is somehow not a correct secret, try again.", + 20, + 40, + "The secret should be over 20 and under 40 characters, double check your input.", +) +user = handle_input( + "Username > ", + False, + r"[_0-9a-zA-Z]+", + "That is not a valid user", + 3, + 20, + "A username HAS to be between 3 and 20 characters", +) +passw = handle_input("Password > ", False, "", "", 8, None, "Password too short") +twofactor = handle_input( + "2fa Enabled? (yes/no) > ", + False, + r"(yes)|(no)", + "You need to input either yes or no", +) +opacity = handle_input( + "Opacity? (range of 0-1) > ", + float, + "", + "You need to input a number between 0 and 1", + 0, + 1, + "Your number is not between 0 and 1", +) +subreddit = handle_input( + "Subreddit (without r/) > ", + False, + r"[_0-9a-zA-Z]+", + "This subreddit cannot exist, make sure you typed it in correctly and removed the r/ (or /r/).", + 3, + 20, + "A subreddit name HAS to be between 3 and 20 characters", +) +theme = handle_input( + "Theme? (light or dark) > ", + False, + r"(light)|(dark)", + "You need to input 'light' or 'dark'", +) +loader = Loader("Attempting to save your credentials...", "Done!").start() +# you can also put a while loop here, e.g. while VideoIsBeingMade == True: ... +console.log("Writing to the .env file...") +with open(".env", "w") as f: + f.write( + f"""REDDIT_CLIENT_ID="{client_id}" +REDDIT_CLIENT_SECRET="{client_sec}" +REDDIT_USERNAME="{user}" +REDDIT_PASSWORD="{passw}" +REDDIT_2FA="{twofactor}" +THEME="{theme}" +SUBREDDIT="{subreddit}" +OPACITY={opacity} +""" + ) + +with open(".setup-done-before", "w") as f: + f.write( + "This file blocks the setup assistant from running again. Delete this file to run setup again." + ) loader.stop() console.log("[bold green]Setup Complete! Returning...") # Post-Setup: send message and try to run main.py again. -os.system("python3 main.py") +subprocess.call("python3 main.py", shell=True) diff --git a/utils/console.py b/utils/console.py index d024dc0..11ee429 100644 --- a/utils/console.py +++ b/utils/console.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from rich.console import Console from rich.markdown import Markdown from rich.padding import Padding diff --git a/utils/loader.py b/utils/loader.py index 58fd662..46c40fe 100644 --- a/utils/loader.py +++ b/utils/loader.py @@ -1,9 +1,8 @@ -""" -Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it. -Although, it is edited to use less threads. +# Okay, have to admit. This code is from StackOverflow. It's so efficient, that it's probably the best way to do it. +# Although, it is edited to use less threads. + -""" from itertools import cycle from shutil import get_terminal_size from threading import Thread @@ -50,4 +49,4 @@ class Loader: def __exit__(self, exc_type, exc_value, tb): # handle exceptions with those variables ^ - self.stop() \ No newline at end of file + self.stop() diff --git a/video_creation/background.py b/video_creation/background.py index dce46bd..fe7b5ec 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from random import randrange from yt_dlp import YoutubeDL @@ -13,6 +14,7 @@ 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. diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 93bac6f..8a635d6 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -7,7 +8,7 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.subreddit +import reddit.subreddit import re from utils.console import print_step from dotenv import load_dotenv @@ -16,13 +17,12 @@ import os W, H = 1080, 1920 - def make_final_video(number_of_clips): - + # Calls opacity from the .env load_dotenv() - opacity = os.getenv('OPACITY') - + opacity = os.getenv("OPACITY") + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) @@ -65,7 +65,7 @@ def make_final_video(number_of_clips): .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) else: image_clips.insert( 0, @@ -74,13 +74,15 @@ def make_final_video(number_of_clips): .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.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 diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index d3d32ef..2925daa 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from playwright.sync_api import sync_playwright, ViewportSize from pathlib import Path from rich.progress import track @@ -24,7 +25,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): context = browser.new_context() if theme.casefold() == "dark": - cookie_file = open('video_creation/cookies.json') + cookie_file = open("video_creation/cookies.json") cookies = json.load(cookie_file) context.add_cookies(cookies) @@ -58,5 +59,4 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): 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/voices.py b/video_creation/voices.py index c0df8b7..5a64f7b 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from gtts import gTTS from pathlib import Path from mutagen.mp3 import MP3 From c028d66b0cdec11c37b4a29fa9ca51f2e0fec807 Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 20:52:41 +0300 Subject: [PATCH 120/152] fixed run.sh --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 3ee26db..1769e21 100755 --- a/run.sh +++ b/run.sh @@ -1,2 +1,2 @@ #!/bin/sh -docker run -v "$(pwd)/out/:/app/assets" -v "$(pwd)/.env:/app/.env -it rvmt" +docker run -v $(pwd)/out/:/app/assets -v $(pwd)/.env:/app/.env -it rvmt From 86c7b26f00024c50d715f85e6a189eb8e05ddf72 Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 21:07:33 +0300 Subject: [PATCH 121/152] small regex fix --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 0154ce9..f33daff 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def handle_input( nmax=None, oob_error="", ): - match = re.compile(match) + match = re.compile(match + "$") while True: user_input = input(message + "\n> ").strip() if re.match(match, user_input) is not None: @@ -149,7 +149,7 @@ user = handle_input( 20, "A username HAS to be between 3 and 20 characters", ) -passw = handle_input("Password > ", False, "", "", 8, None, "Password too short") +passw = handle_input("Password > ", False, ".*", "", 8, None, "Password too short") twofactor = handle_input( "2fa Enabled? (yes/no) > ", False, @@ -159,7 +159,7 @@ twofactor = handle_input( opacity = handle_input( "Opacity? (range of 0-1) > ", float, - "", + ".*", "You need to input a number between 0 and 1", 0, 1, @@ -206,4 +206,4 @@ loader.stop() console.log("[bold green]Setup Complete! Returning...") # Post-Setup: send message and try to run main.py again. -subprocess.call("python3 main.py", shell=True) +subprocess.call("python3 main.py", shell=False) From 42861287ef8a2977ea66e4461320f927265d00ec Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 21:10:21 +0300 Subject: [PATCH 122/152] forgor to change shell back to true :skull: --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f33daff..1ed0e93 100755 --- a/setup.py +++ b/setup.py @@ -206,4 +206,4 @@ loader.stop() console.log("[bold green]Setup Complete! Returning...") # Post-Setup: send message and try to run main.py again. -subprocess.call("python3 main.py", shell=False) +subprocess.call("python3 main.py", shell=True) From d9bf0e509b9d3d746be1a000cc3480f095bd79f2 Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 21:19:01 +0300 Subject: [PATCH 123/152] main.py surface level refactor --- main.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 92cc886..ea944f0 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 # Main from utils.console import print_markdown -from utils.console import print_step -from utils.console import print_substep from rich.console import Console import time from reddit.subreddit import get_subreddit_threads @@ -10,12 +8,10 @@ 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 utils.loader import Loader from dotenv import load_dotenv +import os console = Console() -from dotenv import load_dotenv -import os, time, shutil configured = True REQUIRED_VALUES = [ @@ -82,9 +78,9 @@ for val in REQUIRED_VALUES: exit() try: float(os.getenv("OPACITY")) -except: +except ValueError: console.log( - f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file" + "[red]Please ensure that OPACITY is set between 0 and 1 in your .env file" ) configured = False exit() From 24863a9940814c577280fdedfff8a8a80e73eeef Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 21:20:08 +0300 Subject: [PATCH 124/152] video_creation surface level refactor --- video_creation/final_video.py | 10 +++++----- video_creation/voices.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 8a635d6..3cbed3a 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -39,9 +39,9 @@ def make_final_video(number_of_clips): audio_clips = [] for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) - audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip("assets/mp3/title.mp3")) try: - audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + audio_clips.insert(1, AudioFileClip("assets/mp3/posttext.mp3")) except: OSError() audio_concat = concatenate_audioclips(audio_clips) @@ -57,10 +57,10 @@ def make_final_video(number_of_clips): .resize(width=W - 100) .set_opacity(float(opacity)), ) - if os.path.exists(f"assets/mp3/posttext.mp3"): + if os.path.exists("assets/mp3/posttext.mp3"): image_clips.insert( 0, - ImageClip(f"assets/png/title.png") + ImageClip("assets/png/title.png") .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100) @@ -69,7 +69,7 @@ def make_final_video(number_of_clips): else: image_clips.insert( 0, - ImageClip(f"assets/png/title.png") + ImageClip("assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") .resize(width=W - 100) diff --git a/video_creation/voices.py b/video_creation/voices.py index 5a64f7b..3d54c40 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -19,18 +19,18 @@ def save_text_to_mp3(reddit_obj): Path("assets/mp3").mkdir(parents=True, exist_ok=True) 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 + tts.save("assets/mp3/title.mp3") + length += MP3("assets/mp3/title.mp3").info.length try: - Path(f"assets/mp3/posttext.mp3").unlink() - except OSError as e: + Path("assets/mp3/posttext.mp3").unlink() + except OSError: pass if reddit_obj["thread_post"] != "": tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) - tts.save(f"assets/mp3/posttext.mp3") - length += MP3(f"assets/mp3/posttext.mp3").info.length + tts.save("assets/mp3/posttext.mp3") + length += MP3("assets/mp3/posttext.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 From 69c8b4a1890363c4157281f4545ed4867483f464 Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 21:21:17 +0300 Subject: [PATCH 125/152] subreddit.py surface level refactor --- reddit/subreddit.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index a52a214..ff01684 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -1,10 +1,13 @@ #!/usr/bin/env python3 from rich.console import Console -from utils.console import print_markdown, print_step, print_substep +from utils.console import print_step, print_substep from dotenv import load_dotenv +import os +import random +import praw +import re console = Console() -import os, random, praw, re def get_subreddit_threads(): @@ -39,7 +42,7 @@ def get_subreddit_threads(): 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...") + print_step("Getting the inserted thread...") submission = reddit.submission(url=thread_link) else: # Otherwise, picks a random thread from the inserted subreddit @@ -80,7 +83,7 @@ def get_subreddit_threads(): } ) - except AttributeError as e: + except AttributeError: pass print_substep("Received AskReddit threads successfully.", style="bold green") From 01c9977549e71db691ce285d92c1e4578892801b Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Mon, 6 Jun 2022 21:35:10 +0300 Subject: [PATCH 126/152] fixed the character bounds for client_ID --- CONTRIBUTING.md | 16 +++++++++------- setup.py | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ad3adb0..71a9aa8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,8 +6,8 @@ All types of contributions are encouraged and valued. See the [Table of Contents > And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: > -> - ⭐ Star the project -> - πŸ“£ Tweet about it +> - ⭐ Star the project +> - πŸ“£ Tweet about it > - 🌲 Refer this project in your project's readme ## Table of Contents @@ -38,8 +38,7 @@ Additionally, there is a [Discord Server](https://discord.gg/swqtb7AsNQ) for any ## I Want To Contribute ### Reporting Bugs - -#### Before Submitting a Bug Report +

Before Submitting a Bug Report

A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. @@ -53,8 +52,8 @@ A good bug report shouldn't leave others needing to chase you up for more inform - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. - Your input and the output - Is the issue reproducable? Does it exist in previous versions? - -#### How Do I Submit a Good Bug Report? +
+

How Do I Submit a Good Bug Report?

We use GitHub issues to track bugs and errors. If you run into an issue with the project: @@ -68,12 +67,13 @@ Once it's filed: - The project team will label the issue accordingly. - A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will try to support you as best as they can, but you may not recieve an instant. - If the team discovers that this is an issue it will be marked `bug` or `error`, as well as possibly other tags relating to the nature of the error), and the issue will be left to be [implemented by someone](#your-first-code-contribution). +
### Suggesting Enhancements This section guides you through submitting an enhancement suggestion for Reddit Video Maker Bot, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions. -#### Before Submitting an Enhancement +

Before Submitting an Enhancement

- Make sure that you are using the latest version. - Read the [documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/) carefully and find out if the functionality is already covered, maybe by an individual configuration. @@ -90,6 +90,8 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/elebum - You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. - **Explain why this enhancement would be useful** to most users. You may also want to point out the other projects that solved it better and which could serve as inspiration. +
+ ### Your First Code Contribution #### Your environment diff --git a/setup.py b/setup.py index 1ed0e93..b09c30d 100755 --- a/setup.py +++ b/setup.py @@ -127,9 +127,9 @@ client_id = handle_input( False, "[-a-zA-Z0-9._~+/]+=*", "That is somehow not a correct ID, try again.", - 20, - 40, - "The ID should be over 20 and under 40 characters, double check your input.", + 12, + 30, + "The ID should be over 12 and under 30 characters, double check your input.", ) client_sec = handle_input( "Client Secret > ", From 0914a7858fcef1631dcf0c5792418239f28349eb Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 6 Jun 2022 21:04:42 +0100 Subject: [PATCH 127/152] Add correct playwright command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bda3b5..0e5a5df 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` -3. Run `playwright install` and `playwright install-deps`. +3. Run `python3 -m playwright install` and `python3 -m playwright install-deps`. 4. 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. From 2e675193bf7ad45a9f87355b97986a272bac889b Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 6 Jun 2022 22:14:39 +0100 Subject: [PATCH 128/152] Move to more comprehensive gitignore --- .gitignore | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 162 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 72e6fc7..97c134a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,165 @@ -assets/ -reddit/__pycache__/ -utils/__pycache__/ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments .env -reddit-bot-351418-5560ebc49cac.json -video_creation/__pycache__/ -.setup-done-before -__pycache__ +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -.DS_Store + +assets/ out +.DS_Store +.setup-done-before \ No newline at end of file From e4c5fb40b1127929c47490387908dfc3b971964d Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 6 Jun 2022 22:26:36 +0100 Subject: [PATCH 129/152] Add pylintrc --- .pylintrc | 614 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 614 insertions(+) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..e3fead7 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,614 @@ +[MAIN] + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Load and enable all available extensions. Use --list-extensions to see a list +# all available extensions. +#enable-all-extensions= + +# In error mode, checkers without error messages are disabled and for others, +# only the ERROR messages are displayed, and no reports are done by default. +#errors-only= + +# Always return a 0 (non-error) status code, even if lint errors are found. +# This is primarily useful in continuous integration scripts. +#exit-zero= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-allow-list= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) +extension-pkg-whitelist= + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +fail-on= + +# Specify a score threshold to be exceeded before program exits with error. +fail-under=10 + +# Interpret the stdin as a python script, whose filename needs to be passed as +# the module_or_package argument. +#from-stdin= + +# Files or directories to be skipped. They should be base names, not paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the ignore-list. The +# regex matches against paths and can be in Posix or Windows format. +ignore-paths= + +# Files or directories matching the regex patterns are skipped. The regex +# matches against base names, not paths. The default value ignores Emacs file +# locks +ignore-patterns=^\.# + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=1 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Minimum Python version to use for version dependent checks. Will default to +# the version used to run pylint. +py-version=3.6 + +# Discover python modules and packages in the file system subtree. +recursive=no + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# In verbose mode, extra non-checker-related info will be displayed. +#verbose= + + +[REPORTS] + +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'fatal', 'error', 'warning', 'refactor', +# 'convention', and 'info' which contain the number of messages in each +# category, as well as 'statement' which is the total number of statements +# analyzed. This score is used by the global evaluation report (RP0004). +evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +#output-format= + +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, +# UNDEFINED. +confidence=HIGH, + CONTROL_FLOW, + INFERENCE, + INFERENCE_FAILURE, + UNDEFINED + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then re-enable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=raw-checker-failed, + bad-inline-option, + locally-disabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead + attribute-defined-outside-init, + invalid-name, + missing-docstring, + protected-access, + too-few-public-methods, + format, # handled by black + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. If left empty, argument names will be checked with the set +# naming style. +#argument-rgx= + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. If left empty, attribute names will be checked with the set naming +# style. +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +bad-names-rgxs= + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. If left empty, class attribute names will be checked +# with the set naming style. +#class-attribute-rgx= + +# Naming style matching correct class constant names. +class-const-naming-style=UPPER_CASE + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. If left empty, class constant names will be checked with +# the set naming style. +#class-const-rgx= + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming- +# style. If left empty, class names will be checked with the set naming style. +#class-rgx= + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style. If left empty, constant names will be checked with the set naming +# style. +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style. If left empty, function names will be checked with the set +# naming style. +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _ + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +good-names-rgxs= + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=no + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. If left empty, inline iteration names will be checked +# with the set naming style. +#inlinevar-rgx= + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style. If left empty, method names will be checked with the set naming style. +#method-rgx= + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style. If left empty, module names will be checked with the set naming style. +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty + +# Regular expression matching correct type variable names. If left empty, type +# variable names will be checked with the set naming style. +#typevar-rgx= + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. If left empty, variable names will be checked with the set +# naming style. +#variable-rgx= + + +[CLASSES] + +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=no + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp, + __post_init__ + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=cls + + +[DESIGN] + +# List of regular expressions of class ancestor names to ignore when counting +# public methods (see R0903) +exclude-too-few-public-methods= + +# List of qualified class names to ignore when counting class parents (see +# R0901) +ignored-parents= + +# Maximum number of arguments for function / method. +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=12 + +# Maximum number of locals for function / method body. +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when caught. +overgeneral-exceptions=BaseException, + Exception + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module. +max-module-lines=1000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules= + +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). +ext-import-graph= + +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). +import-graph= + +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= + + +[LOGGING] + +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style=old + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules=logging + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + +# Regular expression of note tags to take in consideration. +notes-rgx= + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit,argparse.parse_error + + +[SIMILARITIES] + +# Comments are removed from the similarity computation +ignore-comments=yes + +# Docstrings are removed from the similarity computation +ignore-docstrings=yes + +# Imports are removed from the similarity computation +ignore-imports=yes + +# Signatures are removed from the similarity computation +ignore-signatures=yes + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it work, +# install the 'python-enchant' package. +spelling-dict= + +# List of comma separated words that should be considered directives if they +# appear at the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=no + + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=no + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of symbolic message names to ignore for Mixin members. +ignored-checks-for-mixins=no-member, + not-async-context-manager, + not-context-manager, + attribute-defined-outside-init + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# Regex pattern to define which classes are considered mixins. +mixin-class-rgx=.*[Mm]ixin + +# List of decorators that change the signature of a decorated function. +signature-mutators= + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of names allowed to shadow builtins +allowed-redefined-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore. +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io From 76e52af6b2fca20d852edfc743aa0e185cf79261 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:48:29 +0200 Subject: [PATCH 130/152] fixed errors --- main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/main.py b/main.py index 27e46a8..31b14a1 100644 --- a/main.py +++ b/main.py @@ -30,6 +30,9 @@ 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." ) +""" +Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. +If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. """ client_id = os.getenv("REDDIT_CLIENT_ID") @@ -53,4 +56,43 @@ for val in REQUIRED_VALUES: if val not in os.environ or not os.getenv(val): console.log(f'[bold red]Missing Variable: "{val}"') configured = False + console.log( + "[red]Looks like you need to set your Reddit credentials in the .env file. Please follow the instructions in the README.md file to set them up." + ) + time.sleep(0.5) + console.log( + "[red]We can also launch the easy setup wizard. type yes to launch it, or no to quit the program." + ) + setup_ask = input("Launch setup wizard? > ") + if setup_ask == "yes": + console.log("[bold green]Here goes nothing! Launching setup wizard...") + time.sleep(0.5) + os.system("python3 setup.py") + + elif setup_ask == "no": + console.print("[red]Exiting...") + time.sleep(0.5) + exit() + else: + console.print("[red]I don't understand that. Exiting...") + time.sleep(0.5) + exit() +try: + float(os.getenv("OPACITY")) +except: + console.log( + f"[red]Please ensure that OPACITY is set between 0 and 1 in your .env file" + ) + configured = False + exit() +console.log("[bold green]Enviroment Variables are set! Continuing...") +if configured: + 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) + final_video = make_final_video(number_of_comments) From 2f61580af7907ccff11cffc0ed7c548f00266cbe Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:49:27 +0200 Subject: [PATCH 131/152] fixed error --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 31b14a1..eedc718 100644 --- a/main.py +++ b/main.py @@ -31,8 +31,10 @@ print_markdown( ) """ +- Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. +- """ client_id = os.getenv("REDDIT_CLIENT_ID") From c302d8c2e5d60e4177ed7b13e0c680121cba755e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Mon, 6 Jun 2022 23:51:23 +0200 Subject: [PATCH 132/152] fixed errors --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index eedc718..9aabe78 100644 --- a/main.py +++ b/main.py @@ -31,10 +31,10 @@ print_markdown( ) """ -- + Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. -- + """ client_id = os.getenv("REDDIT_CLIENT_ID") From eeeaff0a0497cbd1ec3ab4461667741ffb1fb791 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:50:30 +0200 Subject: [PATCH 133/152] gives user thread stats --- reddit/subreddit.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index c560293..d4c2cc9 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -57,7 +57,14 @@ def get_subreddit_threads(): threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] - print_substep(f"Video will be: {submission.title} :thumbsup:") + upvotes=submission.score + ratio=submission.upvote_ratio * 100 + num_comments=submission.num_comments + + console.log(f"[bold green] Video will be: {submission.title} :thumbsup:") + console.log(f"[bold blue] Thread has " + str(upvotes) + " upvotes") + 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 From 232b4442510e6a88e4591c41e06ea6b8a1bf2d17 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:52:02 +0200 Subject: [PATCH 134/152] Update final_video.py --- video_creation/final_video.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 93bac6f..8e1c5de 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -12,6 +12,9 @@ import re from utils.console import print_step from dotenv import load_dotenv import os +from rich.console import Console +console = Console() + W, H = 1080, 1920 @@ -47,6 +50,11 @@ def make_final_video(number_of_clips): audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) + #Get sum of all clip lengths + total_length = sum([clip.duration for clip in audio_clips]) + #Output Length + console.log("[bold green] Video Will Be: " + str(total_length) + " Seconds Long") + # Gather all images image_clips = [] for i in range(0, number_of_clips): From bafe8c3616d003076943d69db99d9ef7ff3b3f6e Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:52:21 +0200 Subject: [PATCH 135/152] Update screenshot_downloader.py --- video_creation/screenshot_downloader.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index d3d32ef..1e1ae21 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -3,6 +3,8 @@ from pathlib import Path from rich.progress import track from utils.console import print_step, print_substep import json +from rich.console import Console +console = Console() def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): @@ -43,9 +45,12 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): ) for idx, comment in track( - enumerate(reddit_object["comments"]), "Downloading screenshots..." + enumerate(reddit_object["comments"]) ): + #allow user to see what comment is being saved + print_substep(f"Downloading screenshot {idx + 1}") + # Stop if we have reached the screenshot_num if idx >= screenshot_num: break @@ -57,6 +62,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): page.locator(f"#t1_{comment['comment_id']}").screenshot( path=f"assets/png/comment_{idx}.png" ) - - print_substep("Screenshots downloaded Successfully.", - style="bold green") + + #let user know that the screenshots are done + console.log(f"[bold green]Saved {idx + 1} screenshots.") + From 9b25603bba6b5d4b3b426655b2f583bd8fc1d705 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:52:44 +0200 Subject: [PATCH 136/152] Update voices.py --- video_creation/voices.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index c0df8b7..9ac6aac 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,7 +3,8 @@ from pathlib import Path from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track - +from rich.console import Console +console = Console() def save_text_to_mp3(reddit_obj): """Saves Text to MP3 files. @@ -31,7 +32,11 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/posttext.mp3") length += MP3(f"assets/mp3/posttext.mp3").info.length - for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): + for idx, comment in track(enumerate(reddit_obj["comments"])): + + #allow user to see what comment is being saved + print_substep(f"Saving MP3 {idx + 1} ") + # ! 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 @@ -39,6 +44,7 @@ def save_text_to_mp3(reddit_obj): 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") + #let user know that the MP3 files are saved + console.log(f"[bold green]Saved {idx + 1} MP3 Files.") # ! Return the index so we know how many screenshots of comments we need to make. return length, idx From c24234aa5362f129382e38adbd1a50f591ef1d56 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 01:53:19 +0200 Subject: [PATCH 137/152] Update main.py --- main.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9aabe78..5d701d3 100644 --- a/main.py +++ b/main.py @@ -25,6 +25,27 @@ REQUIRED_VALUES = [ "OPACITY", ] +#create an giant banner +banner = ''' + +β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β€ƒβ€ƒβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ +β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β€ƒβ€ƒβ–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— +β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ•šβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ +β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ–‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ +β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–‘β€ƒβ€ƒβ–‘β–‘β•šβ–ˆβ–ˆβ•”β•β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• +β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β€ƒβ€ƒβ–‘β–‘β–‘β•šβ•β•β–‘β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘ + +β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ +β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— +β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•β•β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• +β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•”β•β•β•β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— +β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘ +β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β–‘β–‘β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β–‘β–‘β•šβ•β• + +''' +print(banner) + +time.sleep(.5) 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." @@ -46,7 +67,7 @@ reddit2fa = os.getenv("REDDIT_2FA") load_dotenv() console.log("[bold green]Checking environment variables...") -time.sleep(1) +time.sleep(.5) if not os.path.exists(".env"): From 5fb9b1a6c35fb835b0815c6971bfdc4ba5dba1a7 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Tue, 7 Jun 2022 02:14:21 +0200 Subject: [PATCH 138/152] Added Disclaimer "Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH" The banner may look bad or wrong in IDE/Text Editor but looks perfect in CMD, BASH, or ZSH. Don't worry looks great when in actual use! --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index e10aa67..8ae743d 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,7 @@ REQUIRED_VALUES = [ "OPACITY", ] -#create an giant banner +#Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH banner = ''' β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β€ƒβ€ƒβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘ @@ -42,6 +42,8 @@ banner = ''' ''' print(banner) +#Banner may look bad or wrong in IDE/Text Editor, but looks perfect in CMD, BASH or ZSH + time.sleep(.5) print_markdown( From 2234a5c973677c51e177f99648e5e781a4754034 Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Tue, 7 Jun 2022 13:03:29 +0300 Subject: [PATCH 139/152] fixed image hyperlink --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 56f4581..8b06174 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@ All done WITHOUT video editing or asset compiling. Just pure ✨programming magi Created by Lewis Menelaws & [TMRRW](https://tmrrwinc.ca) -[ - +[ -](https://tmrrwinc.ca) +](https://tmrrwinc.ca) ## Motivation πŸ€” @@ -35,7 +34,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 2. Run `pip3 install -r requirements.txt` 3. Run `playwright install` and `playwright install-deps`. -4. +4. 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. 4b **Manual Install**: 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. From afd89a7ef82490f6e56d4fc64fbe623c231c730a Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Tue, 7 Jun 2022 13:06:01 +0300 Subject: [PATCH 140/152] merge conflict --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b06174..30723ca 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 1. Clone this repository 2. Run `pip3 install -r requirements.txt` -3. Run `playwright install` and `playwright install-deps`. +3. Run `python3 -m playwright install` and `python3 -m playwright install-deps`. 4. 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. From 914f8679ae9a4a9ccf745b1f1e575b27a526ce6f Mon Sep 17 00:00:00 2001 From: CordlessCoder Date: Tue, 7 Jun 2022 13:06:54 +0300 Subject: [PATCH 141/152] merge conflict --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30723ca..8596ee7 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ These videos on TikTok, YouTube and Instagram get MILLIONS of views across all p 2. Run `pip3 install -r requirements.txt` 3. Run `python3 -m playwright install` and `python3 -m playwright install-deps`. -4. +4. 4a **Automatic Install**: Run `python3 main.py` and type 'yes' to activate the setup assistant. 4b **Manual Install**: 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. From 50cca3183d252d44230360161dbe913c93c39174 Mon Sep 17 00:00:00 2001 From: Phlipde <65417693+Phlipde@users.noreply.github.com> Date: Tue, 7 Jun 2022 18:45:18 +0200 Subject: [PATCH 142/152] Removed "Click to see nsfw" Button in Screenshot --- video_creation/screenshot_downloader.py | 1 + 1 file changed, 1 insertion(+) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 2925daa..d1f5719 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -38,6 +38,7 @@ def download_screenshots_of_reddit_posts(reddit_object, screenshot_num, theme): print_substep("Post is NSFW. You are spicy...") page.locator('[data-testid="content-gate"] button').click() + page.locator('[data-click-id="text"] button').click() # Remove "Click to see nsfw" Button in Screenshot page.locator('[data-test-id="post-content"]').screenshot( path="assets/png/title.png" From 5bf088846028fa479863311ab576057d0c1336a1 Mon Sep 17 00:00:00 2001 From: Domiziano Scarcelli Date: Wed, 8 Jun 2022 00:23:29 +0200 Subject: [PATCH 143/152] Removed unused imports --- video_creation/final_video.py | 1 - 1 file changed, 1 deletion(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index d9463bb..96be579 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,4 +1,3 @@ -from click import style from moviepy.editor import ( VideoFileClip, AudioFileClip, From abbb496012e52e2396ed1d5b45d2b3a685535215 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:16:35 +0200 Subject: [PATCH 144/152] round video length turns 'total_length' into an int, instead of float. --- video_creation/final_video.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 9b96f3c..b3a0df6 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -8,7 +7,7 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.subreddit +import reddit.subreddit import re from utils.console import print_step from dotenv import load_dotenv @@ -20,12 +19,13 @@ console = Console() W, H = 1080, 1920 -def make_final_video(number_of_clips): +def make_final_video(number_of_clips): + # Calls opacity from the .env load_dotenv() - opacity = os.getenv("OPACITY") - + opacity = os.getenv('OPACITY') + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) @@ -42,9 +42,9 @@ def make_final_video(number_of_clips): audio_clips = [] for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) - audio_clips.insert(0, AudioFileClip("assets/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) try: - audio_clips.insert(1, AudioFileClip("assets/mp3/posttext.mp3")) + audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) except: OSError() audio_concat = concatenate_audioclips(audio_clips) @@ -52,8 +52,10 @@ def make_final_video(number_of_clips): #Get sum of all clip lengths total_length = sum([clip.duration for clip in audio_clips]) + #round total_length to an integer + int_total_length=round(total_length) #Output Length - console.log("[bold green] Video Will Be: " + str(total_length) + " Seconds Long") + console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long") # Gather all images image_clips = [] @@ -65,32 +67,30 @@ def make_final_video(number_of_clips): .resize(width=W - 100) .set_opacity(float(opacity)), ) - if os.path.exists("assets/mp3/posttext.mp3"): + if os.path.exists(f"assets/mp3/posttext.mp3"): image_clips.insert( 0, - ImageClip("assets/png/title.png") + ImageClip(f"assets/png/title.png") .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) else: image_clips.insert( 0, - ImageClip("assets/png/title.png") + ImageClip(f"assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = re.sub( - '[?"%*:|<>]', "", ("assets/" + reddit.subreddit.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 31a4e825f1e45988f4f33e5927fbe6198130cab5 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:22:19 +0200 Subject: [PATCH 145/152] fixed merge issues --- video_creation/final_video.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 58706d4..b3a0df6 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -9,7 +9,7 @@ from moviepy.editor import ( ) import reddit.subreddit import re -from utils.console import print_step, print_substep +from utils.console import print_step from dotenv import load_dotenv import os from rich.console import Console @@ -92,15 +92,5 @@ def make_final_video(number_of_clips): final = CompositeVideoClip([background_clip, image_concat]) filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))) final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") - final_video_path = "assets/" - if os.getenv("FINAL_VIDEO_PATH"): - final_video_path = os.getenv("FINAL_VIDEO_PATH") - filename = (re.sub('[?\"%*:|<>]', '', (final_video_path + reddit.subreddit.submission.title + ".mp4"))) - try: - final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") - except: - print_substep("Something's wrong with the path you inserted, the video will be saved in the default path (assets/)", style="bold red") - 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 2004f7c0a5129524e4f4c0a585c23e5e1c7bd4e4 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:25:31 +0200 Subject: [PATCH 146/152] fixed merge errors --- video_creation/final_video.py | 46 ++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index b3a0df6..a1ad0e1 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from moviepy.editor import ( VideoFileClip, AudioFileClip, @@ -7,25 +8,21 @@ from moviepy.editor import ( CompositeAudioClip, CompositeVideoClip, ) -import reddit.subreddit +import reddit.subreddit import re -from utils.console import print_step +from utils.console import print_step, print_substep from dotenv import load_dotenv import os -from rich.console import Console -console = Console() - W, H = 1080, 1920 - def make_final_video(number_of_clips): - + # Calls opacity from the .env load_dotenv() - opacity = os.getenv('OPACITY') - + opacity = os.getenv("OPACITY") + print_step("Creating the final video...") VideoFileClip.reW = lambda clip: clip.resize(width=W) @@ -42,20 +39,21 @@ def make_final_video(number_of_clips): audio_clips = [] for i in range(0, number_of_clips): audio_clips.append(AudioFileClip(f"assets/mp3/{i}.mp3")) - audio_clips.insert(0, AudioFileClip(f"assets/mp3/title.mp3")) + audio_clips.insert(0, AudioFileClip("assets/mp3/title.mp3")) try: - audio_clips.insert(1, AudioFileClip(f"assets/mp3/posttext.mp3")) + audio_clips.insert(1, AudioFileClip("assets/mp3/posttext.mp3")) except: OSError() audio_concat = concatenate_audioclips(audio_clips) audio_composite = CompositeAudioClip([audio_concat]) - - #Get sum of all clip lengths + + #Get sum of all clip lengths total_length = sum([clip.duration for clip in audio_clips]) #round total_length to an integer int_total_length=round(total_length) #Output Length console.log(f"[bold green] Video Will Be: {int_total_length} Seconds Long") + # Gather all images image_clips = [] @@ -67,30 +65,38 @@ def make_final_video(number_of_clips): .resize(width=W - 100) .set_opacity(float(opacity)), ) - if os.path.exists(f"assets/mp3/posttext.mp3"): + if os.path.exists("assets/mp3/posttext.mp3"): image_clips.insert( 0, - ImageClip(f"assets/png/title.png") + ImageClip("assets/png/title.png") .set_duration(audio_clips[0].duration + audio_clips[1].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) else: image_clips.insert( 0, - ImageClip(f"assets/png/title.png") + ImageClip("assets/png/title.png") .set_duration(audio_clips[0].duration) .set_position("center") .resize(width=W - 100) .set_opacity(float(opacity)), - ) + ) image_concat = concatenate_videoclips(image_clips).set_position( ("center", "center") ) image_concat.audio = audio_composite final = CompositeVideoClip([background_clip, image_concat]) - filename = (re.sub('[?\"%*:|<>]', '', ("assets/" + reddit.subreddit.submission.title + ".mp4"))) - final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") + final_video_path = "assets/" + if os.getenv("FINAL_VIDEO_PATH"): + final_video_path = os.getenv("FINAL_VIDEO_PATH") + filename = (re.sub('[?\"%*:|<>]', '', (final_video_path + reddit.subreddit.submission.title + ".mp4"))) + try: + final.write_videofile(filename, fps=30, audio_codec="aac", audio_bitrate="192k") + except: + print_substep("Something's wrong with the path you inserted, the video will be saved in the default path (assets/)", style="bold red") + 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 6af6b4136b4bf2552bf580092ac4bbf12dca38a9 Mon Sep 17 00:00:00 2001 From: null3000 <76852813+null3000@users.noreply.github.com> Date: Wed, 8 Jun 2022 22:51:40 +0200 Subject: [PATCH 147/152] fixed merge errors --- reddit/subreddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 3f3b24f..249f902 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -65,7 +65,7 @@ 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 From acb6017d5bc2c851ed97912565b5bf4e6b369ace Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:01:16 +0100 Subject: [PATCH 148/152] chore(env): clarify definitions, include defaults --- .env.template | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index 5830840..f3a2fc8 100644 --- a/.env.template +++ b/.env.template @@ -1,3 +1,4 @@ +# This can be found in the email that reddit sent you when you created the app REDDIT_CLIENT_ID="" REDDIT_CLIENT_SECRET="" @@ -5,15 +6,17 @@ REDDIT_USERNAME="" REDDIT_PASSWORD="" # Valid options are "yes" and "no" + +# Whether or not 2FA is enabled on the reddit account. Default: "no" REDDIT_2FA="" -#If no, it will ask you a thread link to extract the thread, if yes it will randomize it. -RANDOM_THREAD="yes" +# If no, it will ask you a thread link to extract the thread, if yes it will randomize it. Default: "no" +RANDOM_THREAD="" -# Valid options are "light" and "dark" +# Valid options are "light" and "dark". Default: "light" THEME="" -# Enter a subreddit, e.g. "AskReddit" +# Enter a subreddit, e.g. "AskReddit". SUBREDDIT="" # Filters the comments by range of lenght (min and max characters) @@ -21,7 +24,7 @@ SUBREDDIT="" # DO NOT INSERT ANY SPACES BETWEEN THE COMMA AND THE VALUES COMMENT_LENGTH_RANGE = "min,max" -# Range is 0 -> 1 +# Range is 0 -> 1. Default: "0.9" OPACITY="0.9" # The absolute path of the folder where you want to save the final video From 8472915cf912f34bddb7618b7c338711497c0d82 Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:01:39 +0100 Subject: [PATCH 149/152] chore: remove debug statements and clean up --- main.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/main.py b/main.py index cade990..6b0e825 100644 --- a/main.py +++ b/main.py @@ -2,14 +2,13 @@ # Main from utils.console import print_markdown from rich.console import Console -import time 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 from video_creation.final_video import make_final_video from dotenv import load_dotenv -import os +import time, os console = Console() @@ -22,16 +21,13 @@ REQUIRED_VALUES = [ "OPACITY", ] - 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." ) """ - Load .env file if exists. If it doesnt exist, print a warning and launch the setup wizard. If there is a .env file, check if the required variables are set. If not, print a warning and launch the setup wizard. - """ client_id = os.getenv("REDDIT_CLIENT_ID") @@ -45,13 +41,11 @@ load_dotenv() console.log("[bold green]Checking environment variables...") time.sleep(1) - if not os.path.exists(".env"): configured = False console.log("[red] Your .env file is invalid, or was never created. Standby.") for val in REQUIRED_VALUES: - # print(os.getenv(val)) if val not in os.environ or not os.getenv(val): console.log(f'[bold red]Missing Variable: "{val}"') configured = False From f6be3d2f1a4111d965f0fb68019c4324e9abf2d6 Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:09:34 +0100 Subject: [PATCH 150/152] fix(subreddit): Exception thrown if any value in `COMMENT_LENGTH_RANGE` is not numeric --- reddit/subreddit.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 40c95b6..bf9be74 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -2,14 +2,10 @@ from numpy import Infinity from rich.console import Console from utils.console import print_step, print_substep, print_markdown from dotenv import load_dotenv -import os -import random -import praw -import re +import os, random, praw, re console = Console() - def get_subreddit_threads(): global submission """ @@ -49,7 +45,7 @@ def get_subreddit_threads(): if os.getenv("SUBREDDIT"): subreddit = reddit.subreddit(re.sub(r"r\/", "", os.getenv("SUBREDDIT"))) else: - # ! Prompt the user to enter a subreddit + # Prompt the user to enter a subreddit try: subreddit = reddit.subreddit( re.sub( @@ -64,7 +60,7 @@ def get_subreddit_threads(): threads = subreddit.hot(limit=25) submission = list(threads)[random.randrange(0, 25)] - + print_substep(f"Video will be: {submission.title}") print("Getting video comments...") @@ -76,8 +72,13 @@ def get_subreddit_threads(): for top_level_comment in submission.comments: COMMENT_LENGTH_RANGE = [0, Infinity] - if os.getenv("COMMENT_LENGTH_RANGE"): - COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")] + + # Ensure all values are numeric before attempting to cast + if os.getenv("COMMENT_LENGTH_RANGE") and (False not in list(map(lambda arg: arg.isnumeric(), os.getenv("COMMENT_LENGTH_RANGE").split(",")))): + try: + COMMENT_LENGTH_RANGE = [int(i) for i in os.getenv("COMMENT_LENGTH_RANGE").split(",")] + except TypeError: + pass if COMMENT_LENGTH_RANGE[0] <= len(top_level_comment.body) <= COMMENT_LENGTH_RANGE[1]: if not top_level_comment.stickied: content["comments"].append( @@ -87,9 +88,9 @@ def get_subreddit_threads(): "comment_id": top_level_comment.id, } ) - except AttributeError: pass - print_substep("Received AskReddit threads successfully.", style="bold green") + print_substep("Received AskReddit threads successfully.", style="bold green") + print(content["comments"]) return content From fc980a4a734807796c06339790eee1bb049cc9fb Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:20:36 +0100 Subject: [PATCH 151/152] chore(env): clarify default value mapping for `SUBREDDIT` --- .env.template | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index f3a2fc8..2ff25d7 100644 --- a/.env.template +++ b/.env.template @@ -16,7 +16,8 @@ RANDOM_THREAD="" # Valid options are "light" and "dark". Default: "light" THEME="" -# Enter a subreddit, e.g. "AskReddit". +# Enter a subreddit, e.g. "AskReddit". If this isn't defined, you'll be asked when +# the programme runs. Simply press Enter if you wish to use the default "AskReddit" subreddit when prompted. SUBREDDIT="" # Filters the comments by range of lenght (min and max characters) From a4e7963d511f75709518f814f86d3301a3608c55 Mon Sep 17 00:00:00 2001 From: Asad Date: Sat, 11 Jun 2022 01:36:24 +0100 Subject: [PATCH 152/152] remove debug statement --- reddit/subreddit.py | 1 - setup.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/reddit/subreddit.py b/reddit/subreddit.py index bf9be74..6d002e6 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -92,5 +92,4 @@ def get_subreddit_threads(): pass print_substep("Received AskReddit threads successfully.", style="bold green") - print(content["comments"]) return content diff --git a/setup.py b/setup.py index b09c30d..640cd26 100755 --- a/setup.py +++ b/setup.py @@ -92,7 +92,7 @@ if input("Are you sure you want to continue? > ").strip().casefold() != "yes": # Once they confirm, move on with the script. console.print("[bold green]Alright! Let's get started!") -print("\n") +print() console.log("Ensure you have the following ready to enter:") console.log("[bold green]Reddit Client ID") console.log("[bold green]Reddit Client Secret")