Skip to content

Commit

Permalink
Feat: 更新到 v3.13.0
Browse files Browse the repository at this point in the history
Feat: 资源页面显示运行时长
Feat: 支持单文件/目录的压缩分卷和加密(linux)
Feat: 可在父目录之间复制文件/目录
Feat: Github 新版本检查
Fix: 改进 Submit 逻辑: 当提交后设置校验重试, 避免报错重复上传
Fix: Android 服务设置 START_NOT_STICKY
Fix: 更新应用后不会更新前端页面的问题
  • Loading branch information
ERR0RPR0MPT committed Oct 13, 2023
1 parent 9f578c7 commit c26874d
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 121 deletions.
21 changes: 17 additions & 4 deletions biliup/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/google/go-querystring/query"
"github.com/tidwall/gjson"
"io"
"math/rand"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -418,12 +419,24 @@ func UploadFolderWithSubmit(uploadPath string, Biliup Bilibili, UUID string) (re
common.LogPrintf(UUID, common.BUlStr, "开始上传目录到哔哩源:", uploadPath)
submitFiles, uploadedFile, err := Biliup.FolderUpload(uploadPath, UUID)
if err != nil {
common.LogPrintf(UUID, common.BUlStr, "UploadFile file error:%s", err)
common.LogPrintf(UUID, common.BUlStr, "视频上传失败:%s", err)
return "", nil, err
}
reqBody, err = Biliup.Submit(submitFiles)
if err != nil {
common.LogPrintf(UUID, common.BUlStr, "Submit file error:%s", err)
// 避免同一时间提交多个稿件
isSuccess := false
for i := 0; i < BilibiliMaxRetryTimes; i++ {
reqBody, err = Biliup.Submit(submitFiles)
if err != nil {
rand.Seed(time.Now().UnixNano())
delayTime := rand.Intn(60) + 1
common.LogPrintf(UUID, common.BUlStr, "视频提交失败,准备在", delayTime, "秒后重试:%s", err)
time.Sleep(time.Duration(delayTime) * time.Second)
continue
}
isSuccess = true
break
}
if !isSuccess {
return "", nil, err
}
return reqBody, uploadedFile, nil
Expand Down
10 changes: 9 additions & 1 deletion common/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (

const (
LumikaVersionNum = 3
LumikaVersionString = "v3.12.0"
LumikaVersionString = "v3.13.0"
LumikaGithubRepo = "err0rpr0mpt/lumika"
LumikaWebGithubRepo = "err0rpr0mpt/lumika-web"
LumikaAndroidGithubRepo = "err0rpr0mpt/lumika-android"
LumikaWorkDirName = "lumika_data"
LumikaConfigFileName = "lumika_config"
InitStr = "Init:"
UpdateStr = "Update:"
WebStr = "WebServer:"
DbStr = "Database:"
EnStr = "Encode:"
Expand Down Expand Up @@ -56,6 +60,7 @@ const (
)

var (
EpDir string
EpPath string
LumikaWorkDirPath string
LumikaEncodePath string
Expand Down Expand Up @@ -192,6 +197,7 @@ type FileInfo struct {

type SystemResourceUsage struct {
OSName string `json:"osName"`
ExecuteTime string `json:"executeTime"`
CpuUsagePercent float64 `json:"cpuUsagePercent"`
MemUsageTotalAndUsed string `json:"memUsageTotalAndUsed"`
MemUsagePercent float64 `json:"memUsagePercent"`
Expand Down Expand Up @@ -336,6 +342,8 @@ type BUlTaskListData struct {
Duration string `json:"duration"`
}

var StartTimestamp int64

var DatabaseVariable Database

var VarSettingsVariable VarSettings
Expand Down
29 changes: 15 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func main() {
common.LogPrintln("", common.InitStr, "工作目录获取失败")
return
}
common.EpPath = filepath.Dir(est)
common.EpPath = est
common.EpDir = filepath.Dir(est)
UISubFiles, err := fs.Sub(UIFiles, "ui")
if err != nil {
fmt.Println("静态文件加载失败:", err)
Expand Down Expand Up @@ -69,31 +70,31 @@ func main() {
encodeKGValue := encodeFlag.Int("k", common.AddKGLevel, "The output video frame data shards(default="+strconv.Itoa(common.AddKGLevel)+"), 2-256")
encodeThread := encodeFlag.Int("t", common.VarSettingsVariable.DefaultMaxThreads, "Set Runtime Go routines number to process the task(default="+strconv.Itoa(runtime.NumCPU())+"), 1-128")
encodeFFmpegMode := encodeFlag.String("m", common.EncodeFFmpegModeLevel, "FFmpeg mode(default="+common.EncodeFFmpegModeLevel+"): ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo")
encodePath := encodeFlag.String("d", common.EpPath, "The dir path to save lumika data files")
encodePath := encodeFlag.String("d", common.EpDir, "The dir path to save lumika data files")

decodeFlag := flag.NewFlagSet("decode", flag.ExitOnError)
decodeInputDir := decodeFlag.String("i", "", "The input dir include video segments to decode")
decodeMGValue := decodeFlag.Int("m", common.AddMGLevel, "The output video frame all shards(default="+strconv.Itoa(common.AddMGLevel)+"), 2-256")
decodeKGValue := decodeFlag.Int("k", common.AddKGLevel, "The output video frame data shards(default="+strconv.Itoa(common.AddKGLevel)+"), 2-256")
decodeThread := decodeFlag.Int("t", common.VarSettingsVariable.DefaultMaxThreads, "Set Runtime Go routines number to process the task(default="+strconv.Itoa(runtime.NumCPU())+"), 1-128")
decodePath := decodeFlag.String("d", common.EpPath, "The dir path to save lumika data files")
decodePath := decodeFlag.String("d", common.EpDir, "The dir path to save lumika data files")

addFlag := flag.NewFlagSet("add", flag.ExitOnError)
addPath := addFlag.String("d", common.EpPath, "The dir path to save lumika data files")
addPath := addFlag.String("d", common.EpDir, "The dir path to save lumika data files")

getFlag := flag.NewFlagSet("get", flag.ExitOnError)
getPath := getFlag.String("d", common.EpPath, "The dir path to save lumika data files")
getPath := getFlag.String("d", common.EpDir, "The dir path to save lumika data files")

dlFlag := flag.NewFlagSet("dl", flag.ExitOnError)
dlPath := dlFlag.String("d", common.EpPath, "The dir path to save lumika data files")
dlPath := dlFlag.String("d", common.EpDir, "The dir path to save lumika data files")

webFlag := flag.NewFlagSet("web", flag.ExitOnError)
webHost := webFlag.String("h", common.DefaultWebServerHost, "The host to listen on")
webPort := webFlag.Int("p", common.DefaultWebServerPort, "The port to listen on")
webPath := webFlag.String("d", common.EpPath, "The dir path to save lumika data files")
webPath := webFlag.String("d", common.EpDir, "The dir path to save lumika data files")

if len(os.Args) < 2 {
utils.LumikaDataPathInit(common.EpPath)
utils.LumikaDataPathInit(common.EpDir)
utils.WebServer(common.DefaultWebServerHost, common.DefaultWebServerPort)
return
}
Expand All @@ -104,7 +105,7 @@ func main() {
common.LogPrintln("", common.WebStr, common.ErStr, "参数解析错误")
return
}
p := common.EpPath
p := common.EpDir
if *webPath != "" {
p = *webPath
}
Expand All @@ -125,7 +126,7 @@ func main() {
common.LogPrintln("", common.AddStr, common.ErStr, "参数解析错误")
return
}
p := common.EpPath
p := common.EpDir
if *addPath != "" {
p = *addPath
}
Expand All @@ -138,7 +139,7 @@ func main() {
common.LogPrintln("", common.GetStr, common.ErStr, "参数解析错误")
return
}
p := common.EpPath
p := common.EpDir
if *getPath != "" {
p = *getPath
}
Expand All @@ -155,7 +156,7 @@ func main() {
common.LogPrintln("", common.BDlStr, common.ErStr, "参数解析错误,请输入正确的av/BV号")
return
}
p := common.EpPath
p := common.EpDir
if *dlPath != "" {
p = *dlPath
}
Expand All @@ -172,7 +173,7 @@ func main() {
common.LogPrintln("", common.EnStr, common.ErStr, "参数解析错误")
return
}
p := common.EpPath
p := common.EpDir
if *encodePath != "" {
p = *encodePath
}
Expand All @@ -189,7 +190,7 @@ func main() {
common.LogPrintln("", common.DeStr, common.ErStr, "参数解析错误")
return
}
p := common.EpPath
p := common.EpDir
if *decodePath != "" {
p = *decodePath
}
Expand Down
13 changes: 13 additions & 0 deletions ui/assets/index-11121d1f.js

Large diffs are not rendered by default.

13 changes: 0 additions & 13 deletions ui/assets/index-5d9e8779.js

This file was deleted.

2 changes: 1 addition & 1 deletion ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="icon" href="/ui/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lumika Web</title>
<script type="module" crossorigin src="/ui/assets/index-5d9e8779.js"></script>
<script type="module" crossorigin src="/ui/assets/index-11121d1f.js"></script>
<link rel="stylesheet" href="/ui/assets/index-aef14ea1.css">
</head>

Expand Down
75 changes: 0 additions & 75 deletions utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,81 +10,6 @@ import (
"time"
)

func LumikaDataPathInit(p string) {
common.LumikaWorkDirPath = filepath.Join(p, common.LumikaWorkDirName)
common.LumikaEncodePath = filepath.Join(p, common.LumikaWorkDirName, "encode")
common.LumikaDecodePath = filepath.Join(p, common.LumikaWorkDirName, "decode")
common.LumikaEncodeOutputPath = filepath.Join(p, common.LumikaWorkDirName, "encodeOutput")
common.LumikaDecodeOutputPath = filepath.Join(p, common.LumikaWorkDirName, "decodeOutput")
// 创建 Lumika 工作目录
if _, err := os.Stat(common.LumikaWorkDirPath); err == nil {
common.LogPrintln("", common.InitStr, "Lumika 工作目录已存在,跳过创建 Lumika 工作目录")
if _, err := os.Stat(common.LumikaEncodePath); err != nil {
common.LogPrintln("", common.InitStr, "创建 encode 工作目录")
err = os.Mkdir(common.LumikaEncodePath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 encode 目录失败:", err)
return
}
}
if _, err := os.Stat(common.LumikaDecodePath); err != nil {
common.LogPrintln("", common.InitStr, "创建 decode 工作目录")
err = os.Mkdir(common.LumikaDecodePath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 decode 目录失败:", err)
return
}
}
if _, err := os.Stat(common.LumikaEncodeOutputPath); err != nil {
common.LogPrintln("", common.InitStr, "创建 encodeOutput 工作目录")
err = os.Mkdir(common.LumikaEncodeOutputPath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 encodeOutput 目录失败:", err)
return
}
}
if _, err := os.Stat(common.LumikaDecodeOutputPath); err != nil {
common.LogPrintln("", common.InitStr, "创建 decodeOutput 工作目录")
err = os.Mkdir(common.LumikaDecodeOutputPath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 decodeOutput 目录失败:", err)
return
}
}
} else {
common.LogPrintln("", common.InitStr, "Lumika 工作目录不存在,创建 Lumika 工作目录")
err = os.Mkdir(common.LumikaWorkDirPath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 Lumika 工作目录失败:", err)
return
}
common.LogPrintln("", common.InitStr, "创建 encode 工作目录")
err = os.Mkdir(common.LumikaEncodePath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 encode 目录失败:", err)
return
}
common.LogPrintln("", common.InitStr, "创建 decode 工作目录")
err = os.Mkdir(common.LumikaDecodePath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 decode 目录失败:", err)
return
}
common.LogPrintln("", common.InitStr, "创建 encodeOutput 工作目录")
err = os.Mkdir(common.LumikaEncodeOutputPath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 encodeOutput 目录失败:", err)
return
}
common.LogPrintln("", common.InitStr, "创建 decodeOutput 工作目录")
err = os.Mkdir(common.LumikaDecodeOutputPath, 0755)
if err != nil {
common.LogPrintln("", common.InitStr, "创建 decodeOutput 目录失败:", err)
return
}
}
}

func DbSave(wd string, i int) {
db := &common.Database{
DlTaskList: common.DlTaskList,
Expand Down
8 changes: 4 additions & 4 deletions utils/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func Decode(videoFileDir string, segmentLength int64, filePathList []string, MGV

var FFprobePath string
// 检查是否有 FFprobe 在程序目录下
FFprobePath = SearchFileNameInDir(common.EpPath, "ffprobe")
FFprobePath = SearchFileNameInDir(common.EpDir, "ffprobe")
if FFprobePath == "" || FFprobePath != "" && !strings.Contains(filepath.Base(FFprobePath), "ffprobe") {
common.LogPrintln(UUID, common.DeStr, "使用系统环境变量中的 FFprobe")
FFprobePath = "ffprobe"
Expand Down Expand Up @@ -225,7 +225,7 @@ func Decode(videoFileDir string, segmentLength int64, filePathList []string, MGV

var FFmpegPath string
// 检查是否有 FFmpeg 在程序目录下
FFmpegPath = SearchFileNameInDir(common.EpPath, "ffmpeg")
FFmpegPath = SearchFileNameInDir(common.EpDir, "ffmpeg")
if FFmpegPath == "" || FFmpegPath != "" && !strings.Contains(filepath.Base(FFmpegPath), "ffmpeg") {
common.LogPrintln(UUID, common.DeStr, "使用系统环境变量中的 FFmpeg")
FFmpegPath = "ffmpeg"
Expand Down Expand Up @@ -1839,7 +1839,7 @@ func DecodeWithoutPipe(videoFileDir string, segmentLength int64, filePathList []

var FFprobePath string
// 检查是否有 FFprobe 在程序目录下
FFprobePath = SearchFileNameInDir(common.EpPath, "ffprobe")
FFprobePath = SearchFileNameInDir(common.EpDir, "ffprobe")
if FFprobePath == "" || FFprobePath != "" && !strings.Contains(filepath.Base(FFprobePath), "ffprobe") {
common.LogPrintln(UUID, common.DeStr, "使用系统环境变量中的 FFprobe")
FFprobePath = "ffprobe"
Expand Down Expand Up @@ -1910,7 +1910,7 @@ func DecodeWithoutPipe(videoFileDir string, segmentLength int64, filePathList []

var FFmpegPath string
// 检查是否有 FFmpeg 在程序目录下
FFmpegPath = SearchFileNameInDir(common.EpPath, "ffmpeg")
FFmpegPath = SearchFileNameInDir(common.EpDir, "ffmpeg")
if FFmpegPath == "" || FFmpegPath != "" && !strings.Contains(filepath.Base(FFmpegPath), "ffmpeg") {
common.LogPrintln(UUID, common.DeStr, "使用系统环境变量中的 FFmpeg")
FFmpegPath = "ffmpeg"
Expand Down
18 changes: 13 additions & 5 deletions utils/dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ func Dl(url string, filePath string, referer string, origin string, userAgent st
return &common.CommonError{Msg: err.Error()}
}

req.Header.Set("Referer", referer)
req.Header.Set("Origin", origin)
if referer != "" {
req.Header.Set("Referer", referer)
}
if origin != "" {
req.Header.Set("Origin", origin)
}
req.Header.Set("User-Agent", userAgent)

var totalSize int64
Expand Down Expand Up @@ -206,9 +210,13 @@ func Dl(url string, filePath string, referer string, origin string, userAgent st

rangeHeader := fmt.Sprintf("bytes=%d-%d", thread.StartOffset, thread.EndOffset)
req2.Header.Set("Range", rangeHeader)
req2.Header.Set("Referer", referer)
req2.Header.Set("Origin", origin)
req2.Header.Set("User-Agent", userAgent)
if referer != "" {
req.Header.Set("Referer", referer)
}
if origin != "" {
req.Header.Set("Origin", origin)
}
req.Header.Set("User-Agent", userAgent)

resp2, err := client.Do(req2)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions utils/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func Encode(fileDir string, videoSize int, outputFPS int, maxSeconds int, MGValu

var FFmpegPath string
// 检查是否有 FFmpeg 在程序目录下
FFmpegPath = SearchFileNameInDir(common.EpPath, "ffmpeg")
FFmpegPath = SearchFileNameInDir(common.EpDir, "ffmpeg")
if FFmpegPath == "" || FFmpegPath != "" && !strings.Contains(filepath.Base(FFmpegPath), "ffmpeg") {
common.LogPrintln(UUID, common.EnStr, "使用系统环境变量中的 FFmpeg")
FFmpegPath = "ffmpeg"
Expand Down Expand Up @@ -1543,7 +1543,7 @@ func EncodeWithoutPipe(fileDir string, videoSize int, outputFPS int, maxSeconds
// 存储所有图片序列到目录后调用 FFmpeg
var FFmpegPath string
// 检查是否有 FFmpeg 在程序目录下
FFmpegPath = SearchFileNameInDir(common.EpPath, "ffmpeg")
FFmpegPath = SearchFileNameInDir(common.EpDir, "ffmpeg")
if FFmpegPath == "" || FFmpegPath != "" && !strings.Contains(filepath.Base(FFmpegPath), "ffmpeg") {
common.LogPrintln(UUID, common.EnStr, "使用系统环境变量中的 FFmpeg")
FFmpegPath = "ffmpeg"
Expand Down
Loading

0 comments on commit c26874d

Please sign in to comment.