From 46f9c2f278f89c4705b576bb19ab2c37d7b705e6 Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:33:34 +0100 Subject: [PATCH 1/9] add github action file to build docker package --- .github/workflows/github-image.yml | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/github-image.yml diff --git a/.github/workflows/github-image.yml b/.github/workflows/github-image.yml new file mode 100644 index 0000000..02e9f37 --- /dev/null +++ b/.github/workflows/github-image.yml @@ -0,0 +1,52 @@ +name: Github Registry + +on: + push: + branches: + - '**' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: Push Docker Image to Github Registry + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From 2b56ca3064f064e28afe0ae0c33bc24c70424e85 Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:34:14 +0100 Subject: [PATCH 2/9] add docker files --- docker/Dockerfile | 24 ++++++++++++++++++++++++ docker/download_chat.py | 10 ++++++++++ docker/entrypoint.sh | 14 ++++++++++++++ docker/requirements.txt | 1 + 4 files changed, 49 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/download_chat.py create mode 100644 docker/entrypoint.sh create mode 100644 docker/requirements.txt diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..13ce7e0 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.12 +LABEL maintainer="lauwarm@mailbox.org" + +WORKDIR /app + +RUN apt-get update && apt-get install gosu -y + +COPY requirements.txt /app/ +RUN pip install --no-cache-dir -r requirements.txt + +RUN echo 'export PATH="${HOME}/.local/bin:${PATH}"' + +COPY . /app + +RUN mkdir /home/download +RUN mkdir /home/script + +COPY ./entrypoint.sh /home/script/ + +RUN ["chmod", "+x", "/home/script/entrypoint.sh"] + +ENTRYPOINT [ "/home/script/entrypoint.sh" ] + +CMD python download_chat.py ${channelURL} ${channelName} \ No newline at end of file diff --git a/docker/download_chat.py b/docker/download_chat.py new file mode 100644 index 0000000..41e2722 --- /dev/null +++ b/docker/download_chat.py @@ -0,0 +1,10 @@ +import subprocess, sys +from datetime import datetime + +channel_url = sys.argv[1] +channel_name = sys.argv[2] + +now = datetime.now() +d1 = now.strftime("%Y%m%d-%H%M%S") + +subprocess.run(['chat_downloader', channel_url, '--output', "/home/download/"+channel_name+"-"+d1+'.json']) \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..95e916f --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Add local user and group +# Either use the uid and gid if passed in at runtime or +# fallback to 9001 + +USER_ID=${uid:-9001} +GROUP_ID=${gid:-9001} + +echo "UID : $USER_ID \nGID : $GROUP_ID" + +chown -R $USER_ID:$GROUP_ID /home/script + +exec gosu $USER_ID "$@" \ No newline at end of file diff --git a/docker/requirements.txt b/docker/requirements.txt new file mode 100644 index 0000000..2a7b3a3 --- /dev/null +++ b/docker/requirements.txt @@ -0,0 +1 @@ +chat-downloader==0.2.8 \ No newline at end of file From 8097b57abd1f27a71d8abd9ba813c93f9cf53caa Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:37:24 +0100 Subject: [PATCH 3/9] update readme with instructions for docker --- docs/README.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/README.rst b/docs/README.rst index 630f6e4..966c229 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -60,6 +60,11 @@ Alternatively, the tool can be installed with ``git``: $ cd chat-downloader $ python setup.py install +The tool can be used with ``docker``: + +.. code:: console + + $ docker run -v /path/to/download/:/home/download/ -e channelURL='https://www.twitch.tv/twitch' -e channelName='twitch' -e uid='1000' -e gid='1000' ghcr.io/xenova/chat-downloader:master ##### Usage @@ -99,6 +104,24 @@ Python For advanced python use-cases and examples, consult the :ref:`Python Documentation`. +Docker +------ + +.. code:: console + + /home/download - the place where the file will be saved. Mount it to a desired place with -v option. + + channelURL - the url of the stream you want to record. + + channelName - the name for the stream. + + uid - UserID, map to your desired User ID (fallback to 9001) + + gid - GroupID, map to your desired Group ID (fallback to 9001) + + +The File will be saved as streamName-YearMonthDate-HourMinuteSecond.json + ########## Chat Items ########## From 72f297f3672547b38b76e9452e6c741c1e14849e Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:47:10 +0100 Subject: [PATCH 4/9] update readme with instructions for docker --- README.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.rst b/README.rst index a256b6c..71c60ef 100644 --- a/README.rst +++ b/README.rst @@ -60,6 +60,12 @@ Alternatively, the tool can be installed with ``git``: $ cd chat-downloader $ python setup.py install +The tool can be used with ``docker``: + +.. code:: console + + $ docker run -v /path/to/download/:/home/download/ -e channelURL='https://www.twitch.tv/twitch' -e channelName='twitch' -e uid='1000' -e gid='1000' ghcr.io/xenova/chat-downloader:master + ##### Usage @@ -118,6 +124,25 @@ Python For advanced python use-cases and examples, consult the `Python Documentation `_. +Docker +------ + +.. code:: console + + /home/download - the place where the file will be saved. Mount it to a desired place with -v option. + + channelURL - the url of the stream you want to record. + + channelName - the name for the stream. + + uid - UserID, map to your desired User ID (fallback to 9001) + + gid - GroupID, map to your desired Group ID (fallback to 9001) + + +The File will be saved as streamName-YearMonthDate-HourMinuteSecond.json + + ########## Chat Items ########## From ed9378754b030a2365d26814b04759691d293efe Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:48:50 +0100 Subject: [PATCH 5/9] update github actions with update github action --- .github/workflows/github-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-image.yml b/.github/workflows/github-image.yml index 02e9f37..ee64253 100644 --- a/.github/workflows/github-image.yml +++ b/.github/workflows/github-image.yml @@ -46,7 +46,7 @@ jobs: id: build-and-push uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 with: - context: . + context: ./docker/ push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file From 13db8de2b30d7c97495a75d31df4cdc377acd279 Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:54:26 +0100 Subject: [PATCH 6/9] cleanup readme --- README.rst | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 71c60ef..8545b67 100644 --- a/README.rst +++ b/README.rst @@ -126,19 +126,12 @@ For advanced python use-cases and examples, consult the `Python Documentation Date: Sun, 17 Dec 2023 21:34:42 +0100 Subject: [PATCH 7/9] fix text --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 8545b67..5e12e46 100644 --- a/README.rst +++ b/README.rst @@ -133,7 +133,7 @@ Docker - **uid** - UserID, map to your desired User ID (fallback to 9001) - **gid** - GroupID, map to your desired Group ID (fallback to 9001) -The File will be saved as streamName-YearMonthDate-HourMinuteSecond.json +The File will be saved as channelName-YearMonthDate-HourMinuteSecond.json ########## From 90b81f97edfc866392485c3e0ab30b17076ff54e Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Tue, 23 Jan 2024 14:32:25 +0100 Subject: [PATCH 8/9] added an option to specify the file format --- docker/Dockerfile | 2 +- docker/download_chat.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 13ce7e0..b38d497 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,4 +21,4 @@ RUN ["chmod", "+x", "/home/script/entrypoint.sh"] ENTRYPOINT [ "/home/script/entrypoint.sh" ] -CMD python download_chat.py ${channelURL} ${channelName} \ No newline at end of file +CMD python download_chat.py ${channelURL} ${channelName} ${fileFormat} \ No newline at end of file diff --git a/docker/download_chat.py b/docker/download_chat.py index 41e2722..4b41337 100644 --- a/docker/download_chat.py +++ b/docker/download_chat.py @@ -3,8 +3,9 @@ channel_url = sys.argv[1] channel_name = sys.argv[2] +file_format = sys.argv[3] now = datetime.now() d1 = now.strftime("%Y%m%d-%H%M%S") -subprocess.run(['chat_downloader', channel_url, '--output', "/home/download/"+channel_name+"-"+d1+'.json']) \ No newline at end of file +subprocess.run(['chat_downloader', channel_url, '--output', "/home/download/"+channel_name+"-"+d1+'.'+file_format]) \ No newline at end of file From bc481bbe8dfe2bfbb865e68426943a0c36f507cc Mon Sep 17 00:00:00 2001 From: lauwarm <10065855+lauwarm@users.noreply.github.com> Date: Tue, 23 Jan 2024 14:47:40 +0100 Subject: [PATCH 9/9] update readme to reflect changes --- README.rst | 5 +++-- docs/README.rst | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 5e12e46..53ee938 100644 --- a/README.rst +++ b/README.rst @@ -64,7 +64,7 @@ The tool can be used with ``docker``: .. code:: console - $ docker run -v /path/to/download/:/home/download/ -e channelURL='https://www.twitch.tv/twitch' -e channelName='twitch' -e uid='1000' -e gid='1000' ghcr.io/xenova/chat-downloader:master + $ docker run -v /path/to/download/:/home/download/ -e channelURL='https://www.twitch.tv/twitch' -e channelName='twitch' -e fileFormat='json' -e uid='1000' -e gid='1000' ghcr.io/xenova/chat-downloader:master ##### @@ -130,10 +130,11 @@ Docker - **/home/download** - the place where the file will be saved. Mount it to a desired place with -v option. - **channelURL** - the url of the stream you want to record. - **channelName** - the name for the stream. +- **fileFormat** - file extension to be used. - **uid** - UserID, map to your desired User ID (fallback to 9001) - **gid** - GroupID, map to your desired Group ID (fallback to 9001) -The File will be saved as channelName-YearMonthDate-HourMinuteSecond.json +The File will be saved as channelName-YearMonthDate-HourMinuteSecond.ext ########## diff --git a/docs/README.rst b/docs/README.rst index 966c229..8591ad1 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -64,7 +64,7 @@ The tool can be used with ``docker``: .. code:: console - $ docker run -v /path/to/download/:/home/download/ -e channelURL='https://www.twitch.tv/twitch' -e channelName='twitch' -e uid='1000' -e gid='1000' ghcr.io/xenova/chat-downloader:master + $ docker run -v /path/to/download/:/home/download/ -e channelURL='https://www.twitch.tv/twitch' -e channelName='twitch' -e fileFormat='json' -e uid='1000' -e gid='1000' ghcr.io/xenova/chat-downloader:master ##### Usage @@ -115,12 +115,14 @@ Docker channelName - the name for the stream. + fileFormat - file extension to be used. + uid - UserID, map to your desired User ID (fallback to 9001) gid - GroupID, map to your desired Group ID (fallback to 9001) -The File will be saved as streamName-YearMonthDate-HourMinuteSecond.json +The File will be saved as streamName-YearMonthDate-HourMinuteSecond.ext ########## Chat Items