diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4fcdfa6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,33 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +scripts/docker-compose-dev.yml +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +./deploy diff --git a/.github/workflows/CI-docker.yml b/.github/workflows/CI-docker.yml new file mode 100644 index 0000000..e8bd359 --- /dev/null +++ b/.github/workflows/CI-docker.yml @@ -0,0 +1,31 @@ +name: Docker Build CI + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: lychee0 + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64 + push: true + tags: lychee0/animepipeline:dev diff --git a/.github/workflows/Release-pypi.yml b/.github/workflows/Release-pypi.yml deleted file mode 100644 index 1f75436..0000000 --- a/.github/workflows/Release-pypi.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Release-pypi - -on: - workflow_dispatch: - -jobs: - Pypi: - strategy: - matrix: - python-version: ["3.9"] - poetry-version: ["1.8.3"] - - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - uses: abatilo/actions-poetry@v2 - with: - poetry-version: ${{ matrix.poetry-version }} - - - name: Build package - run: | - make build - - - name: Publish a Python distribution to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.PYPI_API }} diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml new file mode 100644 index 0000000..c8ae6c2 --- /dev/null +++ b/.github/workflows/Release.yml @@ -0,0 +1,81 @@ +name: Release + +on: + workflow_dispatch: + push: + tags: + - "v*" + +jobs: + pypi: + strategy: + matrix: + python-version: ["3.9"] + poetry-version: ["1.8.3"] + + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - uses: abatilo/actions-poetry@v2 + with: + poetry-version: ${{ matrix.poetry-version }} + + - name: Build package + run: | + make build + + - name: Publish a Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API }} + + docker: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: lychee0 + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + lychee0/animepipeline + tags: | + latest + ${{ github.ref_name }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + + github: + needs: [pypi, docker] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Release + uses: softprops/action-gh-release@v2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7cdda74 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.11.10 + +RUN apt update && apt install -y \ + curl \ + make \ + iputils-ping \ + libmediainfo-dev \ + libgl1-mesa-glx + +WORKDIR /app + +COPY . . + +ENV POETRY_HOME="/opt/poetry" +ENV PATH="$POETRY_HOME/bin:$PATH" + +RUN curl -sSL https://install.python-poetry.org | python3 - + +RUN poetry install + +CMD ["make", "run"] diff --git a/Makefile b/Makefile index b00127f..3f29c4b 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,11 @@ lint: .PHONY: build build: poetry build --format wheel + +.PHONY: run +run: + poetry run python -m animepipeline + +.PHONY: docker +docker: + docker buildx build -t lychee0/animepipeline . diff --git a/animepipeline/loop.py b/animepipeline/loop.py index ffb486d..f30d141 100644 --- a/animepipeline/loop.py +++ b/animepipeline/loop.py @@ -199,12 +199,17 @@ async def pipeline_finalrip(self, task_info: TaskInfo) -> None: await self.finalrip_client.download_completed_task(video_key=bt_downloaded_path.name, save_path=temp_saved_path) # rename temp file - gen_name = gen_file_name( - FileNameInfo( - path=temp_saved_path, episode=task_info.episode, name=task_info.name, uploader=task_info.uploader + try: + gen_name = gen_file_name( + FileNameInfo( + path=temp_saved_path, episode=task_info.episode, name=task_info.name, uploader=task_info.uploader + ) ) - ) - finalrip_downloaded_path = bt_downloaded_path.parent / gen_name + finalrip_downloaded_path = bt_downloaded_path.parent / gen_name + except Exception as e: + logger.error(f"Failed to generate file name: {e}") + raise e + if finalrip_downloaded_path.exists(): finalrip_downloaded_path.unlink() logger.warning(f"Encode File already exists, remove it: {finalrip_downloaded_path}") diff --git a/deploy/docker-compose-dev.yml b/deploy/docker-compose-dev.yml index f48f3f9..9096598 100644 --- a/deploy/docker-compose-dev.yml +++ b/deploy/docker-compose-dev.yml @@ -1,6 +1,6 @@ version: "3.8" -name: animepipeline +name: animepipeline-dev networks: backend: diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..333d067 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,49 @@ +version: "3.8" + +name: animepipeline + +networks: + backend: + driver: bridge + +services: + animepipeline: + image: lychee0/animepipeline:latest + restart: always + volumes: + - ../conf:/app/conf + - ./docker/downloads:/downloads + networks: + - backend + + qb: + image: superng6/qbittorrentee:4.4.5.10 + restart: always + environment: + - PUID=1026 + - PGID=100 + volumes: + - ./docker/qb-config:/config + - ./docker/downloads:/downloads + ports: + - "6881:6881" + - "6881:6881/udp" + - "8091:8080" + + telegram-bot-api: + image: aiogram/telegram-bot-api:latest + restart: always + environment: + TELEGRAM_API_ID: "26" + TELEGRAM_API_HASH: "4a" + TELEGRAM_LOCAL: 1 + volumes: + - telegram-bot-api-data:/var/lib/telegram-bot-api + ports: + - "8081:8081" + +# !这可不能乱动,wsl2下不这么搞会报错,真他妈的坑 +# Note: Don't use -v option to mount volumes in WSL2!!! +# Ref: https://github.com/tdlib/td/issues/1776 +volumes: + telegram-bot-api-data: diff --git a/pyproject.toml b/pyproject.toml index 64278bb..3547142 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ license = "MIT" name = "animepipeline" readme = "README.md" repository = "https://github.com/TensoRaws/AnimePipeline" -version = "0.0.1" +version = "0.0.2" # Requirements [tool.poetry.dependencies]