feat: Add Docker support for simplified project setup - Added Dockerfile for building the application image - Added docker-compose.yml for multi-container orchestration - Updated README with instructions for running the project using Docker - Verified compatibility with existing project dependencies This change enables users to easily set up and run the project in a Docker environment, reducing local setup complexity.

This commit is contained in:
ihmily
2025-04-11 20:21:35 +08:00
parent 1527c9d217
commit b923803e7c
7 changed files with 227 additions and 14 deletions

28
.dockerignore Normal file
View File

@@ -0,0 +1,28 @@
# Version Control
**/.git
# Development Configuration
**/.env*
**/docker-compose*.yml
**/Dockerfile*
# Documentation and Tests
**/docs
**/tests
**/*.md
# Build Artifacts and Cache
**/__pycache__
**/*.pyc
**/*.log
**/node_modules
**/venv
# IDE Files
**/.vscode
**/.idea
# Static Assets (Adjust as needed)
**/.iconset/
**/*.icns
assets/images

View File

@@ -6,4 +6,7 @@ PLATFORM=desktop
HOST=127.0.0.1 HOST=127.0.0.1
# PORT: Web server port number (default: 6006) # PORT: Web server port number (default: 6006)
PORT=6006 PORT=6006
# Set timezone
TZ=Asia/Shanghai

42
Dockerfile Normal file
View File

@@ -0,0 +1,42 @@
FROM python:3.12-slim AS builder
WORKDIR /app
# Install system dependencies for build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements-web.txt .
RUN pip install --no-cache-dir -r requirements-web.txt
COPY . .
RUN mkdir -p /app/logs /app/downloads
# Final stage: production image
FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
tzdata \
curl \
gnupg \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y --no-install-recommends nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set timezone
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo "$TZ" > /etc/timezone
# Copy Python dependencies and project files from the builder stage
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /app/ ./
CMD ["sh", "-c", "python main.py --web --host 0.0.0.0"]

View File

@@ -4,9 +4,11 @@
<p align="center"> <p align="center">
<img alt="Python version" src="https://img.shields.io/badge/python-3.10%2B-blue.svg"> <img alt="Python version" src="https://img.shields.io/badge/python-3.10%2B-blue.svg">
<a href="https://github.com/ihmily/StreamCap"> <a href="https://github.com/ihmily/StreamCap">
<img alt="Supported Platforms" src="https://img.shields.io/badge/platforms-Windows%20%7C%20macOS-orange.svg"></a> <img alt="Supported Platforms" src="https://img.shields.io/badge/Platforms-Win%20%7C%20Mac%20%7C%20Linux-6B5BFF.svg"></a>
<a href="https://hub.docker.com/r/ihmily/streamcap/tags">
<img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/ihmily/streamcap?label=Docker%20Pulls&color=2496ED&logo=docker"></a>
<a href="https://github.com/ihmily/StreamCap/releases/latest"> <a href="https://github.com/ihmily/StreamCap/releases/latest">
<img alt="Latest Release" src="https://img.shields.io/github/v/release/ihmily/StreamCap?color=green"></a> <img alt="Latest Release" src="https://img.shields.io/github/v/release/ihmily/StreamCap"></a>
<a href="https://github.com/ihmily/StreamCap/releases/latest"> <a href="https://github.com/ihmily/StreamCap/releases/latest">
<img alt="Downloads" src="https://img.shields.io/github/downloads/ihmily/StreamCap/total"></a> <img alt="Downloads" src="https://img.shields.io/github/downloads/ihmily/StreamCap/total"></a>
</p> </p>
@@ -16,10 +18,12 @@
StreamCap 是一个基于FFmpeg和StreamGet的多平台直播流录制客户端覆盖 40+ 国内外主流直播平台,支持批量录制、循环监控、定时监控和自动转码等功能。 StreamCap 是一个基于FFmpeg和StreamGet的多平台直播流录制客户端覆盖 40+ 国内外主流直播平台,支持批量录制、循环监控、定时监控和自动转码等功能。
## ✨功能特性 ## ✨功能特性
- **多端支持**支持Windows/MacOS/Web运行
- **循环监控**:实时监控直播间状态,开播即录。 - **循环监控**:实时监控直播间状态,开播即录。
- **定时任务**:根据设定时间范围检查直播间状态。 - **定时任务**:根据设定时间范围检查直播间状态。
- **多种输出格式**:支持 ts、flv、mkv、mov、mp4、mp3、m4a 等格式。 - **多种输出格式**:支持 ts、flv、mkv、mov、mp4、mp3、m4a 等格式。
@@ -53,20 +57,73 @@ cd StreamCap
2.**安装依赖** 2.**安装依赖**
```bash ```bash
# 桌面端
pip install -r requirements.txt pip install -r requirements.txt
# 或者
poetry install # Web端
pip install -r requirements-web.txt
``` ```
3.**运行程序** 3.**配置运行环境**
使用以下命令启动程序:
将.env.example示例配置文件复制一份并将文件重命名为.env
```bash
cp .env.example .env
```
4.**运行程序**
在Windows和macOS上默认以桌面程序的方式运行使用以下命令启动程序
```bash ```bash
python main.py python main.py
``` ```
修改 `.env` 文件,将 `PLATFORM` 的值改为 `web`即可以Web方式运行。
或者,无需修改配置文件,直接使用以下命令启动
```bash
# Linux请使用web方式运行
python main.py --web
```
启动成功后,通过 `http://ip:6006` 访问。
如果程序提示缺少 FFmpeg请访问 FFmpeg 官方下载页面[Download FFmpeg](https://ffmpeg.org/download.html),下载预编译的 FFmpeg 可执行文件,并配置环境变量。 如果程序提示缺少 FFmpeg请访问 FFmpeg 官方下载页面[Download FFmpeg](https://ffmpeg.org/download.html),下载预编译的 FFmpeg 可执行文件,并配置环境变量。
## 🐋容器运行
本机无需Python环境运行在运行命令之前请确保您的机器上安装了 [Docker](https://docs.docker.com/get-docker/) 和 [Docker Compose](https://docs.docker.com/compose/install/)
1.**快速启动**
最简单方法是运行项目中的 [docker-compose.yml](https://github.com/ihmily/StreamCap/blob/main/docker-compose.yml) 文件,进入项目根目录后,只需简单执行以下命令(确保已经存在`.env`文件)
```bash
docker compose up
```
可选 `-d` 在后台运行。注意容器内时区问题,默认使用的是 `Asia/Shanghai` ,如需修改可以在.env文件配置。
2.**停止容器实例**
```bash
docker compose stop
```
3.**构建镜像**
Docker镜像仓库中代码版本可能不是最新的如要运行本仓库主分支最新代码可以本地自定义构建通过修改 [docker-compose.yml](https://github.com/ihmily/StreamCap/blob/main/docker-compose.yml) 文件
```bash
docker build -t streamcap .
```
构建完成后请先将docker-compose.yml文件中的镜像名称修改为 `streamcap` 后再使用`docker compose` 运行。
## 😺已支持平台 ## 😺已支持平台
**国内平台30+** **国内平台30+**

View File

@@ -4,9 +4,11 @@
<p align="center"> <p align="center">
<img alt="Python version" src="https://img.shields.io/badge/python-3.10%2B-blue.svg"> <img alt="Python version" src="https://img.shields.io/badge/python-3.10%2B-blue.svg">
<a href="https://github.com/ihmily/StreamCap"> <a href="https://github.com/ihmily/StreamCap">
<img alt="Supported Platforms" src="https://img.shields.io/badge/platforms-Windows%20%7C%20macOS-orange.svg"></a> <img alt="Supported Platforms" src="https://img.shields.io/badge/Platforms-Win%20%7C%20Mac%20%7C%20Linux-6B5BFF.svg"></a>
<a href="https://hub.docker.com/r/ihmily/streamcap/tags">
<img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/ihmily/streamcap?label=Docker%20Pulls&color=2496ED&logo=docker"></a>
<a href="https://github.com/ihmily/StreamCap/releases/latest"> <a href="https://github.com/ihmily/StreamCap/releases/latest">
<img alt="Latest Release" src="https://img.shields.io/github/v/release/ihmily/StreamCap?color=green"></a> <img alt="Latest Release" src="https://img.shields.io/github/v/release/ihmily/StreamCap"></a>
<a href="https://github.com/ihmily/StreamCap/releases/latest"> <a href="https://github.com/ihmily/StreamCap/releases/latest">
<img alt="Downloads" src="https://img.shields.io/github/downloads/ihmily/StreamCap/total"></a> <img alt="Downloads" src="https://img.shields.io/github/downloads/ihmily/StreamCap/total"></a>
</p> </p>
@@ -15,10 +17,12 @@
</div><br> </div><br>
StreamCap is a multi-platform live stream recording client based on FFmpeg and StreamGet. It covers over 40 mainstream live streaming platforms both domestically and internationally, and supports features such as batch recording, loop monitoring, timed monitoring, and automatic transcoding. StreamCap is a multi-platform live stream recording client based on FFmpeg and StreamGet. It covers over 40 mainstream live streaming platforms both domestically and internationally, and supports features such as batch recording, loop monitoring, timed monitoring, and automatic transcoding.
## ✨Features ## ✨Features
- **Multi-Platform Support**: Compatible with Windows, macOS, and Web environments.
- **Loop Monitoring**: Real-time monitoring of live stream status. Recording starts immediately when a stream goes live. - **Loop Monitoring**: Real-time monitoring of live stream status. Recording starts immediately when a stream goes live.
- **Scheduled Tasks**: Checks live stream status within a set time range. - **Scheduled Tasks**: Checks live stream status within a set time range.
- **Multiple Output Formats**: Supports ts, flv, mkv, mov, mp4, mp3, m4a, and other formats. - **Multiple Output Formats**: Supports ts, flv, mkv, mov, mp4, mp3, m4a, and other formats.
@@ -52,21 +56,73 @@ cd StreamCap
2.**Install Dependencies**: 2.**Install Dependencies**:
```bash ```bash
# For desktop
pip install -r requirements.txt pip install -r requirements.txt
# or
poetry install # For web
pip install -r requirements-web.txt
``` ```
3.**Run the Program**: 3.**Configure the Runtime Environment**
Use the following command to start the program: Copy the `.env.example` sample configuration file and rename it to `.env`
```bash
cp .env.example .env
```
4.**Run the Program**:
On Windows and macOS, the program runs as a desktop application by default. Use the following command to start the program:
```bash ```bash
python main.py python main.py
``` ```
To run the program in web mode, modify the `.env` file and change the value of PLATFORM to web.
Alternatively, you can run the program in web mode without modifying the configuration file by using the following command:
```bash
# On Linux, please run in web mode
python main.py --web
```
After successful startup, access it via `http://ip:6006`.
If the program prompts that FFmpeg is missing, please visit the FFmpeg official download page [Download FFmpeg](https://ffmpeg.org/download.html) to download the precompiled FFmpeg executable files and configure the environment variables. If the program prompts that FFmpeg is missing, please visit the FFmpeg official download page [Download FFmpeg](https://ffmpeg.org/download.html) to download the precompiled FFmpeg executable files and configure the environment variables.
## 🐋Docker Running
No Python environment is required on your local machine. Before running the commands, ensure that you have installed [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/).
1.**Quick Start**
The simplest method is to run the [docker-compose.yml](https://github.com/ihmily/StreamCap/blob/main/docker-compose.yml) file in the project. Navigate to the project root directory and execute the following command (ensure the `.env` file exists):
```bash
docker compose up
```
You can use the `-d` flag to run in the background. Note that the default timezone in the container is `Asia/Shanghai`. If you need to change it, you can configure it in the `.env` file.
2.**Stop Container Instances**:
```bash
docker compose stop
```
3.**Build the Image**:
If the code in the Docker image repository is not the latest, you can build the image locally from the main branch of this repository by modifying the [docker-compose.yml](https://github.com/ihmily/StreamCap/blob/main/docker-compose.yml) file.
```
docker build -t streamcap .
```
After the build is complete, please modify the image name in the `docker-compose.yml` file to `streamcap` before running it with `docker compose`.
## 😺 Supported Platforms ## 😺 Supported Platforms
**Domestic Platforms (30+)**: **Domestic Platforms (30+)**:

25
docker-compose.yml Normal file
View File

@@ -0,0 +1,25 @@
services:
streamcap:
image: ihmily/streamcap
tty: true
ports:
- "${PORT:-6006}:${PORT:-6006}"
environment:
- PORT=${PORT:-6006}
- TZ=${TZ:-Asia/Shanghai}
volumes:
- ./logs:/app/logs
- ./config:/app/config
- ./downloads:/app/downloads
healthcheck:
test: ["CMD", "sh", "-c", "curl -f http://localhost:${PORT:-6006}/about"]
interval: 30s
timeout: 10s
retries: 3
networks:
- streamcap-network
networks:
streamcap-network:
driver: bridge

View File

@@ -87,7 +87,7 @@ def main(page: ft.Page) -> None:
page.title = "StreamCap" page.title = "StreamCap"
page.theme_mode = ft.ThemeMode.LIGHT page.theme_mode = ft.ThemeMode.LIGHT
is_web = platform == "web" is_web = args.web or platform == "web"
setup_window(page, is_web) setup_window(page, is_web)
app = App(page) app = App(page)
@@ -119,6 +119,7 @@ if __name__ == "__main__":
multiprocessing.freeze_support() multiprocessing.freeze_support()
if args.web or platform == "web": if args.web or platform == "web":
logger.debug("Running in web mode on http://" + args.host + ":" + str(args.port))
ft.app( ft.app(
target=main, target=main,
view=ft.AppView.WEB_BROWSER, view=ft.AppView.WEB_BROWSER,
@@ -127,5 +128,6 @@ if __name__ == "__main__":
assets_dir=ASSETS_DIR, assets_dir=ASSETS_DIR,
use_color_emoji=True, use_color_emoji=True,
) )
else: else:
ft.app(target=main, assets_dir=ASSETS_DIR) ft.app(target=main, assets_dir=ASSETS_DIR)