Skip to content

Commit

Permalink
[update] version 1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Diving-Fish committed Jul 19, 2023
1 parent be8f23c commit 5eee8c7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 33 deletions.
39 changes: 35 additions & 4 deletions proxy/cmd/maimaidx-prober-proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"os"
"strings"
Expand All @@ -17,13 +18,43 @@ const (
)

type config struct {
UserName string `json:"username"`
Password string `json:"password"`
Mode string `json:"mode,omitempty"`
MaiDiffs []string `json:"mai_diffs,omitempty"`
UserName string `json:"username"`
Password string `json:"password"`
Mode string `json:"mode,omitempty"`
MaiDiffs []string `json:"mai_diffs,omitempty"`
Verbose bool `json:"verbose" default:"false"`
Addr string `json:"addr" default:":8033"`
NoEditGlobalProxy bool `json:"no_edit_global_proxy" default:"false"`
NetworkTimeout int `json:"timeout" default:"30"`
Slice bool `json:"slice" default:"false"`
// intermediate value
MaiIntDiffs []int
}

func (c *config) FlagOverride(set *flag.FlagSet) (err error) {
set.Visit(func(f *flag.Flag) {
if f.Name == "v" {
c.Verbose = f.Value.(flag.Getter).Get().(bool)
} else if f.Name == "addr" {
c.Addr = f.Value.(flag.Getter).Get().(string)
} else if f.Name == "no-edit-global-proxy" {
c.NoEditGlobalProxy = f.Value.(flag.Getter).Get().(bool)
} else if f.Name == "timeout" {
c.NetworkTimeout = f.Value.(flag.Getter).Get().(int)
} else if f.Name == "mai-diffs" {
maiDiffs := strings.Split(f.Value.String(), ",")
if len(maiDiffs) == 1 && maiDiffs[0] == "" {
maiDiffs = c.MaiDiffs
} else {
c.MaiDiffs = maiDiffs
}
} else if f.Name == "slice" {
c.Slice = f.Value.(flag.Getter).Get().(bool)
}
})
return
}

