From 1cc8f40e2c789418049ec5ff35d67ea0f20ce191 Mon Sep 17 00:00:00 2001 From: Simon <65854503+OpenSourceSimon@users.noreply.github.com> Date: Thu, 13 Apr 2023 16:48:58 +0200 Subject: [PATCH 1/9] Fix autoblack --- .github/workflows/autoblack.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/autoblack.yml b/.github/workflows/autoblack.yml index ba9cc36..60bf35c 100644 --- a/.github/workflows/autoblack.yml +++ b/.github/workflows/autoblack.yml @@ -29,4 +29,4 @@ jobs: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY git checkout $GITHUB_HEAD_REF git commit -am "fixup: Format Python code with Black" - git push + git push origin HEAD:master From 6c29ad91720291b32fefedff836267e2e7eb58f2 Mon Sep 17 00:00:00 2001 From: "codesee-maps[bot]" <86324825+codesee-maps[bot]@users.noreply.github.com> Date: Thu, 13 Apr 2023 19:58:29 +0000 Subject: [PATCH 2/9] Install the CodeSee workflow. Learn more at https://docs.codesee.io --- .github/workflows/codesee-arch-diagram.yml | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/codesee-arch-diagram.yml diff --git a/.github/workflows/codesee-arch-diagram.yml b/.github/workflows/codesee-arch-diagram.yml new file mode 100644 index 0000000..a72f58b --- /dev/null +++ b/.github/workflows/codesee-arch-diagram.yml @@ -0,0 +1,23 @@ +# This workflow was added by CodeSee. Learn more at https://codesee.io/ +# This is v2.0 of this workflow file +on: + push: + branches: + - master + pull_request_target: + types: [opened, synchronize, reopened] + +name: CodeSee + +permissions: read-all + +jobs: + codesee: + runs-on: ubuntu-latest + continue-on-error: true + name: Analyze the repo with CodeSee + steps: + - uses: Codesee-io/codesee-action@v2 + with: + codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }} + codesee-url: https://app.codesee.io From c5abb1a63ef57e2d8f75c1241649ce0a2d9b5eb6 Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 12:13:48 +1000 Subject: [PATCH 3/9] adds zoom support --- utils/.config.template.toml | 1 + video_creation/screenshot_downloader.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/utils/.config.template.toml b/utils/.config.template.toml index b2fa1d4..8c833ef 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -31,6 +31,7 @@ storymodemethod= { optional = true, default = 1, example = 1, explanation = "Sty storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } resolution_w = { optional = false, default = 1080, example = 1440, explantation = "Sets the width in pixels of the final video" } resolution_h = { optional = false, default = 1920, example = 2560, explantation = "Sets the height in pixels of the final video" } +zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger." type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" } [settings.background] background_choice = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" } diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 1c3ab5e..823f8fa 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -120,6 +120,8 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # Get the thread screenshot page.goto(reddit_object["thread_url"], timeout=0) page.set_viewport_size(ViewportSize(width=W, height=H)) + if(settings.config["settings"]["zoom"] != 1): + page.evaluate("document.body.style.zoom="+str(settings.config["settings"]["zoom"])) page.wait_for_load_state() page.wait_for_timeout(5000) From a7f21349c69d938617d28371b5f0d738abf4f1b9 Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 12:15:26 +1000 Subject: [PATCH 4/9] missing comma --- utils/.config.template.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 8c833ef..e6fa558 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -31,7 +31,7 @@ storymodemethod= { optional = true, default = 1, example = 1, explanation = "Sty storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } resolution_w = { optional = false, default = 1080, example = 1440, explantation = "Sets the width in pixels of the final video" } resolution_h = { optional = false, default = 1920, example = 2560, explantation = "Sets the height in pixels of the final video" } -zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger." type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" } +zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger.", type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" } [settings.background] background_choice = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" } From e426baed2ab675d846c1acd8f95cd320b44170c1 Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 12:34:47 +1000 Subject: [PATCH 5/9] reset --- utils/.config.template.toml | 1 - video_creation/screenshot_downloader.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/utils/.config.template.toml b/utils/.config.template.toml index e6fa558..b2fa1d4 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -31,7 +31,6 @@ storymodemethod= { optional = true, default = 1, example = 1, explanation = "Sty storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } resolution_w = { optional = false, default = 1080, example = 1440, explantation = "Sets the width in pixels of the final video" } resolution_h = { optional = false, default = 1920, example = 2560, explantation = "Sets the height in pixels of the final video" } -zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger.", type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" } [settings.background] background_choice = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" } diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 823f8fa..1c3ab5e 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -120,8 +120,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # Get the thread screenshot page.goto(reddit_object["thread_url"], timeout=0) page.set_viewport_size(ViewportSize(width=W, height=H)) - if(settings.config["settings"]["zoom"] != 1): - page.evaluate("document.body.style.zoom="+str(settings.config["settings"]["zoom"])) page.wait_for_load_state() page.wait_for_timeout(5000) From 1bd927e57eb356330692cf52efbbac5e0803a03c Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 12:35:33 +1000 Subject: [PATCH 6/9] adds zoom support --- utils/.config.template.toml | 1 + video_creation/screenshot_downloader.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/utils/.config.template.toml b/utils/.config.template.toml index b2fa1d4..e6fa558 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -31,6 +31,7 @@ storymodemethod= { optional = true, default = 1, example = 1, explanation = "Sty storymode_max_length = { optional = true, default = 1000, example = 1000, explanation = "Max length of the storymode video in characters. 200 characters are approximately 50 seconds.", type = "int", nmin = 1, oob_error = "It's very hard to make a video under a second." } resolution_w = { optional = false, default = 1080, example = 1440, explantation = "Sets the width in pixels of the final video" } resolution_h = { optional = false, default = 1920, example = 2560, explantation = "Sets the height in pixels of the final video" } +zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the browser zoom level. Useful if you want the text larger.", type = "float", nmin = 0.1, nmax = 2, oob_error = "The text is really difficult to read at a zoom level higher than 2" } [settings.background] background_choice = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" } diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 1c3ab5e..823f8fa 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -120,6 +120,8 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # Get the thread screenshot page.goto(reddit_object["thread_url"], timeout=0) page.set_viewport_size(ViewportSize(width=W, height=H)) + if(settings.config["settings"]["zoom"] != 1): + page.evaluate("document.body.style.zoom="+str(settings.config["settings"]["zoom"])) page.wait_for_load_state() page.wait_for_timeout(5000) From f8ceee035d443471c4b3c4664750e97c4b6eb7ce Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 13:32:52 +1000 Subject: [PATCH 7/9] fix zoom cropping issue --- video_creation/screenshot_downloader.py | 37 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 823f8fa..0ce9845 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -120,8 +120,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): # Get the thread screenshot page.goto(reddit_object["thread_url"], timeout=0) page.set_viewport_size(ViewportSize(width=W, height=H)) - if(settings.config["settings"]["zoom"] != 1): - page.evaluate("document.body.style.zoom="+str(settings.config["settings"]["zoom"])) page.wait_for_load_state() page.wait_for_timeout(5000) @@ -160,9 +158,20 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): postcontentpath = f"assets/temp/{reddit_id}/png/title.png" try: - page.locator('[data-test-id="post-content"]').screenshot( - path=postcontentpath - ) + if(settings.config["settings"]["zoom"] != 1): + # store zoom settings + zoom = settings.config["settings"]["zoom"] + # zoom the body of the page + page.evaluate("document.body.style.zoom="+str(zoom)) + # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom + location = page.locator('[data-test-id="post-content"]').bounding_box() + for i in location: + location[i] = float("{:.2f}".format(location[i]*zoom)) + page.screenshot(clip=location, path=postcontentpath) + else: + page.locator('[data-test-id="post-content"]').screenshot( + path=postcontentpath + ) except Exception as e: print_substep("Something went wrong!", style="red") resp = input( @@ -216,9 +225,21 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int): [comment_tl, comment["comment_id"]], ) try: - page.locator(f"#t1_{comment['comment_id']}").screenshot( - path=f"assets/temp/{reddit_id}/png/comment_{idx}.png" - ) + if(settings.config["settings"]["zoom"] != 1): + # store zoom settings + zoom = settings.config["settings"]["zoom"] + # zoom the body of the page + page.evaluate("document.body.style.zoom="+str(zoom)) + # as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom + location = page.locator(f"#t1_{comment['comment_id']}").bounding_box() + for i in location: + location[i] = float("{:.2f}".format(location[i]*zoom)) + page.screenshot(clip=location, path=f"assets/temp/{reddit_id}/png/comment_{idx}.png") + else: + page.locator(f"#t1_{comment['comment_id']}").screenshot( + path=f"assets/temp/{reddit_id}/png/comment_{idx}.png" + ) + except TimeoutError: del reddit_object["comments"] screenshot_num += 1 From ded12d8b156000cd5682e26c34756c5c2333a1ab Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 14:14:33 +1000 Subject: [PATCH 8/9] Adds background audio --- utils/.config.template.toml | 4 ++-- video_creation/final_video.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/utils/.config.template.toml b/utils/.config.template.toml index e6fa558..3ab2a18 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -35,8 +35,8 @@ zoom = { optional = true, default = 1, example = 1.1, explanation = "Sets the br [settings.background] background_choice = { optional = true, default = "minecraft", example = "rocket-league", options = ["minecraft", "gta", "rocket-league", "motor-gta", "csgo-surf", "cluster-truck", "minecraft-2","multiversus","fall-guys","steep", ""], explanation = "Sets the background for the video based on game name" } -#background_audio = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Sets a audio to play in the background (put a background.mp3 file in the assets/backgrounds directory for it to be used.)" } -#background_audio_volume = { optional = true, type = "float", default = 0.3, example = 0.1, explanation="Sets the volume of the background audio. only used if the background_audio is also set to true" } +background_audio = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Sets a audio to play in the background (put a background.mp3 file in the assets/backgrounds directory for it to be used.)" } +background_audio_volume = { optional = true, type = "float", default = 0.3, example = 0.1, explanation="Sets the volume of the background audio. only used if the background_audio is also set to true" } background_thumbnail = { optional = true, type = "bool", default = false, example = false, options = [true, false,], explanation = "Generate a thumbnail for the video (put a thumbnail.png file in the assets/backgrounds directory.)" } background_thumbnail_font_family = { optional = true, default = "arial", example = "arial", explanation = "Font family for the thumbnail text" } background_thumbnail_font_size = { optional = true, type = "int", default = 96, example = 96, explanation = "Font size in pixels for the thumbnail text" } diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 4838574..7ef9c2b 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -177,6 +177,14 @@ def make_final_video( screenshot_width = int((W * 45) // 100) audio = ffmpeg.input(f"assets/temp/{reddit_id}/audio.mp3") + # adds background audio + if settings.config["settings"]['background']["background_audio"] and exists(f"assets/backgrounds/background.mp3"): + # sets volume to config + bg_audio = ffmpeg.input(f"assets/backgrounds/background.mp3").filter('volume', settings.config["settings"]['background']["background_audio_volume"]) + # merges audio and bg_audio + merged_audio = ffmpeg.filter([audio, bg_audio], 'amix', duration='first') + # sets final audio to merged audio + audio = merged_audio image_clips = list() From c94e976b89d9dc1e7417f2a0579175f7b40678cc Mon Sep 17 00:00:00 2001 From: liamb Date: Sat, 15 Apr 2023 15:12:35 +1000 Subject: [PATCH 9/9] introducing chatgpt --- utils/.config.template.toml | 3 +++ utils/chatgpt.py | 31 +++++++++++++++++++++++++++++++ video_creation/final_video.py | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 utils/chatgpt.py diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 3ab2a18..28ca833 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -19,6 +19,9 @@ min_comments = { default = 20, optional = false, nmin = 10, type = "int", explan [ai] ai_similarity_enabled = {optional = true, option = [true, false], default = false, type = "bool", explanation = "Threads read from Reddit are sorted based on their similarity to the keywords given below"} ai_similarity_keywords = {optional = true, type="str", example= 'Elon Musk, Twitter, Stocks', explanation = "Every keyword or even sentence, seperated with comma, is used to sort the reddit threads based on similarity"} +use_openai = { optional = true, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to use OpenAI" } +openai_api_key = {optional = true, type="str", example= 'sk-1234-567', explanation = "If you want to access chatGPT you'll need to enter an API Key"} + [settings] allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to allow NSFW content, True or False" } diff --git a/utils/chatgpt.py b/utils/chatgpt.py new file mode 100644 index 0000000..fe07786 --- /dev/null +++ b/utils/chatgpt.py @@ -0,0 +1,31 @@ +import openai +from utils import settings +from utils.console import print_step + + +def get_video_details( + subreddit: str, filename: str, reddit_title: str +): + """Gets a title, description and tags from chatGPT and saves as a txt file + + Args: + @param subreddit: + @param reddit_title: + """ + print_step("Now asking ChatGPT for Video Details") + openai.api_key = settings.config["ai"]["openai_api_key"] + messages = [ {"role": "system", "content": + "You are a intelligent assistant."} ] + messages.append( + {"role": "user", "content": "I would like you to supply a video title, description and tags comma-separated for a video about: " + reddit_title}, + ) + chat = openai.ChatCompletion.create( + model="gpt-3.5-turbo", messages=messages + ) + reply = chat.choices[0].message.content + print(f"ChatGPT: {reply}") + path = f"results/{subreddit}/{filename}" + path = path[:251] + path = path + ".txt" + with open(path, 'w', encoding="utf-8") as f: + f.write(reply) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 7ef9c2b..db4d0ca 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -17,6 +17,7 @@ from utils.cleanup import cleanup from utils.console import print_step, print_substep from utils.thumbnail import create_thumbnail from utils.videos import save_data +from utils.chatgpt import get_video_details console = Console() @@ -355,6 +356,7 @@ def make_final_video( pbar.update(100 - old_percentage) pbar.close() + get_video_details(subreddit, filename, title) save_data(subreddit, filename + ".mp4", title, idx, background_config[2]) print_step("Removing temporary files 🗑") cleanups = cleanup(reddit_id)