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/7] 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/7] 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/7] 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/7] 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/7] 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/7] 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/7] 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