Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Apr 17, 2024
1 parent c5347fa commit 04d3d61
Show file tree
Hide file tree
Showing 40 changed files with 1,073 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 发行版
on:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@master

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@

# Go workspace file
go.work

# Packed configs
*.zip

# MacOS system file
.DS_Store
89 changes: 89 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
project_name: rvcmd
env:
- GO111MODULE=on
before:
hooks:
- go mod tidy
- go generate
builds:
- id: linux
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- linux
goarch:
- 386
- amd64
- arm
- arm64
goarm:
- 6
- 7
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w
- id: macos
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- darwin
goarch:
- amd64
- arm64
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w
- id: windows
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- windows
goarch:
- 386
- amd64
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- -s -w

checksum:
name_template: "rvcmd_checksums.txt"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- fix typo
- Merge pull request
- Merge branch
- Merge remote-tracking
- go mod tidy

archives:
- id: all
builds:
- linux
- macos
- windows
name_template: "rvcmd_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
format_overrides:
- goos: windows
format: zip

nfpms:
- license: AGPL 3.0
homepage: https://github.com/RVC-Project/RVC-Models-Downloader
file_name_template: "rvcmd_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
formats:
- deb
- rpm
maintainer: Fumiama Minamoto
7 changes: 7 additions & 0 deletions assets/all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BaseURL: https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main
Targets:
- Refer: hubert
- Refer: rmvpe
- Refer: v1
- Refer: v2
- Refer: uvr5
5 changes: 5 additions & 0 deletions assets/hubert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BaseURL: https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main
Targets:
- Folder: assets/hubert
Copy:
- hubert_base.pt
6 changes: 6 additions & 0 deletions assets/rmvpe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BaseURL: https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main
Targets:
- Folder: .
Copy:
- rmvpe.pt
- rmvpe.onnx
15 changes: 15 additions & 0 deletions assets/uvr5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BaseURL: https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main
Targets:
- Folder: assets/uvr5_weights
Copy:
- uvr5_weights/HP2-人声vocals+非人声instrumentals.pth
- uvr5_weights/HP2_all_vocals.pth
- uvr5_weights/HP3_all_vocals.pth
- uvr5_weights/HP5-主旋律人声vocals+其他instrumentals.pth
- uvr5_weights/HP5_only_main_vocal.pth
- uvr5_weights/VR-DeEchoAggressive.pth
- uvr5_weights/VR-DeEchoDeReverb.pth
- uvr5_weights/VR-DeEchoNormal.pth
- Folder: assets/uvr5_weights/onnx_dereverb_By_FoxJoy
Copy:
- uvr5_weights/onnx_dereverb_By_FoxJoy/vocals.onnx
18 changes: 18 additions & 0 deletions assets/v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BaseURL: https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main
Targets:
- Refer: hubert
- Folder: assets/pretrained
Copy:
- pretrained/D32k.pth
- pretrained/D40k.pth
- pretrained/D48k.pth
- pretrained/G32k.pth
- pretrained/G40k.pth
- pretrained/G48k.pth
- pretrained/f0D32k.pth
- pretrained/f0D40k.pth
- pretrained/f0D48k.pth
- pretrained/f0G32k.pth
- pretrained/f0G40k.pth
- pretrained/f0G48k.pth
- Refer: uvr5
18 changes: 18 additions & 0 deletions assets/v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BaseURL: https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main
Targets:
- Refer: hubert
- Folder: assets/pretrained_v2
Copy:
- pretrained_v2/D32k.pth
- pretrained_v2/D40k.pth
- pretrained_v2/D48k.pth
- pretrained_v2/G32k.pth
- pretrained_v2/G40k.pth
- pretrained_v2/G48k.pth
- pretrained_v2/f0D32k.pth
- pretrained_v2/f0D40k.pth
- pretrained_v2/f0D48k.pth
- pretrained_v2/f0G32k.pth
- pretrained_v2/f0G40k.pth
- pretrained_v2/f0G48k.pth
- Refer: uvr5
143 changes: 143 additions & 0 deletions cfg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package main

import (
"archive/zip"
"bytes"
_ "embed"
"fmt"
"io"
"net/http"
"os"
"runtime"
"strings"
"sync"
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
)

//go:embed cfg.zip
var cfgdata []byte

var cfg = func() *zip.Reader {
r, err := zip.NewReader(bytes.NewReader(cfgdata), int64(len(cfgdata)))
if err != nil {
panic(err)
}
for _, f := range r.File {
cmdlst = append(cmdlst, f.Name)
}
return r
}()

