Add docker configuration file

This commit is contained in:
ihmily 2024-01-02 07:10:19 +08:00
parent 61d37ed7d3
commit 3ea1f7481a
5 changed files with 89 additions and 19 deletions

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM python:3.11-slim
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
RUN apt-get update && \
apt-get install -y ffmpeg
CMD ["python", "main.py"]

View File

@ -2,6 +2,8 @@
## 💡简介 ## 💡简介
[![Python Version](https://img.shields.io/badge/python-3.11.6-blue.svg)](https://www.python.org/downloads/release/python-3116/) [![Python Version](https://img.shields.io/badge/python-3.11.6-blue.svg)](https://www.python.org/downloads/release/python-3116/)
[![Supported Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20Linux-blue.svg)](https://github.com/ihmily/DouyinLiveRecorder)
[![Docker Support](https://img.shields.io/static/v1?label=Docker&message=Supported&color=blue&logo=docker)](https://hub.docker.com/r/ihmily/douyinliverecorder)
![GitHub issues](https://img.shields.io/github/issues/ihmily/DouyinLiveRecorder.svg) ![GitHub issues](https://img.shields.io/github/issues/ihmily/DouyinLiveRecorder.svg)
![Downloads](https://img.shields.io/github/downloads/ihmily/DouyinLiveRecorder/total) ![Downloads](https://img.shields.io/github/downloads/ihmily/DouyinLiveRecorder/total)
@ -104,7 +106,7 @@ AfreecaTV
https://play.afreecatv.com/sw7love/249471484 https://play.afreecatv.com/sw7love/249471484
``` ```
直播间分享地址和网页端长地址都能正常进行录制(抖音尽量用长链接,避免因短链接转换失效导致不能正常录制)。 直播间分享地址和网页端长地址都能正常进行录制(抖音尽量用长链接,避免因短链接转换失效导致不能正常录制需要有nodejs环境否则无法转换)。
</div> </div>
@ -130,7 +132,45 @@ GET https://hmily.vip/api/jx/live/convert.php?url=https://v.douyin.com/iQLgKSj/
在线播放m3u8和flv视频网站[M3U8 在线视频播放器 ](https://jx.hmily.vip/play/) 在线播放m3u8和flv视频网站[M3U8 在线视频播放器 ](https://jx.hmily.vip/play/)
&emsp;
## 🐋容器运行
首先确保已经安装了docker以及docker-compose然后进入到项目文件夹依次执行下面命令
1.构建镜像
```
docker build -t douyin-live-recorder:2.0.7 .
```
或者直接使用
```
docker-compose build
```
2.运行容器实例
运行之前确保URL配置文件中有直播间地址
```
docker-compose -f docker-compose.yaml up
```
可选 `-d` 在后台运行。第一次运行之后都可用 `docker-compose start` 启动已创建的容器。
3.停止容器实例
```
docker-compose stop
```
4.注意事项
①在docker容器内运行请先在配置文件中添加要录制的直播间地址。②在容器内时如果手动中断容器运行停止录制会导致正在录制的视频文件损坏所以一般不建议这么做。
如果想避免手动中断或者异常中断导致文件损坏的情况,请使用 `ts` 格式录制 (其他系统同理)。
&emsp; &emsp;
@ -142,15 +182,19 @@ GET https://hmily.vip/api/jx/live/convert.php?url=https://v.douyin.com/iQLgKSj/
## ⏳提交日志 ## ⏳提交日志
- 20240102
- 修复Linux上运行新增docker配置文件
- 20231210 - 20231210
- 修复录制分段bug修复bigo录制检测bug - 修复录制分段bug修复bigo录制检测bug
- 新增自定义修改录制主播名 - 新增自定义修改录制主播名
- 新增AfreecaTV直播录制修复某些可能会发生的bug - 新增AfreecaTV直播录制修复某些可能会发生的bug
- 20231207 - 20231207
- 新增blued直播录制修复YY直播录制新增直播结束消息推送 - 新增blued直播录制修复YY直播录制新增直播结束消息推送

View File

@ -9,7 +9,7 @@
排队读取网址时间(秒) = 0 排队读取网址时间(秒) = 0
是否显示循环秒数 = 是否显示循环秒数 =
分段录制是否开启 = 分段录制是否开启 =
视频分段时间(秒) = 3600 视频分段时间(秒) = 1800
生成时间文件 = 生成时间文件 =
TS录制完成后自动转为mp4格式 = TS录制完成后自动转为mp4格式 =
TS录制完成后自动增加生成m4a格式 = TS录制完成后自动增加生成m4a格式 =

13
docker-compose.yaml Normal file
View File

@ -0,0 +1,13 @@
version: '3.8'
services:
app:
image: douyin-live-recorder
environment:
- TERM=xterm-256color
tty: true
stdin_open: true
build: .
volumes:
- .:/app
restart: always

25
main.py
View File

@ -4,8 +4,8 @@
Author: Hmily Author: Hmily
GitHub: https://github.com/ihmily GitHub: https://github.com/ihmily
Date: 2023-07-17 23:52:05 Date: 2023-07-17 23:52:05
Update: 2023-12-10 22:03:56 Update: 2024-01-02 05:57:10
Copyright (c) 2023 by Hmily, All Rights Reserved. Copyright (c) 2023-2024 by Hmily, All Rights Reserved.
Function: Record live stream video. Function: Record live stream video.
""" """
@ -23,6 +23,7 @@ import time
import json import json
import re import re
import shutil import shutil
import signal
from spider import ( from spider import (
get_douyin_stream_data, get_douyin_stream_data,
get_tiktok_stream_data, get_tiktok_stream_data,
@ -79,6 +80,12 @@ default_path = os.getcwd()
# --------------------------用到的函数------------------------------------- # --------------------------用到的函数-------------------------------------
def signal_handler(signal, frame):
sys.exit(0)
signal.signal(signal.SIGTERM, signal_handler)
def display_info(): def display_info():
# TODO: 显示当前录制配置信息 # TODO: 显示当前录制配置信息
@ -839,7 +846,6 @@ def start_record(url_tuple, count_variable=-1):
ffmpeg_command.extend(command) ffmpeg_command.extend(command)
_output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT) _output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# logging.warning(str(e.output)) # logging.warning(str(e.output))
print(f"{e.output} 发生错误的行数: {e.__traceback__.tb_lineno}") print(f"{e.output} 发生错误的行数: {e.__traceback__.tb_lineno}")
@ -863,7 +869,7 @@ def start_record(url_tuple, count_variable=-1):
_output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT) _output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT)
if tsconvert_to_m4a: if tsconvert_to_m4a:
threading.Thread(target=converts_m4a, args=(file,)).start() threading.Thread(target=converts_m4a, args=(save_file_path,)).start()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# logging.warning(str(e.output)) # logging.warning(str(e.output))
print(f"{e.output} 发生错误的行数: {e.__traceback__.tb_lineno}") print(f"{e.output} 发生错误的行数: {e.__traceback__.tb_lineno}")
@ -887,7 +893,7 @@ def start_record(url_tuple, count_variable=-1):
_output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT) _output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT)
if tsconvert_to_m4a: if tsconvert_to_m4a:
threading.Thread(target=converts_m4a, args=(file,)).start() threading.Thread(target=converts_m4a, args=(save_file_path,)).start()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# logging.warning(str(e.output)) # logging.warning(str(e.output))
print(f"{e.output} 发生错误的行数: {e.__traceback__.tb_lineno}") print(f"{e.output} 发生错误的行数: {e.__traceback__.tb_lineno}")
@ -926,11 +932,6 @@ def start_record(url_tuple, count_variable=-1):
_output = subprocess.check_output(ffmpeg_command, _output = subprocess.check_output(ffmpeg_command,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
if tsconvert_to_mp4:
threading.Thread(target=converts_mp4, args=(file,)).start()
if tsconvert_to_m4a:
threading.Thread(target=converts_m4a, args=(file,)).start()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
logging.warning(str(e.output)) logging.warning(str(e.output))
logger.warning( logger.warning(
@ -964,9 +965,9 @@ def start_record(url_tuple, count_variable=-1):
_output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT) _output = subprocess.check_output(ffmpeg_command, stderr=subprocess.STDOUT)
if tsconvert_to_mp4: if tsconvert_to_mp4:
threading.Thread(target=converts_mp4, args=(file,)).start() threading.Thread(target=converts_mp4, args=(save_file_path,)).start()
if tsconvert_to_m4a: if tsconvert_to_m4a:
threading.Thread(target=converts_m4a, args=(file,)).start() threading.Thread(target=converts_m4a, args=(save_file_path,)).start()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
# logging.warning(str(e.output)) # logging.warning(str(e.output))