Compare commits

...

3 Commits

Author SHA1 Message Date
cb4d0e518d gitignore 2024-05-08 13:50:23 +08:00
2edd98353f 上传 2024-05-07 17:23:37 +08:00
8183fdbd7b gitignore 2024-05-07 17:21:57 +08:00
17 changed files with 84 additions and 42 deletions

BIN
.DS_Store vendored

Binary file not shown.

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.DS_Store

View File

@ -5,4 +5,4 @@ Website = "https://iteay.top"
Name = "HLS-builder"
ID = "top.iteay.hls-builder"
Version = "1.0.0"
Build = 24
Build = 32

BIN
bin/.DS_Store vendored

Binary file not shown.

BIN
fyne-cross/.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>HLS-builder</string>
<key>CFBundleExecutable</key>
<string>hls-builder</string>
<key>CFBundleIdentifier</key>
<string>top.iteay.hls-builder</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>30</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
</dict>
</plist>

Binary file not shown.

Binary file not shown.

6
go.mod
View File

@ -3,12 +3,12 @@ module hls-builder
go 1.22.0
require (
fyne.io/fyne v1.4.3
fyne.io/fyne/v2 v2.4.5
github.com/google/uuid v1.1.2
)
require (
fyne.io/fyne v1.4.3
fyne.io/systray v1.10.1-0.20231115130155-104f5ef7839e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.0.0 // indirect
@ -16,13 +16,14 @@ require (
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240306074159-ea2d69986ecb // indirect
github.com/go-text/render v0.1.0 // indirect
github.com/go-text/typesetting v0.1.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
@ -34,6 +35,7 @@ require (
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)

4
go.sum
View File

@ -89,8 +89,9 @@ github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2/go.mod h1:eO7W361vml
github.com/fyne-io/mobile v0.1.2/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA=
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@ -109,7 +110,6 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff h1:W71vTCKoxtdXgnm1ECDFkfQnpdqAO00zzGXLA5yaEX8=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=

78
main.go
View File

@ -1,7 +1,7 @@
/*
* @Author: BlackTeay
* @Date: 2024-04-30 09:37:39
* @LastEditTime: 2024-05-07 13:53:30
* @LastEditTime: 2024-05-08 13:44:32
* @LastEditors: BlackTeay
* @Description:
* @FilePath: /hls_builder/main.go
@ -15,9 +15,11 @@ import (
_ "embed"
"errors"
"fmt"
"image/color"
"log"
"math"
"net/url"
"os"
"os/exec"
"path/filepath"
@ -30,6 +32,7 @@ import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
@ -42,9 +45,6 @@ var ttfBytes []byte
//go:embed bin/*
var ffmpegFS embed.FS
//go:embed config/userconfig.yaml
var configFS embed.FS
// MyTheme 定义了一个自定义的主题结构体。
type MyTheme struct{}
@ -114,9 +114,12 @@ func getFFmpegPath() (string, func(), error) {
tmpFilePath := filepath.Join(tmpDir, ffmpegFileName)
if err := os.WriteFile(tmpFilePath, data, 0755); err != nil {
log.Fatal(err)
} else {
log.Println("FFmpeg path:", tmpFilePath)
}
cleanup := func() {
os.RemoveAll(tmpDir) // 删除整个临时目录
log.Println("Cleaned up FFmpeg temporary files.")
}
return tmpFilePath, cleanup, nil
@ -150,34 +153,13 @@ func getUs3cliPath() (string, func(), error) {
tmpFilePath := filepath.Join(tmpDir, us3cliFileName)
if err := os.WriteFile(tmpFilePath, data, 0755); err != nil {
log.Fatal(err)
} else {
log.Println("us3cli path:", tmpFilePath)
}
cleanup := func() {
os.RemoveAll(tmpDir) // 删除整个临时目录
log.Println("Cleaned up Us3cli temporary files.")
}
return tmpFilePath, cleanup, nil
}
func getUs3Config() (string, func(), error) {
// 读取嵌入的配置文件
data, err := configFS.ReadFile("config/userconfig.yaml")
if err != nil {
log.Fatal(err)
}
// 创建临时目录并将us3cli文件内容写入其中
tmpDir, err := os.MkdirTemp("", "config")
if err != nil {
log.Fatal(err)
}
tmpFilePath := filepath.Join(tmpDir, "userconfig.yaml")
if err := os.WriteFile(tmpFilePath, data, 0755); err != nil {
log.Fatal(err)
}
cleanup := func() {
os.RemoveAll(tmpDir) // 删除整个临时目录
}
return tmpFilePath, cleanup, nil
}
@ -192,7 +174,7 @@ func main() {
// 创建主窗口并设置大小
myWindow := myApp.NewWindow("HLS-builder 视频切片上传工具")
myWindow.Resize(fyne.NewSize(800, 600))
myWindow.Resize(fyne.NewSize(800, 400))
// 初始化UI组件文件选择提示、输出路径选择提示、进度条
inputFile := widget.NewLabel("请选择mp4文件!")
@ -278,6 +260,13 @@ func main() {
})
btnUpload.Disable()
copyRight := widget.NewLabelWithStyle("© 2024 JLNTV ", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
blogLink := widget.NewHyperlink("BlackTeay", createURL("https://iteay.top"))
copyRightHyperlink := container.NewHBox(copyRight, blogLink)
// 创建一个水平和垂直居中的布局
centeredLayout := container.NewBorder(nil, nil, nil, nil, copyRightHyperlink)
// 组合UI元素
content := container.NewVBox(
inputFile,
@ -291,8 +280,11 @@ func main() {
uploadProgressBar,
)
// 将内容放置在水平和垂直居中的布局中
centeredContent := container.New(layout.NewVBoxLayout(), content, centeredLayout)
// 设置窗口内容并显示
myWindow.SetContent(content)
myWindow.SetContent(centeredContent)
myWindow.ShowAndRun()
}
@ -314,7 +306,6 @@ func sliceVideo(inputFile, outputDir string, progressBar *widget.ProgressBar, on
if err != nil {
log.Fatal(err)
}
defer cleanup() // 确保在函数返回时删除临时目录
startTime := time.Now() // 记录开始时间以便计算总耗时
log.Println("开始切割视频")
@ -369,6 +360,7 @@ func sliceVideo(inputFile, outputDir string, progressBar *widget.ProgressBar, on
dialog.ShowInformation("完成", fmt.Sprintf("✅ 视频切片完成!可以将切片直接上传云存储。\n总用时: %s\n存储位置%s", formattedDuration, outputDir), myWindow)
log.Println("视频切片完成")
btnUpload.Enable()
cleanup() // 确保在函数返回时删除临时目录
break
}
}
@ -519,6 +511,7 @@ func formatDuration(d time.Duration) string {
// 上传到Ucloud
func upload(localPath string, keyPath string, progressBar *widget.ProgressBar, myWindow fyne.Window, onComplete func()) {
fmt.Println("上传到Ucloud")
progressBar.SetValue(0)
fmt.Println("localPath:", localPath)
fmt.Println("keyPath:", keyPath)
// 统计 .ts .m3u8 文件数量
@ -530,18 +523,20 @@ func upload(localPath string, keyPath string, progressBar *widget.ProgressBar, m
fmt.Printf("Total .m3u8 files: %d\n", m3u8Files)
filesTotal := float64(tsFiles + m3u8Files)
fmt.Printf("Total files: %d\n", int(filesTotal))
// 获取 us3cli 的路径
us3cliPath, cleanup, err := getUs3cliPath()
if err != nil {
log.Fatal(err)
}
defer cleanup() // 确保在函数返回时删除临时目录
bucket := "us3://jlntv-live/replay/" + keyPath
us3ConfigPath, cleanup, err := getUs3Config()
if err != nil {
log.Fatal(err)
}
defer cleanup() // 确保在函数返回时删除临时目录
cmd := exec.Command(us3cliPath, "cp", localPath, bucket, "-r", "--parallel", "20", "--config", us3ConfigPath)
// us3ConfigPath, cleanup, err := getUs3Config()
// if err != nil {
// log.Fatal(err)
// }
// defer cleanup() // 确保在函数返回时删除临时目录
// cmd := exec.Command(us3cliPath, "cp", localPath, bucket, "-r", "--parallel", "20", "--config", us3ConfigPath)
cmd := exec.Command(us3cliPath, "cp", localPath, bucket, "-r", "--parallel", "20", "--accesskey", "TOKEN_6096c736-12b7-4c20-bfa5-e85e0e9c9b65", "--secretkey", "cc8a5965-3325-4231-9f64-a6626f624049", "--endpoint", "cn-bj.ufileos.com")
//输出cmd
fmt.Println(cmd.String())
@ -725,3 +720,12 @@ func countMediaFiles(directory string) (int, int, error) {
// 返回 .ts 和 .m3u8 文件的计数结果,以及遍历过程中可能遇到的错误
return tsCount, m3u8Count, err
}
// 创建 URL 函数
func createURL(link string) *url.URL {
url, err := url.Parse(link)
if err != nil {
log.Fatalf("Error parsing URL: %v", err)
}
return url
}