From 593094d14b075eec523382154a84f25c043237e1 Mon Sep 17 00:00:00 2001 From: andronedev Date: Thu, 2 Jun 2022 21:49:38 +0200 Subject: [PATCH] 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")