func (c *config) getWorkingMode() workingMode {
if c.Mode == "export" {
return workingModeExport
Expand Down
52 changes: 30 additions & 22 deletions proxy/cmd/maimaidx-prober-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"syscall"

"github.com/elazarl/goproxy"
Expand All @@ -25,20 +24,19 @@ func patchGoproxyCert() {
}

func main() {
verbose := flag.Bool("v", false, "should every proxy request be logged to stdout")
addr := flag.String("addr", ":8033", "proxy listen address")
configPath := flag.String("config", "config.json", "path to config.json file")
noEditGlobalProxy := flag.Bool("no-edit-global-proxy", false, "don't edit the global proxy settings")
networkTimeout := flag.Int("timeout", 30, "timeout when connect to servers")
maiDiffStr := flag.String("mai-diffs", "", "mai diffs to import")
flag.Parse()
flagSet := flag.NewFlagSet("proxy", flag.PanicOnError)

flagSet.Bool("v", false, "should every proxy request be logged to stdout")
flagSet.String("addr", ":8033", "proxy listen address")
configPath := flagSet.String("config", "config.json", "path to config.json file")
flagSet.Bool("no-edit-global-proxy", false, "don't edit the global proxy settings")
flagSet.Bool("slice", false, "using more parts to import records")
flagSet.Int("timeout", 30, "timeout when connect to servers")
flagSet.String("mai-diffs", "", "mai diffs to import")

checkUpdate()

var spm *systemProxyManager
if !*noEditGlobalProxy {
spm = newSystemProxyManager(*addr)
}

commandFatal := func(err error) {
if spm != nil {
spm.rollback()
Expand All @@ -49,25 +47,35 @@ func main() {
os.Exit(0)
}

err := flagSet.Parse(os.Args[1:])
if err != nil {
commandFatal(fmt.Errorf("加载命令行参数出错,请检查您的参数"))
}

cfg, err := initConfig(*configPath)
if err != nil {
commandFatal(err)
}

maiDiffs := strings.Split(*maiDiffStr, ",")
if len(maiDiffs) == 1 && maiDiffs[0] == "" {
maiDiffs = cfg.MaiDiffs
err = cfg.FlagOverride(flagSet)
if err != nil {
commandFatal(err)
}
cfg.MaiIntDiffs, err = getMaiDiffs(maiDiffs)

cfg.MaiIntDiffs, err = getMaiDiffs(cfg.MaiDiffs)
if err != nil {
commandFatal(err)
}

apiClient, err := newProberAPIClient(&cfg, *networkTimeout)
if !cfg.NoEditGlobalProxy {
spm = newSystemProxyManager(cfg.Addr)
}

apiClient, err := newProberAPIClient(&cfg, cfg.NetworkTimeout)
if err != nil {
commandFatal(err)
}
proxyCtx := newProxyContext(apiClient, commandFatal, *verbose)
proxyCtx := newProxyContext(apiClient, commandFatal, cfg.Verbose)

Log(LogLevelInfo, "使用此软件则表示您同意共享您在微信公众号舞萌 DX、中二节奏中的数据。")
Log(LogLevelInfo, "您可以在微信客户端访问微信公众号舞萌 DX、中二节奏的个人信息主页进行分数导入,如需退出请直接关闭程序或按下 Ctrl + C")
Expand All @@ -91,11 +99,11 @@ func main() {
patchGoproxyCert()
srv := proxyCtx.makeProxyServer()

if host, _, err := net.SplitHostPort(*addr); err == nil && host == "" {
if host, _, err := net.SplitHostPort(cfg.Addr); err == nil && host == "" {
// hack
*addr = "127.0.0.1" + *addr
cfg.Addr = "127.0.0.1" + cfg.Addr
}
Log(LogLevelInfo, "代理已开启到 %s", *addr)
Log(LogLevelInfo, "代理已开启到 %s", cfg.Addr)

log.Fatal(http.ListenAndServe(*addr, srv))
log.Fatal(http.ListenAndServe(cfg.Addr, srv))
}
68 changes: 62 additions & 6 deletions proxy/cmd/maimaidx-prober-proxy/prober_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type proberAPIClient struct {
jwt *http.Cookie
mode workingMode
maiDiffs []int
slice bool
}

func newProberAPIClient(cfg *config, networkTimeout int) (*proberAPIClient, error) {
Expand All @@ -46,6 +47,7 @@ func newProberAPIClient(cfg *config, networkTimeout int) (*proberAPIClient, erro
jwt: resp.Cookies()[0],
mode: cfg.getWorkingMode(),
maiDiffs: cfg.MaiIntDiffs,
slice: cfg.Slice,
}, nil
}

Expand Down Expand Up @@ -89,19 +91,37 @@ func (c *proberAPIClient) fetchDataMaimai(req0 *http.Request, cookies []*http.Co
labels := []string{
"Basic", "Advanced", "Expert", "Master", "Re: MASTER",
}
versionTags := []string{
"V-0", "V-1", "V-2", "V-3", "V-4", "V-5", "V-6", "V-7", "V-8", "V-9", "V-10", "V-11", "V-12", "V-13", "V-15", "V-17", "V-19",
}
versionLabels := []string{
"maimai", "maimai PLUS", "GreeN", "GreeN PLUS", "ORANGE", "ORANGE PLUS", "PiNK", "PiNK PLUS", "MURASAKi", "MURASAKi PLUS", "MiLK", "MiLK PLUS", "FiNALE", "舞萌DX", "舞萌DX 2021", "舞萌DX 2022", "舞萌DX 2023",
}
for _, i := range c.maiDiffs {
Log(LogLevelInfo, "正在导入 %s 难度……", labels[i])
for {
err := c.fetchDataMaimaiPerDiff(i)
if err == nil {
break
if c.slice {
for j, versionTag := range versionTags {
Log(LogLevelInfo, "正在导入 %s 版本的 %s 难度……", versionLabels[j], labels[i])
for {
err := c.fetchDataMaimaiPerDiffAndVersion(i, versionTag)
if err == nil {
break
}
}
}
} else {
Log(LogLevelInfo, "正在导入 %s 难度……", labels[i])
for {
err := c.fetchDataMaimaiPerDiff(i)
if err == nil {
break
}
}
}
}
}

func (c *proberAPIClient) fetchDataMaimaiPerDiff(diff int) (err error) {
req, err := http.NewRequest(http.MethodGet, "https://maimai.wahlap.com/maimai-mobile/record/musicGenre/search/?genre=99&diff="+strconv.Itoa(diff), nil)
req, err := http.NewRequest(http.MethodGet, "https://maimai.wahlap.com/maimai-mobile/record/musicSort/search/?search=A&sort=1&playCheck=on&diff="+strconv.Itoa(diff), nil)
if err != nil {
Log(LogLevelWarning, "从 Wahlap 服务器获取数据失败,正在重试……")
return
Expand Down Expand Up @@ -238,3 +258,39 @@ func (c *proberAPIClient) fetchDataChuniPerDiff(headers http.Header, cookies []*
}
return nil
}

func (c *proberAPIClient) fetchDataMaimaiPerDiffAndVersion(diff int, version string) (err error) {
pageUrl := fmt.Sprintf("https://maimai.wahlap.com/maimai-mobile/record/musicSort/search/?search=%s&sort=1&playCheck=on&diff=%d", version, diff)
req, err := http.NewRequest(http.MethodGet, pageUrl, nil)
if err != nil {
Log(LogLevelWarning, "从 Wahlap 服务器获取数据失败,正在重试……")
return
}
resp, err := c.cl.Do(req)
if err != nil {
Log(LogLevelWarning, "从 Wahlap 服务器获取数据失败,正在重试……")
return
}
respText, err := io.ReadAll(resp.Body)
if err != nil {
Log(LogLevelWarning, "从 Wahlap 服务器获取数据超时,正在重试……您也可以使用命令行参数 -timeout 120 来调整超时时间为 120 秒(默认为 30 秒)")
return
}
switch c.mode {
case workingModeUpdate:
err = c.commit(respText)
if err != nil {
Log(LogLevelWarning, "提交数据到查分服务器失败,正在重试……")
return
}
Log(LogLevelInfo, "导入成功")
case workingModeExport:
err = os.WriteFile(fmt.Sprintf("mai-diff-%s-%d.html", version, diff), respText, 0644)
if err != nil {
Log(LogLevelWarning, "导出到文件失败")
return nil
}
Log(LogLevelInfo, "已导出到文件")
}
return
}
2 changes: 1 addition & 1 deletion web/src/components/ChartTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export default {
if (this.chart === null) {
let that = this;
setTimeout(() => {
that.chart = this.$echarts.init(this.$refs.chart_div);
that.chart = this.$echarts.init(this.$refs.chart_div, 'dark');
that.chart.setOption(option);
}, 100);
} else {
Expand Down

0 comments on commit 5eee8c7

Please sign in to comment.