1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 03:53:50 +08:00

better error

This commit is contained in:
wdvxdr 2021-01-25 17:34:23 +08:00
parent bf65b576f3
commit 23b90e288c
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
2 changed files with 9 additions and 9 deletions

View File

@ -2,13 +2,13 @@ package global
import (
"crypto/md5"
"errors"
"fmt"
"io/ioutil"
"os/exec"
"path"
"github.com/Mrs4s/go-cqhttp/global/codec"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
@ -32,7 +32,7 @@ func EncoderSilk(data []byte) ([]byte, error) {
h := md5.New()
_, err := h.Write(data)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "calc md5 failed")
}
tempName := fmt.Sprintf("%x", h.Sum(nil))
if silkPath := path.Join("data/cache", tempName+".silk"); PathExists(silkPath) {
@ -40,7 +40,7 @@ func EncoderSilk(data []byte) ([]byte, error) {
}
slk, err := codec.EncodeToSilk(data, tempName, true)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "encode silk failed")
}
return slk, nil
}
@ -51,7 +51,7 @@ func EncodeMP4(src string, dst string) error { // -y 覆盖文件
err := cmd1.Run()
if err != nil {
cmd2 := exec.Command("ffmpeg", "-i", src, "-y", "-c:v", "h264", "-c:a", "mp3", dst)
return cmd2.Run()
return errors.Wrap(cmd2.Run(), "convert mp4 failed")
}
return err
}
@ -59,5 +59,5 @@ func EncodeMP4(src string, dst string) error { // -y 覆盖文件
//ExtractCover 获取给定视频文件的Cover
func ExtractCover(src string, target string) error {
cmd := exec.Command("ffmpeg", "-i", src, "-y", "-r", "1", "-f", "image2", target)
return cmd.Run()
return errors.Wrap(cmd.Run(), "extract video cover failed")
}

View File

@ -4,7 +4,7 @@
package codec
import (
"errors"
"github.com/pkg/errors"
"io/ioutil"
"net/http"
"os"
@ -63,7 +63,7 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error)
rawPath := path.Join(silkCachePath, tempName+".wav")
err := ioutil.WriteFile(rawPath, record, os.ModePerm)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "write temp file error")
}
defer os.Remove(rawPath)
@ -71,7 +71,7 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error)
pcmPath := path.Join(silkCachePath, tempName+".pcm")
cmd := exec.Command("ffmpeg", "-i", rawPath, "-f", "s16le", "-ar", "24000", "-ac", "1", pcmPath)
if err = cmd.Run(); err != nil {
return nil, err
return nil, errors.Wrap(err, "convert pcm file error")
}
defer os.Remove(pcmPath)
@ -79,7 +79,7 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error)
silkPath := path.Join(silkCachePath, tempName+".silk")
cmd = exec.Command(getEncoderFilePath(), pcmPath, silkPath, "-rate", "24000", "-quiet", "-tencent")
if err = cmd.Run(); err != nil {
return nil, err
return nil, errors.Wrap(err, "convert silk file error")
}
if !useCache {
defer os.Remove(silkPath)