mirror of
https://git.um-react.app/um/cli.git
synced 2025-11-28 11:43:02 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15e340eac4 | ||
|
|
c836ac7cb5 | ||
|
|
ad301e0ff2 | ||
|
|
1f0aefb72d | ||
|
|
c71ad9cc79 | ||
|
|
1760737121 | ||
|
|
b517806fdb | ||
|
|
b6df09cee3 | ||
|
|
9cf42af251 | ||
|
|
c1c43d2a41 | ||
|
|
f9686bbfc4 |
15
.github/workflows/build.yml
vendored
15
.github/workflows/build.yml
vendored
@@ -6,6 +6,7 @@ on:
|
|||||||
- "**/*.go"
|
- "**/*.go"
|
||||||
- "go.mod"
|
- "go.mod"
|
||||||
- "go.sum"
|
- "go.sum"
|
||||||
|
- ".github/workflows/*.yml"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
types: [ opened, synchronize, reopened ]
|
types: [ opened, synchronize, reopened ]
|
||||||
@@ -22,14 +23,16 @@ jobs:
|
|||||||
os: [ windows-latest, ubuntu-latest, macos-latest ]
|
os: [ windows-latest, ubuntu-latest, macos-latest ]
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
BIN_SUFFIX:
|
BIN_SUFFIX: ""
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
BIN_SUFFIX:
|
BIN_SUFFIX: ""
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
BIN_SUFFIX: .exe
|
BIN_SUFFIX: ".exe"
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout codebase
|
- name: Checkout codebase
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Go 1.x
|
- name: Set up Go 1.x
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
@@ -38,12 +41,14 @@ jobs:
|
|||||||
|
|
||||||
- name: Setup vars
|
- name: Setup vars
|
||||||
id: vars
|
id: vars
|
||||||
run: echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
run: |
|
||||||
|
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
|
||||||
|
echo "::set-output name=git_tag::$(git describe --tags --always)"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
env:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
run: go build -trimpath -ldflags="-w -s" -v -o um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} ./cmd/um
|
run: go build -trimpath -ldflags="-w -s -X main.AppVersion=${{ steps.vars.outputs.git_tag }}" -v -o um-${{ runner.os }}${{ matrix.BIN_SUFFIX }} ./cmd/um
|
||||||
|
|
||||||
- name: Publish artifact
|
- name: Publish artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
# Unlock Music Project - CLI Edition
|
# Unlock Music Project - CLI Edition
|
||||||
|
|
||||||
Original: Web Edition https://github.com/ix64/unlock-music
|
Original: Web Edition https://github.com/ix64/unlock-music
|
||||||
|
|
||||||
- [Release Download](https://github.com/unlock-music/cli/releases/latest)
|
- [Release Download](https://github.com/unlock-music/cli/releases/latest)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [x] All Algorithm Supported By `ix64/unlock-music`
|
- [x] All Algorithm Supported By `ix64/unlock-music`
|
||||||
- [ ] Complete Cover Image
|
- [ ] Complete Cover Image
|
||||||
- [ ] Parse Meta Data
|
- [ ] Parse Meta Data
|
||||||
- [ ] Complete Meta Data
|
- [ ] Complete Meta Data
|
||||||
|
|
||||||
## Hou to Build
|
## Hou to Build
|
||||||
|
|
||||||
- Requirements: **Golang 1.16**
|
- Requirements: **Golang 1.16**
|
||||||
|
|
||||||
1. Clone this repo `git clone https://github.com/unlock-music/cli && cd cli`
|
1. Clone this repo `git clone https://github.com/unlock-music/cli && cd cli`
|
||||||
2. Build the executable `go build ./cmd/um`
|
2. Build the executable `go build ./cmd/um`
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
|
- Drag the encrypted file to `um.exe` (Tested on Windows)
|
||||||
|
- Run: `./um [-o <output dir>] [-i] <input dir/file>`
|
||||||
- Use `./um -h` to show help menu
|
- Use `./um -h` to show help menu
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
type RawDecoder struct {
|
type RawDecoder struct {
|
||||||
file []byte
|
file []byte
|
||||||
audioExt string
|
audioExt string
|
||||||
}
|
}
|
||||||
|
|
||||||
//goland:noinspection GoUnusedExportedFunction
|
|
||||||
func NewRawDecoder(file []byte) Decoder {
|
func NewRawDecoder(file []byte) Decoder {
|
||||||
return &RawDecoder{file: file}
|
return &RawDecoder{file: file}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d RawDecoder) Validate() error {
|
func (d *RawDecoder) Validate() error {
|
||||||
return nil
|
for ext, sniffer := range snifferRegistry {
|
||||||
|
if sniffer(d.file) {
|
||||||
|
d.audioExt = ext
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.New("audio doesn't recognized")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d RawDecoder) Decode() error {
|
func (d RawDecoder) Decode() error {
|
||||||
@@ -33,15 +40,13 @@ func (d RawDecoder) GetAudioExt() string {
|
|||||||
func (d RawDecoder) GetMeta() Meta {
|
func (d RawDecoder) GetMeta() Meta {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func DecoderFuncWithExt(ext string) NewDecoderFunc {
|
|
||||||
return func(file []byte) Decoder {
|
|
||||||
return &RawDecoder{file: file, audioExt: ext}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func init() {
|
func init() {
|
||||||
/*RegisterDecoder("mp3", DecoderFuncWithExt("mp3"))
|
RegisterDecoder("mp3", NewRawDecoder)
|
||||||
RegisterDecoder("flac", DecoderFuncWithExt("flac"))
|
RegisterDecoder("flac", NewRawDecoder)
|
||||||
RegisterDecoder("wav", DecoderFuncWithExt("wav"))
|
RegisterDecoder("ogg", NewRawDecoder)
|
||||||
RegisterDecoder("ogg", DecoderFuncWithExt("ogg"))
|
RegisterDecoder("m4a", NewRawDecoder)
|
||||||
RegisterDecoder("m4a", DecoderFuncWithExt("m4a"))*/
|
RegisterDecoder("wav", NewRawDecoder)
|
||||||
|
RegisterDecoder("wma", NewRawDecoder)
|
||||||
|
RegisterDecoder("aac", NewRawDecoder)
|
||||||
}
|
}
|
||||||
|
|||||||
48
algo/common/sniff.go
Normal file
48
algo/common/sniff.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
|
type Sniffer func(header []byte) bool
|
||||||
|
|
||||||
|
var snifferRegistry = map[string]Sniffer{
|
||||||
|
".mp3": SnifferMP3,
|
||||||
|
".flac": SnifferFLAC,
|
||||||
|
".ogg": SnifferOGG,
|
||||||
|
".m4a": SnifferM4A,
|
||||||
|
".wav": SnifferWAV,
|
||||||
|
".wma": SnifferWMA,
|
||||||
|
".aac": SnifferAAC,
|
||||||
|
}
|
||||||
|
|
||||||
|
func SniffAll(header []byte) (string, bool) {
|
||||||
|
for ext, sniffer := range snifferRegistry {
|
||||||
|
if sniffer(header) {
|
||||||
|
return ext, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
func SnifferM4A(header []byte) bool {
|
||||||
|
return len(header) >= 8 && bytes.Equal([]byte("ftyp"), header[4:8])
|
||||||
|
}
|
||||||
|
|
||||||
|
func SnifferOGG(header []byte) bool {
|
||||||
|
return bytes.HasPrefix(header, []byte("OggS"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func SnifferFLAC(header []byte) bool {
|
||||||
|
return bytes.HasPrefix(header, []byte("fLaC"))
|
||||||
|
}
|
||||||
|
func SnifferMP3(header []byte) bool {
|
||||||
|
return bytes.HasPrefix(header, []byte("ID3"))
|
||||||
|
}
|
||||||
|
func SnifferWAV(header []byte) bool {
|
||||||
|
return bytes.HasPrefix(header, []byte("RIFF"))
|
||||||
|
}
|
||||||
|
func SnifferWMA(header []byte) bool {
|
||||||
|
return bytes.HasPrefix(header, []byte("\x30\x26\xb2\x75\x8e\x66\xcf\x11\xa6\xd9\x00\xaa\x00\x62\xce\x6c"))
|
||||||
|
}
|
||||||
|
func SnifferAAC(header []byte) bool {
|
||||||
|
return bytes.HasPrefix(header, []byte{0xFF, 0xF1})
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ func (d Decoder) GetAudioData() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d Decoder) GetAudioExt() string {
|
func (d Decoder) GetAudioExt() string {
|
||||||
return ""
|
return "" // use sniffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Decoder) GetMeta() common.Meta {
|
func (d Decoder) GetMeta() common.Meta {
|
||||||
@@ -58,9 +58,8 @@ func (d *Decoder) Validate() error {
|
|||||||
|
|
||||||
d.key = d.file[0x1c:0x2c]
|
d.key = d.file[0x1c:0x2c]
|
||||||
d.key = append(d.key, 0x00)
|
d.key = append(d.key, 0x00)
|
||||||
_ = d.file[0x2c:0x3c] //key2
|
_ = d.file[0x2c:0x3c] //todo: key2
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) Decode() error {
|
func (d *Decoder) Decode() error {
|
||||||
@@ -69,7 +68,8 @@ func (d *Decoder) Decode() error {
|
|||||||
lenData := len(dataEncrypted)
|
lenData := len(dataEncrypted)
|
||||||
initMask()
|
initMask()
|
||||||
if fullMaskLen < lenData {
|
if fullMaskLen < lenData {
|
||||||
logging.Log().Warn("文件过大,处理后的音频不完整,请向我们报告此文件的信息")
|
logging.Log().Warn("The file is too large and the processed audio is incomplete, " +
|
||||||
|
"please report to us about this file at https://github.com/unlock-music/cli/issues")
|
||||||
lenData = fullMaskLen
|
lenData = fullMaskLen
|
||||||
}
|
}
|
||||||
d.audio = make([]byte, lenData)
|
d.audio = make([]byte, lenData)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ var maskV2 []byte
|
|||||||
var fullMaskLen int
|
var fullMaskLen int
|
||||||
var initMaskOK = false
|
var initMaskOK = false
|
||||||
|
|
||||||
//todo: 根据需求解压Mask大小
|
//todo: decompress mask on demand
|
||||||
func initMask() {
|
func initMask() {
|
||||||
if initMaskOK {
|
if initMaskOK {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func (d *Decoder) GetAudioData() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) GetAudioExt() string {
|
func (d *Decoder) GetAudioExt() string {
|
||||||
return d.outputExt
|
return "." + d.outputExt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) GetMeta() common.Meta {
|
func (d *Decoder) GetMeta() common.Meta {
|
||||||
@@ -125,4 +125,5 @@ func padOrTruncate(raw string, length int) string {
|
|||||||
func init() {
|
func init() {
|
||||||
// Kuwo Mp3/Flac
|
// Kuwo Mp3/Flac
|
||||||
common.RegisterDecoder("kwm", NewDecoder)
|
common.RegisterDecoder("kwm", NewDecoder)
|
||||||
|
common.RegisterDecoder("kwm", common.NewRawDecoder)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ func (d *Decoder) Validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: 读取前进行检查长度,防止越界
|
|
||||||
func (d *Decoder) readKeyData() error {
|
func (d *Decoder) readKeyData() error {
|
||||||
if d.offsetKey == 0 || d.offsetKey+4 > d.fileLen {
|
if d.offsetKey == 0 || d.offsetKey+4 > d.fileLen {
|
||||||
return errors.New("invalid cover file offset")
|
return errors.New("invalid cover file offset")
|
||||||
@@ -201,7 +200,9 @@ func (d *Decoder) Decode() error {
|
|||||||
|
|
||||||
func (d Decoder) GetAudioExt() string {
|
func (d Decoder) GetAudioExt() string {
|
||||||
if d.meta != nil {
|
if d.meta != nil {
|
||||||
return d.meta.GetFormat()
|
if format := d.meta.GetFormat(); format != "" {
|
||||||
|
return "." + d.meta.GetFormat()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ var (
|
|||||||
0x92, 0x62, 0xf3, 0x74, 0xa1, 0x9f, 0xf4, 0xa0,
|
0x92, 0x62, 0xf3, 0x74, 0xa1, 0x9f, 0xf4, 0xa0,
|
||||||
0x1d, 0x3f, 0x5b, 0xf0, 0x13, 0x0e, 0x09, 0x3d,
|
0x1d, 0x3f, 0x5b, 0xf0, 0x13, 0x0e, 0x09, 0x3d,
|
||||||
0xf9, 0xbc, 0x00, 0x11}
|
0xf9, 0xbc, 0x00, 0x11}
|
||||||
headerFlac = []byte{'f', 'L', 'a', 'C'}
|
|
||||||
headerOgg = []byte{'O', 'g', 'g', 'S'}
|
|
||||||
)
|
)
|
||||||
var key256MappingAll [][]int //[idx256][idx128]idx44
|
var key256MappingAll [][]int //[idx256][idx128]idx44
|
||||||
var key256Mapping128to44 map[int]int
|
var key256Mapping128to44 map[int]int
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package qmc
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/unlock-music/cli/algo/common"
|
||||||
"github.com/unlock-music/cli/internal/logging"
|
"github.com/unlock-music/cli/internal/logging"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
@@ -116,7 +117,7 @@ func detectMflac256Mask(input []byte) (*Key256Mask, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if bytes.Equal(headerFlac, q.Decrypt(input[:len(headerFlac)])) {
|
if common.SnifferFLAC(q.Decrypt(input[:4])) {
|
||||||
rtErr = nil
|
rtErr = nil
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -164,7 +165,7 @@ func detectMgg256Mask(input []byte) (*Key256Mask, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if bytes.Equal(headerOgg, q.Decrypt(input[:len(headerOgg)])) {
|
if common.SnifferOGG(q.Decrypt(input[:4])) {
|
||||||
return q, nil
|
return q, nil
|
||||||
}
|
}
|
||||||
return nil, ErrDetectMggMask
|
return nil, ErrDetectMggMask
|
||||||
|
|||||||
@@ -84,7 +84,10 @@ func (d Decoder) GetAudioData() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d Decoder) GetAudioExt() string {
|
func (d Decoder) GetAudioExt() string {
|
||||||
return d.audioExt
|
if d.audioExt != "" {
|
||||||
|
return "." + d.audioExt
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Decoder) GetMeta() common.Meta {
|
func (d Decoder) GetMeta() common.Meta {
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ func (d *Decoder) GetAudioData() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) GetAudioExt() string {
|
func (d *Decoder) GetAudioExt() string {
|
||||||
return d.audioExt
|
if d.audioExt != "" {
|
||||||
|
return "." + d.audioExt
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) GetMeta() common.Meta {
|
func (d *Decoder) GetMeta() common.Meta {
|
||||||
@@ -70,7 +73,7 @@ func init() {
|
|||||||
common.RegisterDecoder("tm2", DecoderFuncWithExt("m4a"))
|
common.RegisterDecoder("tm2", DecoderFuncWithExt("m4a"))
|
||||||
common.RegisterDecoder("tm6", DecoderFuncWithExt("m4a"))
|
common.RegisterDecoder("tm6", DecoderFuncWithExt("m4a"))
|
||||||
// QQ Music IOS Mp3
|
// QQ Music IOS Mp3
|
||||||
common.RegisterDecoder("tm0", common.DecoderFuncWithExt("mp3"))
|
common.RegisterDecoder("tm0", common.NewRawDecoder)
|
||||||
common.RegisterDecoder("tm3", common.DecoderFuncWithExt("mp3"))
|
common.RegisterDecoder("tm3", common.NewRawDecoder)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,11 @@ func (d *Decoder) GetAudioData() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) GetAudioExt() string {
|
func (d *Decoder) GetAudioExt() string {
|
||||||
return d.outputExt
|
if d.outputExt != "" {
|
||||||
|
return "." + d.outputExt
|
||||||
|
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Decoder) GetMeta() common.Meta {
|
func (d *Decoder) GetMeta() common.Meta {
|
||||||
|
|||||||
@@ -12,36 +12,50 @@ import (
|
|||||||
"github.com/unlock-music/cli/internal/logging"
|
"github.com/unlock-music/cli/internal/logging"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var AppVersion = "0.0.4"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.App{
|
app := cli.App{
|
||||||
Name: "Unlock Music CLI",
|
Name: "Unlock Music CLI",
|
||||||
HelpName: "um",
|
HelpName: "um",
|
||||||
Usage: "Unlock your encrypted music file https://github.com/unlock-music/cli",
|
Usage: "Unlock your encrypted music file https://github.com/unlock-music/cli",
|
||||||
Version: "v0.0.1",
|
Version: AppVersion,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: true},
|
&cli.StringFlag{Name: "input", Aliases: []string{"i"}, Usage: "path to input file or dir", Required: false},
|
||||||
&cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: true},
|
&cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "path to output dir", Required: false},
|
||||||
},
|
},
|
||||||
|
|
||||||
Action: appMain,
|
Action: appMain,
|
||||||
Copyright: "Copyright (c) 2020 Unlock Music https://github.com/unlock-music/cli/blob/master/LICENSE",
|
Copyright: "Copyright (c) 2020 - 2021 Unlock Music https://github.com/unlock-music/cli/blob/master/LICENSE",
|
||||||
HideHelpCommand: true,
|
HideHelpCommand: true,
|
||||||
UsageText: "um -i /path/to/input -o /path/to/output/dir",
|
UsageText: "um [-o /path/to/output/dir] [-i] /path/to/input",
|
||||||
}
|
}
|
||||||
err := app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logging.Log().Fatal("run app failed", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func appMain(c *cli.Context) error {
|
func appMain(c *cli.Context) error {
|
||||||
input := c.String("input")
|
input := c.String("input")
|
||||||
|
if input == "" && c.Args().Present() {
|
||||||
|
input = c.Args().Get(c.Args().Len() - 1)
|
||||||
|
}
|
||||||
|
|
||||||
output := c.String("output")
|
output := c.String("output")
|
||||||
|
if output == "" {
|
||||||
|
var err error
|
||||||
|
output, err = os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inputStat, err := os.Stat(input)
|
inputStat, err := os.Stat(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -117,14 +131,19 @@ func tryDecFile(inputFile string, outputDir string, allDec []common.NewDecoderFu
|
|||||||
return errors.New("failed while decoding: " + err.Error())
|
return errors.New("failed while decoding: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outData := dec.GetAudioData()
|
||||||
outExt := dec.GetAudioExt()
|
outExt := dec.GetAudioExt()
|
||||||
if outExt == "" {
|
if outExt == "" {
|
||||||
outExt = "mp3"
|
if ext, ok := common.SniffAll(outData); ok {
|
||||||
|
outExt = ext
|
||||||
|
} else {
|
||||||
|
outExt = ".mp3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
filenameOnly := strings.TrimSuffix(filepath.Base(inputFile), filepath.Ext(inputFile))
|
filenameOnly := strings.TrimSuffix(filepath.Base(inputFile), filepath.Ext(inputFile))
|
||||||
|
|
||||||
outPath := filepath.Join(outputDir, filenameOnly+"."+outExt)
|
outPath := filepath.Join(outputDir, filenameOnly+outExt)
|
||||||
err = os.WriteFile(outPath, dec.GetAudioData(), 0644)
|
err = os.WriteFile(outPath, outData, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user