mirror of
https://github.com/ihmily/DouyinLiveRecorder.git
synced 2025-12-26 05:48:32 +08:00
Fix tiktok record and add live status message push
This commit is contained in:
parent
1c0dfadcf1
commit
3acec62833
16
README.md
16
README.md
@ -2,7 +2,7 @@
|
||||
|
||||
## 💡简介
|
||||
|
||||
一款可循环值守的直播录制工具,基于FFmpeg实现多平台直播源录制,支持自定义配置录制参数
|
||||
一款可循环值守的直播录制工具,基于FFmpeg实现多平台直播源录制,支持自定义配置录制以及直播状态推送
|
||||
|
||||
</div>
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
├── main.py -> (main file)
|
||||
├── spider.py-> (get live url)
|
||||
├── web_rid.py -> (get web_rid)
|
||||
├── msg_push.py -> (send live status update message)
|
||||
├── cookies.py -> (get douyin cookies)
|
||||
├── x-bogus.js -> (get douyin xbogus token)
|
||||
├── ffmpeg.exe -> (record video)
|
||||
@ -45,12 +46,13 @@
|
||||
- 在config文件夹内的配置文件中对录制进行配置以及添加录制直播间地址
|
||||
- 抖音录制需要使用到PC网页端直播间页面的Cookie,请先在config.ini配置文件中添加后再进行抖音录制
|
||||
- 注意事项① 录制使用到了ffmpeg,如果没有则无法进行录制,请将ffmpeg.exe放置运行文件同个文件夹
|
||||
- 注意事项② 录制Tiktok时需要使用vpn代理,请先在配置文件中设置开启代理并添加proxy_addr
|
||||
- 注意事项③ 如果电脑开启了`全局或者规则代理`,可不用添加proxy_addr参数值但仍需在config.ini配置文件中设置开启代理
|
||||
- 注意事项② 录制Tiktok时需要使用vpn代理,请先在配置文件中设置开启代理并添加proxy_addr链接
|
||||
- 注意事项③ 如果电脑开启了`全局或者规则代理`,可不用添加proxy_addr参数值但仍需在config.ini配置文件中设置开启代理 (最好还是设置一下代理地址,降低出错概率)
|
||||
- 注意事项④ 可以在URL_config.ini中的链接开头加上#,此时将不会录制该条链接对应的直播
|
||||
- 注意事项⑤ 测试时有可能会出现在IDE如Pycharm中运行代码进行直播录制,录制出来的视频却无法正常播放的现象,如果遇到这个问题 最好在命令控制台DOS界面运行代码,录制出来的视频即可正常播放。
|
||||
- 可使用 `pyinstaller -F或-D` 将代码打包成exe可执行文件 ,前提是已经安装了`pyinstaller`库
|
||||
- 可使用 `pyinstaller -D或-F` 将代码打包成exe可执行文件 ,前提是已经安装了`pyinstaller`库
|
||||
- 当同时在录制多个直播时,最好线程数设置大一些,否则可能出现其中一个直播录制出错。当然设置的过大也没用,要同时考虑自身电脑的配置,如CPU内核数、网络带宽等限制。
|
||||
- 如果想直接使用打包好的录制软件,进入[Releases](https://github.com/ihmily/DouyinLiveRecorder/releases) 下载最新发布的 zip压缩包即可,可能有些电脑会报毒,直接忽略即可,这是pyinstaller打包的锅。
|
||||
|
||||
 
|
||||
|
||||
@ -115,9 +117,13 @@ GET https://hmily.vip/api/jx/live/convert.php?url=https://v.douyin.com/iQLgKSj/
|
||||
|
||||
## ⏳提交日志
|
||||
|
||||
- 20230903
|
||||
- 修复了Tiktok录制时报644无法录制的问题
|
||||
- 新增直播状态推送到钉钉和微信的功能,如有需要请看 [设置推送教程](https://d04vqdiqwr3.feishu.cn/docx/XFPwdDDvfobbzlxhmMYcvouynDh?from=from_copylink)
|
||||
- 最近比较忙,其他问题有时间再更新
|
||||
|
||||
- 20230816
|
||||
- 修复斗鱼直播(官方更新了字段)和快手直播录制出错的问题
|
||||
|
||||
- 20230814
|
||||
- 新增B站直播录制
|
||||
- 写了一个在线播放M3U8和FLV视频的网页源码,打开即可食用
|
||||
|
||||
33
main.py
33
main.py
@ -4,7 +4,7 @@
|
||||
Author: Hmily
|
||||
Github: https://github.com/ihmily
|
||||
Date: 2023-07-17 23:52:05
|
||||
Update: 2023-08-16 14:54:17
|
||||
Update: 2023-09-03 19:18:36
|
||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||
Function: Record live stream video.
|
||||
"""
|
||||
@ -21,9 +21,10 @@ import datetime
|
||||
import shutil
|
||||
from spider import *
|
||||
from web_rid import *
|
||||
from msg_push import *
|
||||
|
||||
# 版本号
|
||||
version = "v1.0.5"
|
||||
version = "v1.0.6"
|
||||
platforms = "抖音|Tiktok|快手|虎牙|斗鱼|YY|B站"
|
||||
|
||||
# --------------------------log日志-------------------------------------
|
||||
@ -507,9 +508,10 @@ def start_record(line, count_variable=-1):
|
||||
|
||||
elif record_url.find("https://www.tiktok.com/") > -1:
|
||||
with semaphore:
|
||||
if use_proxy or (global_proxy and proxy_addr != ''):
|
||||
json_data = get_tiktok_stream_data(record_url, proxy_addr)
|
||||
port_info = get_tiktok_stream_url(json_data)
|
||||
if use_proxy:
|
||||
if global_proxy or proxy_addr != '':
|
||||
json_data = get_tiktok_stream_data(record_url, proxy_addr)
|
||||
port_info = get_tiktok_stream_url(json_data)
|
||||
|
||||
elif record_url.find("https://live.kuaishou.com/") > -1:
|
||||
with semaphore:
|
||||
@ -561,7 +563,15 @@ def start_record(line, count_variable=-1):
|
||||
if port_info[1] is False:
|
||||
print(f"{record_name} 等待直播... ")
|
||||
else:
|
||||
print(f"{record_name} 正在直播中...")
|
||||
content = f"{record_name} 正在直播中..."
|
||||
print(content)
|
||||
# 推送通知
|
||||
if live_status_push != '':
|
||||
if '微信' in live_status_push:
|
||||
xizhi(xizhi_api_url,content)
|
||||
if '钉钉' in live_status_push:
|
||||
dingtalk(dingtalk_api_url, content, dingtalk_phone_num)
|
||||
|
||||
|
||||
# 是否显示直播地址
|
||||
if video_m3u8:
|
||||
@ -1013,7 +1023,7 @@ Monitoring = 0
|
||||
try:
|
||||
# 检测电脑是否开启了全局/规则代理
|
||||
print('系统代理检测中...')
|
||||
response_g = urllib.request.urlopen("https://www.tiktok.com/", timeout=5)
|
||||
response_g = urllib.request.urlopen("https://www.tiktok.com/", timeout=10)
|
||||
global_proxy = True
|
||||
print('系统代理已开启√ 注意:配置文件中的代理设置也要开启才会生效哦!')
|
||||
|
||||
@ -1059,7 +1069,7 @@ while True:
|
||||
video_save_path = read_config_value(config, '1', '直播保存路径(不填则默认)', "")
|
||||
video_save_type = read_config_value(config, '1', '视频保存格式TS|MKV|FLV|MP4|TS音频|MKV音频', "MP4")
|
||||
video_quality = read_config_value(config, '1', '原画|超清|高清|标清', "原画")
|
||||
use_proxy = read_config_value(config, '1', '是否使用代理ip(是/否)', "否")
|
||||
use_proxy = read_config_value(config, '1', '是否使用代理ip(是/否)', "是")
|
||||
proxy_addr = read_config_value(config, '1', '代理地址', "")
|
||||
max_request = int(read_config_value(config, '1', '同一时间访问网络的线程数', 3))
|
||||
semaphore = threading.Semaphore(max_request)
|
||||
@ -1073,7 +1083,11 @@ while True:
|
||||
tsconvert_to_m4a = read_config_value(config, '1', 'TS录制完成后自动增加生成m4a格式', "否")
|
||||
delFilebeforeconversion = read_config_value(config, '1', '追加格式后删除原文件', "否")
|
||||
create_time_file = read_config_value(config, '1', '生成时间文件', "否")
|
||||
cookies_set = read_config_value(config, '1', 'cookies(不可为空)', '')
|
||||
live_status_push = read_config_value(config, '1', '直播状态通知(可选微信|钉钉或者两个都填)', "")
|
||||
dingtalk_api_url = read_config_value(config, '1', '钉钉推送接口链接', "")
|
||||
xizhi_api_url = read_config_value(config, '1', '微信推送接口链接', "")
|
||||
dingtalk_phone_num = read_config_value(config, '1', '钉钉通知@对象(填手机号)', "")
|
||||
cookies_set = read_config_value(config, '1', 'cookie(录制抖音必须要有)', '')
|
||||
|
||||
if len(video_save_type) > 0:
|
||||
if video_save_type.upper().lower() == "FLV".lower():
|
||||
@ -1196,4 +1210,3 @@ while True:
|
||||
# 总体循环3s
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
|
||||
64
msg_push.py
Normal file
64
msg_push.py
Normal file
@ -0,0 +1,64 @@
|
||||
"""
|
||||
Author: Hmily
|
||||
Github:https://github.com/ihmily
|
||||
Date: 2023-09-03 19:18:36
|
||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||
"""
|
||||
|
||||
import json
|
||||
import urllib.request
|
||||
|
||||
no_proxy_handler = urllib.request.ProxyHandler({})
|
||||
opener = urllib.request.build_opener(no_proxy_handler)
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
|
||||
def dingtalk(url, content, phone_number=''):
|
||||
json_data = {
|
||||
'msgtype': 'text',
|
||||
'text': {
|
||||
'content': '直播间状态更新:\n' + content,
|
||||
},
|
||||
"at": {
|
||||
"atMobiles": [
|
||||
phone_number # 添加这个手机号,可以被@通知(必须要在群里)
|
||||
],
|
||||
# "atUserIds": [
|
||||
# "user123"
|
||||
# ],
|
||||
# "isAtAll": False
|
||||
},
|
||||
}
|
||||
data = json.dumps(json_data).encode('utf-8')
|
||||
req = urllib.request.Request(url, data=data, headers=headers)
|
||||
response = opener.open(req, timeout=10)
|
||||
html_str = response.read().decode('utf-8')
|
||||
# print(html_str)
|
||||
return html_str
|
||||
|
||||
|
||||
def xizhi(url, content):
|
||||
json_data = {
|
||||
'title': '直播间状态更新',
|
||||
'content': content
|
||||
}
|
||||
data = json.dumps(json_data).encode('utf-8')
|
||||
req = urllib.request.Request(url, data=data, headers=headers)
|
||||
response = opener.open(req, timeout=10)
|
||||
html_str = response.read().decode('utf-8')
|
||||
# print(html_str)
|
||||
return html_str
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
content = '张三 开播了!' # 推送内容
|
||||
phone_number = '' # 被@用户的手机号码
|
||||
# 替换成自己Webhook链接,参考文档:https://open.dingtalk.com/document/robots/custom-robot-access
|
||||
webhook_api = ''
|
||||
# dingtalk(webhook_api,content,phone_number)
|
||||
|
||||
# 替换成自己的单点推送接口,获取地址:https://xz.qqoq.net/#/admin/one
|
||||
xizhi_api = ''
|
||||
# xizhi(xizhi_api,content)
|
||||
@ -4,7 +4,7 @@
|
||||
Author: Hmily
|
||||
Github:https://github.com/ihmily
|
||||
Date: 2023-07-15 23:15:00
|
||||
Update: 2023-08-16 14:07:30
|
||||
Update: 2023-09-03 19:18:36
|
||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||
Function: Get live stream data.
|
||||
"""
|
||||
@ -62,7 +62,7 @@ def get_tiktok_stream_data(url, proxy_addr):
|
||||
|
||||
else:
|
||||
req = urllib.request.Request(url, headers=headers)
|
||||
response = opener.open(req, timeout=15)
|
||||
response = urllib.request.urlopen(req, timeout=15)
|
||||
html_str = response.read().decode('utf-8')
|
||||
|
||||
json_str = re.findall(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user