Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,19 @@ login_file/
node_modules/
package.json
pnpm-lock.yaml
package-lock.json
package-lock.json

# Ignore the biliup folder
upload/config/*
!upload/config/1234567.yaml
!upload/config/upload_config.json
!upload/uploadVideoQueue.txt

# Ignore the production
startRecord-production.sh
settings-production.toml
path.txt
sameSegments.txt

# Ignore the cookies.json
cookies.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
pip install -r requirements.txt

# 记录项目根目录
./setRoutineTask.sh
./setRoutineTask.sh && source ~/.bashrc
```
### 4.2 biliup-rs 登录

Expand Down
34 changes: 0 additions & 34 deletions monitor.sh

This file was deleted.

9 changes: 6 additions & 3 deletions setRoutineTask.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

rootPath=$(pwd)
rm ./path.txt
echo "rootPath $rootPath" >> ./path.txt
# Query the project path
CURRENT_PATH=$(pwd)
# Export the project path to the .bashrc file for the current user using the bash shell
echo "export BILIVE_PATH=$CURRENT_PATH # This for timerring/bilive project path" >> ~/.bashrc
# Make the changes to the .bashrc file immediately effective
echo " Have set the project path $CURRENT_PATH to .bashrc for the current user."
38 changes: 9 additions & 29 deletions settings.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
version = "1.0"
[[tasks]]
webhooks = []

[[tasks]]
room_id = 22230707
enable_monitor = true
enable_recorder = true

[[webhooks]]
live_began = true
live_ended = true
room_change = true
recording_started = true
recording_finished = true
recording_cancelled = true
video_file_created = true
video_file_completed = true
danmaku_file_created = false
danmaku_file_completed = false
raw_danmaku_file_created = false
raw_danmaku_file_completed = false
cover_image_downloaded = true
video_postprocessing_completed = true
postprocessing_completed = true
space_no_enough = true
error_occurred = true
url = "http://localhost:22333"

[output]
path_template = "{roomid}/{roomid}_{year}{month}{day}-{hour}-{minute}-{second}"
filesize_limit = 0
duration_limit = 28800
duration_limit = 0
out_dir = "./Videos"

[logging]
log_dir = "./logs"
log_dir = "./logs/blrecLog"
console_log_level = "INFO"
backup_count = 30

Expand All @@ -57,12 +37,12 @@ save_raw_danmaku = true
[recorder]
stream_format = "flv"
recording_mode = "standard"
quality_number = 150
quality_number = 250
fmp4_stream_timeout = 10
read_timeout = 3
disconnection_timeout = 300
buffer_size = 8192
save_cover = true
disconnection_timeout = 600
buffer_size = 32768
save_cover = false
cover_save_strategy = "dedup"

[postprocessing]
Expand All @@ -71,9 +51,9 @@ inject_extra_metadata = true
delete_source = "auto"

[space]
check_interval = 600
check_interval = 0
space_threshold = 10737418240
recycle_records = true
recycle_records = false

[email_notification]
began_message_type = "html"
Expand Down
Binary file removed src/__pycache__/Live.cpython-310.pyc
Binary file not shown.
Binary file removed src/__pycache__/Myproc.cpython-310.pyc
Binary file not shown.
Binary file removed src/__pycache__/api.cpython-310.pyc
Binary file not shown.
Binary file removed src/__pycache__/httpserver.cpython-310.pyc
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed src/blive_upload/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 9 additions & 15 deletions burnAndMerge.sh → src/burnAndMerge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
# INPUT: sameSegments.txt
# OUTPUT: uploadVideoQueue.txt

# Import the $rootPath
while read key value; do
export $key="$value"
done < ./path.txt

firstOutputFile=""
while read -r line; do
# Skip when read blanket line
Expand All @@ -27,10 +22,10 @@ while read -r line; do
xmlFile=${line%.mp4}.xml
assFile=${line%.mp4}.ass
if [ -f "$xmlFile" ]; then
$rootPath/DanmakuFactory -o "$assFile" -i "$xmlFile" --msgboxfontsize 23 --ignore-warnings
$BILIVE_PATH/utils/DanmakuFactory -o "$assFile" -i "$xmlFile" --msgboxfontsize 23 --ignore-warnings
echo "==================== generated $assFile ===================="
export ASS_PATH="$assFile"
python3 $rootPath/removeEmojis.py >> $rootPath/logs/removeEmojis.log 2>&1
python3 $BILIVE_PATH/utils/removeEmojis.py >> $BILIVE_PATH/logs/removeEmojis.log 2>&1
fi

# Initial some basic parameters and create tmp folder
Expand All @@ -48,30 +43,29 @@ while read -r line; do
echo "file '$newPath'" >> mergevideo.txt
if [ -f "$assFile" ]; then
# The Nvidia GPU accelerating version.
ffmpeg -hwaccel cuda -c:v h264_cuvid -i "$line" -c:v h264_nvenc -vf "ass=$assFile" "$newPath" -y -nostdin > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
ffmpeg -hwaccel cuda -c:v h264_cuvid -i "$line" -c:v h264_nvenc -vf "ass=$assFile" "$newPath" -y -nostdin > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# The only cpu version.
# ffmpeg -i "$line" -vf "ass=$assFile" -preset ultrafast "$newPath" -y -nostdin > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# ffmpeg -i "$line" -vf "ass=$assFile" -preset ultrafast "$newPath" -y -nostdin > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
else
# The Nvidia GPU accelerating version.
ffmpeg -hwaccel cuda -c:v h264_cuvid -i "$line" -c:v h264_nvenc "$newPath" -y -nostdin > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
ffmpeg -hwaccel cuda -c:v h264_cuvid -i "$line" -c:v h264_nvenc "$newPath" -y -nostdin > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# The only cpu version.
# ffmpeg -i "$line" -vf -preset ultrafast "$newPath" -y -nostdin > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# ffmpeg -i "$line" -vf -preset ultrafast "$newPath" -y -nostdin > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
fi

# Delete the related items of videos
rm ${line%.mp4}.*
done < sameSegments.txt
done < ./src/sameSegments.txt

# merge the videos
echo "==================== merge starts ===================="
# echo "ffmpeg -f concat -i mergevideo.txt -c copy $firstOutputFile"
ffmpeg -f concat -safe 0 -i mergevideo.txt -use_wallclock_as_timestamps 1 -c copy $firstOutputFile > $rootPath/logs/mergeLog/merge-$(date +%Y%m%d%H%M%S).log 2>&1
ffmpeg -f concat -safe 0 -i mergevideo.txt -use_wallclock_as_timestamps 1 -c copy $firstOutputFile > $BILIVE_PATH/logs/mergeLog/merge-$(date +%Y%m%d%H%M%S).log 2>&1

# delete useless videos and lists
rm -r $tmpDir
rm mergevideo.txt

echo "==================== start upload $firstOutputFile ===================="
# echo "nohup /root/blive/uploadVideo.sh $firstOutputFile > /root/blive/logs/uploadDanmakuLog/$(date +%Y%m%d%H%M%S).log 2>&1 &"
echo "$firstOutputFile" >> $rootPath/uploadVideoQueue.txt
echo "$firstOutputFile" >> $BILIVE_PATH/upload/uploadVideoQueue.txt
echo "==================== OVER ===================="
18 changes: 7 additions & 11 deletions danmakuBurning.sh → src/danmakuBurning.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
# OUTPUT:
# $formatVideoName - eg:/path/to/video/roomid_YYYY-MM-DD-HH.mp4

while read key value; do
export $key="$value"
done < ./path.txt

# check if the filename is provided.
if [ $# -ne 1 ]; then
echo "Usage: $0 filename"
Expand Down Expand Up @@ -51,25 +47,25 @@ assPath="${path}/${roomid}_${year}-${month}-${day}-${hour}.ass"
# use DanmakuFactory to convert the xml file
xmlPath="${filenameWithoutExt}.xml"
if [ -f "$xmlPath" ]; then
$rootPath/DanmakuFactory -o "$assPath" -i "$xmlPath" --msgboxfontsize 23 --ignore-warnings
$BILIVE_PATH/utils/DanmakuFactory -o "$assPath" -i "$xmlPath" --msgboxfontsize 23 --ignore-warnings
rm $xmlPath
echo “danmaku convert success!”
export ASS_PATH="$assPath"
python3 $rootPath/removeEmojis.py >> $rootPath/logs/removeEmojis.log 2>&1
python3 $BILIVE_PATH/utils/removeEmojis.py >> $BILIVE_PATH/logs/removeEmojis.log 2>&1
fi

# Burn danmaku into video.
if [ -f "$assPath" ]; then
# The only cpu version
# ffmpeg -y -i $fullPath -vf ass=$assPath -preset ultrafast $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# ffmpeg -y -i $fullPath -vf ass=$assPath -preset ultrafast $formatVideoName > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# The Nvidia GPU accelerating version
ffmpeg -y -hwaccel cuda -c:v h264_cuvid -i $fullPath -c:v h264_nvenc -vf ass=$assPath $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
ffmpeg -y -hwaccel cuda -c:v h264_cuvid -i $fullPath -c:v h264_nvenc -vf ass=$assPath $formatVideoName > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
rm $assPath
else
# The only cpu version
# ffmpeg -y -i $fullPath -vf -preset ultrafast $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# ffmpeg -y -i $fullPath -vf -preset ultrafast $formatVideoName > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# The Nvidia GPU acceleting version
ffmpeg -y -hwaccel cuda -c:v h264_cuvid -i $fullPath -c:v h264_nvenc $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
ffmpeg -y -hwaccel cuda -c:v h264_cuvid -i $fullPath -c:v h264_nvenc $formatVideoName > $BILIVE_PATH/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
fi

echo "ffmpeg successfully complete!"
Expand All @@ -78,4 +74,4 @@ echo "ffmpeg successfully complete!"
rm $fullPath

# Upload video.
echo "$formatVideoName" >> $rootPath/uploadVideoQueue.txt
echo "$formatVideoName" >> $BILIVE_PATH/upload/uploadVideoQueue.txt
2 changes: 1 addition & 1 deletion src/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def config(cls, video_list_path,upload_log_dir, upload_config_path):
# class method, for loading the upload list from the config file
@classmethod
def set_upload_list(cls):
with open("upload_config.json", 'r', encoding='utf-8') as f:
with open("../upload/config/upload_config.json", 'r', encoding='utf-8') as f:
# load the JSON config
config = json.load(f)
# assign the list of room_ids from the config file to the upload list
Expand Down
4 changes: 2 additions & 2 deletions main.py → src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

if __name__ == "__main__":
# open and read the TOML configuration file
with open('settings.toml', 'r', encoding='utf-8') as f:
with open('../settings.toml', 'r', encoding='utf-8') as f:
settings = toml.load(f)
# get the video list file path
video_list_path = os.path.join(settings['output']['out_dir'], "_list")
Expand All @@ -25,7 +25,7 @@
os.makedirs(upload_log_dir, exist_ok = True)

# configure the paths and configuration file for MyHandler
MyHandler.config(video_list_path, upload_log_dir, "upload_config.json")
MyHandler.config(video_list_path, upload_log_dir, "../upload/config/upload_config.json")
# set the server listening address and port
server_address = ('', PORT)
# create the HTTP server instance, using MyHandler as the request processor
Expand Down
16 changes: 6 additions & 10 deletions scanSegments.sh → src/scanSegments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
# INPUT: none.
# OUTPUT: $otherMp4File >> sameSegments.txt

while read key value; do
export $key="$value"
done < ./path.txt

CheckAndProcessFolder() {
local folderPath=$1

Expand All @@ -30,7 +26,7 @@ CheckAndProcessFolder() {

# This length to prevent processing the burned videos again!
if [ ${#detectName} -gt 27 ]; then
echo $mp4File > sameSegments.txt
echo $mp4File > ./src/sameSegments.txt

# Find the same date and hour video
datePart=$(basename "$mp4File" | cut -d '_' -f 2| cut -d '-' -f 1)
Expand All @@ -40,23 +36,23 @@ CheckAndProcessFolder() {
# if [[ $(basename "$otherMp4File" | cut -d '_' -f 2| cut -d '-' -f 1) == $datePart && $(basename "$otherMp4File" | cut -d '-' -f 2) == $hourPart ]]; then
if [[ $(basename "$otherMp4File" | cut -d '_' -f 2| cut -d '-' -f 1) == $datePart ]]; then
if [[ "$mp4File" != "$otherMp4File" ]]; then
echo "$otherMp4File" >> sameSegments.txt
echo "$otherMp4File" >> ./src/sameSegments.txt
fi
fi
done
lineCount=$(wc -l < "sameSegments.txt")
lineCount=$(wc -l < "./src/sameSegments.txt")
echo "$lineCount"
if [ $lineCount -gt 1 ]; then
$rootPath/burningAndMerge.sh sameSegments.txt
$BILIVE_PATH/src/burnAndMerge.sh ./src/sameSegments.txt
else
$rootPath/danmakuBurning.sh $mp4File
$BILIVE_PATH/src/danmakuBurning.sh $mp4File
fi
fi
fi
done
}

roomFolderPath="$rootPath/Videos"
roomFolderPath="$BILIVE_PATH/Videos"
while true; do
for roomFolder in "$roomFolderPath"/*; do
if [ -d "$roomFolder" ]; then
Expand Down
2 changes: 1 addition & 1 deletion upload.py → src/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from src.blive_upload import configured_upload

UPLOAD_CONFIGURATION = "upload_config.json"
UPLOAD_CONFIGURATION = "../upload/config/upload_config.json"

if __name__ == '__main__':
os.environ['TZ'] = 'Asia/Shanghai'
Expand Down
6 changes: 1 addition & 5 deletions startRecord.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# pause#!/bin/bash
while read key value; do
export $key="$value"
done < ./path.txt

export config=./settings.toml

# Do not use proxy
Expand All @@ -13,5 +9,5 @@ host=0.0.0.0
port=2233

kill -9 $(pgrep -f blrec)
nohup blrec -c $config --open --host $host --port $port > $rootPath/logs/blrec.log 2>&1 &
nohup blrec -c $config --open --host $host --port $port > $BILIVE_PATH/logs/blrec.log 2>&1 &
echo "blrec run success!"
5 changes: 1 addition & 4 deletions startScan.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
while read key value; do
export $key="$value"
done < ./path.txt
# kill the previous scanSegments process
kill -9 $(pgrep -f scanSegments)
# start the scanSegments process
nohup $rootPath/scanSegments.sh > $rootPath/logs/scanSegments.log 2>&1 &
nohup $BILIVE_PATH/src/scanSegments.sh > $BILIVE_PATH/logs/scanSegments.log 2>&1 &
# Check if the last command was successful
if [ $? -eq 0 ]; then
echo "success"
Expand Down
5 changes: 1 addition & 4 deletions startUpload.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
while read key value; do
export $key="$value"
done < ./path.txt
# kill the previous scanSegments process
kill -9 $(pgrep -f uploadQueue)
# start the scanSegments process
nohup $rootPath/uploadQueue.sh > $rootPath/logs/uploadQueue.log 2>&1 &
nohup $BILIVE_PATH/upload/uploadQueue.sh > $BILIVE_PATH/logs/uploadQueue.log 2>&1 &
# Check if the last command was successful
if [ $? -eq 0 ]; then
echo "success"
Expand Down
Loading