增加注释
This commit is contained in:
parent
774993c8c7
commit
fcdc4d10b5
49
main.go
49
main.go
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: BlackTeay
|
* @Author: BlackTeay
|
||||||
* @Date: 2024-04-30 09:37:39
|
* @Date: 2024-04-30 09:37:39
|
||||||
* @LastEditTime: 2024-05-08 13:44:32
|
* @LastEditTime: 2024-05-08 14:43:47
|
||||||
* @LastEditors: BlackTeay
|
* @LastEditors: BlackTeay
|
||||||
* @Description:
|
* @Description:
|
||||||
* @FilePath: /hls_builder/main.go
|
* @FilePath: /hls_builder/main.go
|
||||||
@ -622,29 +622,50 @@ func upload(localPath string, keyPath string, progressBar *widget.ProgressBar, m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extractTotalValue 函数从给定的文本中提取总值。
|
||||||
|
//
|
||||||
|
// 参数:
|
||||||
|
//
|
||||||
|
// text string - 包含待搜索总值的文本。
|
||||||
|
//
|
||||||
|
// 返回值:
|
||||||
|
//
|
||||||
|
// float64 - 从文本中提取到的总值,如果未找到则返回默认值200。
|
||||||
|
// error - 如果在提取过程中发生错误,则返回相应的错误;否则返回nil。
|
||||||
func extractTotalValue(text string) (float64, error) {
|
func extractTotalValue(text string) (float64, error) {
|
||||||
|
// 使用正则表达式匹配文本中的总值部分
|
||||||
re := regexp.MustCompile(`Total:(\d+)`)
|
re := regexp.MustCompile(`Total:(\d+)`)
|
||||||
matches := re.FindStringSubmatch(text)
|
matches := re.FindStringSubmatch(text)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
|
// 将匹配到的总值字符串转换为整数
|
||||||
total, err := strconv.Atoi(matches[1])
|
total, err := strconv.Atoi(matches[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err // 在转换过程中发生错误
|
// 如果转换过程中发生错误,返回错误信息
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
|
// 返回转换后的总值
|
||||||
return float64(total), nil
|
return float64(total), nil
|
||||||
}
|
}
|
||||||
|
// 如果未在文本中找到总值,返回默认值200和一个错误信息
|
||||||
return 200, fmt.Errorf("no total found in the text")
|
return 200, fmt.Errorf("no total found in the text")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseUploadStats 函数解析上传统计信息字符串,并返回一个包含上传统计详情的结构体指针。
|
||||||
|
// 参数 line 为待解析的上传统计信息字符串。
|
||||||
|
// 返回 *UploadStats 指向解析出的上传统计详情结构体。
|
||||||
|
// 返回 error 表示在解析过程中遇到的任何错误。
|
||||||
func parseUploadStats(line string) (*UploadStats, error) {
|
func parseUploadStats(line string) (*UploadStats, error) {
|
||||||
stats := &UploadStats{}
|
stats := &UploadStats{}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// 初始化正则表达式用于匹配不同的上传统计信息。
|
||||||
successedRegex := regexp.MustCompile(`(\d+) Successed`)
|
successedRegex := regexp.MustCompile(`(\d+) Successed`)
|
||||||
failedRegex := regexp.MustCompile(`(\d+) Failed`)
|
failedRegex := regexp.MustCompile(`(\d+) Failed`)
|
||||||
sizeRegex := regexp.MustCompile(`Size: ([\d.]+ MB)`)
|
sizeRegex := regexp.MustCompile(`Size: ([\d.]+ MB)`)
|
||||||
speedRegex := regexp.MustCompile(`Average speed ([\d.]+ MB/s)`)
|
speedRegex := regexp.MustCompile(`Average speed ([\d.]+ MB/s)`)
|
||||||
elapsedRegex := regexp.MustCompile(`Elapsed\s*:\s*([\d.]+)s`)
|
elapsedRegex := regexp.MustCompile(`Elapsed\s*:\s*([\d.]+)s`)
|
||||||
|
|
||||||
// Extracting number of files successed
|
// 提取成功上传的文件数量。
|
||||||
successedMatches := successedRegex.FindStringSubmatch(line)
|
successedMatches := successedRegex.FindStringSubmatch(line)
|
||||||
if len(successedMatches) > 1 {
|
if len(successedMatches) > 1 {
|
||||||
stats.Successed, err = strconv.Atoi(successedMatches[1])
|
stats.Successed, err = strconv.Atoi(successedMatches[1])
|
||||||
@ -653,7 +674,7 @@ func parseUploadStats(line string) (*UploadStats, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracting number of files failed
|
// 提取失败上传的文件数量。
|
||||||
failedMatches := failedRegex.FindStringSubmatch(line)
|
failedMatches := failedRegex.FindStringSubmatch(line)
|
||||||
if len(failedMatches) > 1 {
|
if len(failedMatches) > 1 {
|
||||||
stats.Failed, err = strconv.Atoi(failedMatches[1])
|
stats.Failed, err = strconv.Atoi(failedMatches[1])
|
||||||
@ -662,19 +683,19 @@ func parseUploadStats(line string) (*UploadStats, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracting total size
|
// 提取上传的总大小。
|
||||||
sizeMatches := sizeRegex.FindStringSubmatch(line)
|
sizeMatches := sizeRegex.FindStringSubmatch(line)
|
||||||
if len(sizeMatches) > 1 {
|
if len(sizeMatches) > 1 {
|
||||||
stats.TotalSize = sizeMatches[1]
|
stats.TotalSize = sizeMatches[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracting average speed
|
// 提取平均上传速度。
|
||||||
speedMatches := speedRegex.FindStringSubmatch(line)
|
speedMatches := speedRegex.FindStringSubmatch(line)
|
||||||
if len(speedMatches) > 1 {
|
if len(speedMatches) > 1 {
|
||||||
stats.AverageSpeed = speedMatches[1]
|
stats.AverageSpeed = speedMatches[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extracting Elapsed
|
// 提取上传所花费的时间。
|
||||||
elapsedMatches := elapsedRegex.FindStringSubmatch(line)
|
elapsedMatches := elapsedRegex.FindStringSubmatch(line)
|
||||||
if len(elapsedMatches) > 1 {
|
if len(elapsedMatches) > 1 {
|
||||||
stats.Elapsed = elapsedMatches[1]
|
stats.Elapsed = elapsedMatches[1]
|
||||||
@ -721,10 +742,22 @@ func countMediaFiles(directory string) (int, int, error) {
|
|||||||
return tsCount, m3u8Count, err
|
return tsCount, m3u8Count, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 URL 函数
|
// createURL 是一个用于创建并返回一个url.URL指针的函数。
|
||||||
|
// 它接受一个字符串类型的参数link,表示待解析的URL链接。
|
||||||
|
// 如果链接解析失败,将会记录错误信息并终止程序。
|
||||||
|
//
|
||||||
|
// 参数:
|
||||||
|
//
|
||||||
|
// link string - 待解析的URL字符串。
|
||||||
|
//
|
||||||
|
// 返回值:
|
||||||
|
//
|
||||||
|
// *url.URL - 解析后的URL结构体指针。
|
||||||
func createURL(link string) *url.URL {
|
func createURL(link string) *url.URL {
|
||||||
|
// 解析提供的链接
|
||||||
url, err := url.Parse(link)
|
url, err := url.Parse(link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// 如果解析失败,记录错误信息并终止程序
|
||||||
log.Fatalf("Error parsing URL: %v", err)
|
log.Fatalf("Error parsing URL: %v", err)
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user