func readconfig(path string) (c config, err error) {
fname := path + ".yaml"
f, err := cfg.Open(fname)
if err != nil {
err = errors.Wrap(err, "invalid path")
return
}
defer f.Close()
err = yaml.NewDecoder(f).Decode(&c)
if err != nil {
err = errors.Wrap(err, "invalid config")
return
}
return
}

type config struct {
BaseURL string `yaml:"BaseURL"`
Targets []targets `yaml:"Targets"`
}

type targets struct {
Refer string `yaml:"Refer"`
Folder string `yaml:"Folder"`
Copy []string `yaml:"Copy"`
OS string `yaml:"OS"`
Arch string `yaml:"Arch"`
}

func (c *config) download(path string) error {
for i, t := range c.Targets {
if t.Refer != "" {
refp := path[:strings.LastIndex(path, "/")+1] + t.Refer
logrus.Infof("#%d refer to target '%s'", i+1, refp)
refcfg, err := readconfig(refp)
if err != nil {
return err
}
err = refcfg.download(refp)
if err != nil {
return err
}
continue
}
if t.OS != "" && t.OS != runtime.GOOS {
logrus.Warnf("#%d target required OS: %s but you are %s, skip.", i+1, t.OS, runtime.GOOS)
continue
}
if t.Arch != "" && t.Arch != runtime.GOARCH {
logrus.Warnf("#%d target required Arch: %s but you are %s, skip.", i+1, t.Arch, runtime.GOARCH)
continue
}
err := os.MkdirAll(t.Folder, 0755)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("#%d make target folder '%s'", i+1, t.Folder))
}
logrus.Infof("#%d open target folder '%s'", i+1, t.Folder)
if len(t.Copy) == 0 {
logrus.Warningf("#%d empty copy target", i+1)
continue
}
wg := sync.WaitGroup{}
wg.Add(len(t.Copy))
logrus.Infof("#%d download copy: %v", i+1, t.Copy)
for i, cp := range t.Copy {
go func(i int, cp string) {
defer wg.Done()
sleep := time.Millisecond * 100 * time.Duration(i)
if sleep > time.Millisecond {
time.Sleep(sleep)
}
req, err := http.NewRequest("GET", c.BaseURL+"/"+cp, nil)
if err != nil {
logrus.Errorln("new request to", cp, "err:", err)
return
}
logrus.Infoln("get:", req.URL)
req.Header.Add("user-agent", ua)
resp, err := cli.Do(req)
if err != nil {
logrus.Errorln("get", req.URL, "err:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
err := errors.New(fmt.Sprintf("HTTP %d %s", resp.StatusCode, resp.Status))
logrus.Errorln("get", req.URL, "err:", err)
return
}
fname := t.Folder + "/" + cp
f, err := os.Create(fname)
if err != nil {
logrus.Errorln("create file", fname, "err:", err)
return
}
logrus.Infoln("writing file", fname)
defer f.Close()
_, err = io.Copy(f, resp.Body)
if err != nil {
logrus.Errorln("download file", fname, "err:", err)
return
}
logrus.Infoln("downloaded file", fname)
}(i, cp)
}
wg.Wait()
}
return nil
}
49 changes: 49 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"strings"
)

type commandlist []string

var cmdlst = make(commandlist, 0, 64)

func (cl commandlist) String() string {
sb := strings.Builder{}
islastdir := false
isfirstloop := true
sb.WriteString(" ")
for _, cmd := range cmdlst {
if len(cmd) == 0 {
continue
}
trimedcmd := strings.TrimSuffix(cmd, "/")
a := strings.LastIndex(trimedcmd, "/") + 1
b := len(cmd) - 1
if a >= b {
continue
}
isdir := cmd[b] == '/'
ident := strings.Count(trimedcmd, "/") + 1
if !isfirstloop && (islastdir || isdir) {
sb.WriteByte('\n')
if !isdir {
ident--
}
for i := 0; i < ident; i++ {
sb.WriteString(" ")
}
}
isfirstloop = false
if isdir {
islastdir = true
sb.WriteString(cmd[a:b])
sb.WriteByte(':')
} else { // is file
islastdir = false
sb.WriteString(" ")
sb.WriteString(strings.TrimSuffix(cmd[a:], ".yaml"))
}
}
return sb.String()
}
Loading

0 comments on commit 04d3d61

Please sign in to comment.