|
@@ -1,4 +1,3 @@
|
|
|
-
|
|
|
package utils
|
|
|
|
|
|
import (
|
|
@@ -292,22 +291,22 @@ func SaveBase64ToFile(content, path string) error {
|
|
|
|
|
|
func SaveBase64ToFileBySeek(content, path string) (err error) {
|
|
|
data, err := base64.StdEncoding.DecodeString(content)
|
|
|
- exist,err:=PathExists(path)
|
|
|
- if err!=nil {
|
|
|
+ exist, err := PathExists(path)
|
|
|
+ if err != nil {
|
|
|
return
|
|
|
}
|
|
|
if !exist {
|
|
|
f, err := os.Create(path)
|
|
|
- if err!=nil {
|
|
|
+ if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
n, _ := f.Seek(0, 2)
|
|
|
// 从末尾的偏移量开始写入内容
|
|
|
_, err = f.WriteAt([]byte(data), n)
|
|
|
defer f.Close()
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
f, err := os.OpenFile(path, os.O_WRONLY, 0644)
|
|
|
- if err!=nil {
|
|
|
+ if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
n, _ := f.Seek(0, 2)
|
|
@@ -319,7 +318,7 @@ func SaveBase64ToFileBySeek(content, path string) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func PathExists(path string) (bool,error) {
|
|
|
+func PathExists(path string) (bool, error) {
|
|
|
_, err := os.Stat(path)
|
|
|
if err == nil {
|
|
|
return true, nil
|
|
@@ -489,7 +488,6 @@ func Sha1(data string) string {
|
|
|
return hex.EncodeToString(sha1.Sum([]byte("")))
|
|
|
}
|
|
|
|
|
|
-
|
|
|
func GetVideoPlaySeconds(videoPath string) (playSeconds float64, err error) {
|
|
|
cmd := `ffmpeg -i ` + videoPath + ` 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//`
|
|
|
out, err := exec.Command("bash", "-c", cmd).Output()
|
|
@@ -497,7 +495,7 @@ func GetVideoPlaySeconds(videoPath string) (playSeconds float64, err error) {
|
|
|
return
|
|
|
}
|
|
|
outTimes := string(out)
|
|
|
- fmt.Println("outTimes:",outTimes)
|
|
|
+ fmt.Println("outTimes:", outTimes)
|
|
|
if outTimes != "" {
|
|
|
timeArr := strings.Split(outTimes, ":")
|
|
|
h := timeArr[0]
|
|
@@ -505,18 +503,18 @@ func GetVideoPlaySeconds(videoPath string) (playSeconds float64, err error) {
|
|
|
s := timeArr[2]
|
|
|
hInt, err := strconv.Atoi(h)
|
|
|
if err != nil {
|
|
|
- return playSeconds,err
|
|
|
+ return playSeconds, err
|
|
|
}
|
|
|
|
|
|
mInt, err := strconv.Atoi(m)
|
|
|
if err != nil {
|
|
|
- return playSeconds,err
|
|
|
+ return playSeconds, err
|
|
|
}
|
|
|
- s=strings.Trim(s," ")
|
|
|
- s=strings.Trim(s,"\n")
|
|
|
- sInt, err :=strconv.ParseFloat(s, 64)
|
|
|
+ s = strings.Trim(s, " ")
|
|
|
+ s = strings.Trim(s, "\n")
|
|
|
+ sInt, err := strconv.ParseFloat(s, 64)
|
|
|
if err != nil {
|
|
|
- return playSeconds,err
|
|
|
+ return playSeconds, err
|
|
|
}
|
|
|
playSeconds = float64(hInt)*3600 + float64(mInt)*60 + float64(sInt)
|
|
|
}
|
|
@@ -535,7 +533,6 @@ func GetMaxTradeCode(tradeCode string) (maxTradeCode string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// excel日期字段格式化 yyyy-mm-dd
|
|
|
func ConvertToFormatDay(excelDaysString string) string {
|
|
|
// 2006-01-02 距离 1900-01-01的天数
|