Skip to content

Commit

Permalink
脱离mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyiming748 committed Dec 28, 2023
1 parent 05d3805 commit cd076d1
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 64 deletions.
8 changes: 0 additions & 8 deletions GetFileInfo/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"processAll/GetAllFolder"
"processAll/mediaInfo"
"processAll/model"
"strings"
"sync"
)
Expand Down Expand Up @@ -175,12 +174,5 @@ func GetAllFiles(dir string) (names []string) {
}
names = append(names, file.Name())
}
var cs []*model.Custom
for _, name := range names {
c := new(model.Custom)
c.FileName = name
cs = append(cs, c)
}
go new(model.Custom).InsertAll(cs)
return names
}
4 changes: 3 additions & 1 deletion conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ audio = /mnt/e/audio
video = /mnt/f/large/artistress/littleSubGirl
gif = /Users/zen/Downloads/Fugtrup collection/archive/webp
txt = /Users/zen/Downloads/tele
bilibili = /sdcard/Android/data/tv.danmaku.bili/download
bilibili = /mnt/d/git/processAll/merge/downloads
louder = E:\aac
[thread]
threads = 5
Expand Down Expand Up @@ -72,3 +72,5 @@ saveTo = /mnt/c/Users/zen/Videos
concurrency = 1
links = /home/zen/git/processAll/lines.txt
proxy = 192.168.1.20:8889
[merge]
prefix = /mnt/c/Users/zen/Videos
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,28 @@ func setLog() {
func final() {
if runtime.GOOS == "darwin" {
slog.Info("M1重新生成预编译文件")
if out, err := exec.Command("zsh", "-c", "/Users/zen/git/ProcessAVI/build.sh").CombinedOutput(); err != nil {
if out, err := exec.Command("zsh", "-c", "build.sh").CombinedOutput(); err != nil {
slog.Warn("程序结束后重新编译失败")
} else {
slog.Debug("编译新版本二进制文件", slog.String("输出", string(out)))
}
}
if runtime.GOOS == "linux" {
slog.Info("linux64重新生成预编译文件")
if out, err := exec.Command("bash", "-c", "/home/zen/git/ProcessAVI/build.sh").CombinedOutput(); err != nil {
if out, err := exec.Command("bash", "-c", "build.sh").CombinedOutput(); err != nil {
slog.Warn("程序结束后重新编译失败")
} else {
slog.Debug("编译新版本二进制文件", slog.String("输出", string(out)))
}
}
if runtime.GOOS == "android" {
slog.Info("android重新生成预编译文件")
if out, err := exec.Command("bash", "-c", "build.sh").CombinedOutput(); err != nil {
slog.Warn("程序结束后重新编译失败")
} else {
slog.Debug("编译新版本二进制文件", slog.String("输出", string(out)))
}
}

}

/*
Expand Down
46 changes: 46 additions & 0 deletions merge/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"media_type": 2,
"has_dash_audio": true,
"is_completed": true,
"total_bytes": 47675288,
"downloaded_bytes": 47675288,
"title": "蜡笔小新【人物志】特殊的一期:春日部防卫队——最强战队",
"type_tag": "80",
"cover": "http:\/\/i0.hdslb.com\/bfs\/archive\/55b5d45ee6857820890e536e8823ead726bc0cbb.jpg",
"video_quality": 80,
"prefered_video_quality": 80,
"guessed_total_bytes": 0,
"total_time_milli": 1058550,
"danmaku_count": 387,
"time_update_stamp": 1702664375269,
"time_create_stamp": 1702664199018,
"can_play_in_advance": true,
"interrupt_transform_temp_file": false,
"quality_pithy_description": "1080P",
"quality_superscript": "",
"cache_version_code": 7590200,
"preferred_audio_quality": 0,
"audio_quality": 0,
"avid": 229337132,
"spid": 0,
"seasion_id": 0,
"bvid": "",
"owner_id": 630727239,
"owner_name": "茂人小头头",
"page_data": {
"cid": 1148286376,
"page": 1,
"from": "vupload",
"part": "盘点《蜡笔小新》最强组织的发展史!永远的春日部防卫队!永远的友谊!",
"link": "",
"rich_vid": "",
"vid": "",
"has_alias": false,
"tid": 253,
"width": 1920,
"height": 1080,
"rotate": 0,
"download_title": "",
"download_subtitle": ""
}
}
50 changes: 26 additions & 24 deletions merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"processAll/GetFileInfo"
"processAll/mediaInfo"
"processAll/replace"
"processAll/sql"
"processAll/util"
"regexp"
"runtime"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -84,11 +85,14 @@ func Merge(rootPath string) {
video := strings.Join([]string{third, "video.m4s"}, string(os.PathSeparator))
audio := strings.Join([]string{third, "audio.m4s"}, string(os.PathSeparator))
fname := strings.Join([]string{name, "mp4"}, ".")
if isExist("/sdcard/Movies") {
os.Mkdir("/sdcard/Movies/bili", 0777)
fname = strings.Join([]string{"/sdcard/Movies/bili", fname}, string(os.PathSeparator))
prefix := util.GetVal("merge", "prefix")
if isExist(prefix) {
aim := strings.Join([]string{prefix, "bili"}, string(os.PathSeparator))
os.Mkdir(aim, 0777)
fname = strings.Join([]string{aim, fname}, string(os.PathSeparator))
} else {
fname = strings.Join([]string{"/sdcard/Movies/bili", fname}, string(os.PathSeparator))
slog.Warn("目标文件夹不存在,退出")
os.Exit(-1)
}
if isFileExist(fname) {
perfix := strings.Replace(fname, ".mp4", "", 1)
Expand All @@ -113,12 +117,12 @@ func Merge(rootPath string) {
slog.Warn("哔哩哔哩合成出错", slog.Any("错误原文", err), slog.Any("命令原文", fmt.Sprint(cmd)))
continue
}
if err = os.RemoveAll(sec); err != nil {
slog.Debug("删除失败", slog.String("目录名", sec), slog.Any("错误原文", err))
return
} else {
slog.Debug("删除成功", slog.String("目录名", sec))
}
//if err = os.RemoveAll(sec); err != nil {
// slog.Debug("删除失败", slog.String("目录名", sec), slog.Any("错误原文", err))
// return
//} else {
// slog.Debug("删除成功", slog.String("目录名", sec))
//}
}
}
}
Expand Down Expand Up @@ -154,6 +158,17 @@ func getName(jackson string) (name string) {
return
}
err = json.Unmarshal(file, &entry)

record := new(sql.Bili)
record.Title = entry.Title
record.Cover = strings.Replace(entry.Cover, "\\/", "//", -1)
record.CreatedAt = sql.S2T(strconv.FormatInt(entry.TimeCreateStamp, 10))
record.UpdatedAt = sql.S2T(strconv.FormatInt(entry.TimeUpdateStamp, 10))
record.Owner = entry.OwnerName
record.PartName = entry.PageData.Part
record.Original = string(file)
record.SetOne()

if err != nil {
return
}
Expand All @@ -163,16 +178,6 @@ func getName(jackson string) (name string) {
return name
}

func Effective(s string) bool {
num := regexp.MustCompile(`\d`) // 匹配任意一个数字
letter := regexp.MustCompile(`[a-zA-Z]`) // 匹配任意一个字母
char := regexp.MustCompile(`[\p{Han}]`) // 匹配任意一个汉字
if num.MatchString(s) || letter.MatchString(s) || char.MatchString(s) {
return true
}
return false
}

/*
判断路径是否存在
*/
Expand Down Expand Up @@ -206,9 +211,6 @@ func isFileExist(fp string) bool {
func CutName(before string) (after string) {
for i, char := range before {
slog.Debug(fmt.Sprintf("第%d个字符:%v", i+1, string(char)))
if !Effective(string(char)) {
continue
}
if i >= 124 {
slog.Debug("截取124之前的完整字符")
break
Expand Down
20 changes: 1 addition & 19 deletions processVideo/h265.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"processAll/GetAllFolder"
"processAll/GetFileInfo"
"processAll/mediaInfo"
"processAll/model"
"processAll/replace"
"processAll/util"
"runtime"
Expand Down Expand Up @@ -102,16 +101,7 @@ func ProcessVideo2H265(in GetFileInfo.BasicInfo, threads string) {
if s_size, d_size, diff, err := util.GetDiffFileSize(in.FullPath, mp4); err != nil {
slog.Warn("文件优化大小计算出错")
} else {
save := new(model.Save)
save.SrcName = in.FullPath
save.DstName = mp4
save.SrcSize = s_size
save.DstSize = d_size
save.Size = diff
_, err := save.InsertOne()
if err != nil {
fmt.Println("节省的空间 记录插入失败")
}
fmt.Println(s_size, d_size, diff)
}
if err == nil {
if err = os.RemoveAll(in.FullPath); err != nil {
Expand All @@ -120,14 +110,6 @@ func ProcessVideo2H265(in GetFileInfo.BasicInfo, threads string) {
slog.Debug("删除成功", slog.Any("源文件", in.FullName))
}
}
s := new(model.Save)
all, err := s.SumSaveAll()
if err != nil {
return
} else {
//fmt.Printf("节省的空间:%v GB\n", all)
slog.Info("转码总共节省的空间", slog.String("GB", all))
}
slog.Debug("本次转码完成")
}
func addTag(in GetFileInfo.BasicInfo) {
Expand Down
36 changes: 36 additions & 0 deletions sql/bili.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package sql

import (
"fmt"
"gorm.io/gorm"
"strconv"
"time"
)

type Bili struct {
gorm.Model
ID uint `gorm:"primaryKey"`
Cover string `gorm:"cover,type=string"`
Title string `gorm:"title"`
Owner string `gorm:"owner"`
PartName string `gorm:"part_name"`
Original string `gorm:"original"`
CreatedAt time.Time `gorm:"created_at"`
UpdatedAt time.Time `gorm:"updated_at"`
}

var layout = "2006-01-02 15:04:05.000000000 +0800"

func S2T(timestampStr string) time.Time {
timestampStr = "1702664199073"
timestampInt, _ := strconv.ParseInt(timestampStr, 10, 64)
t := time.Unix(timestampInt/1000, 0)
formattedTime := t.Format("2006-01-02 15:04:05.000000000 +0800")
fmt.Println(formattedTime)
return t
}

func (b *Bili) SetOne() *gorm.DB {

return GetEngine().Create(&b)
}
1 change: 1 addition & 0 deletions sql/lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func SetEngine() {
})
// 迁移 schema
err := db.AutoMigrate(Ytdlp{})
err = db.AutoMigrate(Bili{})
if err != nil {
return
}
Expand Down
9 changes: 0 additions & 9 deletions telegraph/fromFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log/slog"
"os"
"os/exec"
"processAll/model"
"processAll/soup"
"processAll/util"
"strconv"
Expand Down Expand Up @@ -119,14 +118,6 @@ func DownloadSrc(title string, images []string) {
//slog.Debug("下载命令结束", slog.String("命令返回", string(output)))
success++
}

one := model.Telegraph{
Name: fname,
Url: image,
Shell: fmt.Sprint(cmd),
}
go one.InsertOne()

}
slog.Info("全部下载完毕", slog.Int("共有文件", total), slog.Int("成功下载", success))
}

0 comments on commit cd076d1

Please sign in to comment.