Skip to content

Commit

Permalink
feat: version reject
Browse files Browse the repository at this point in the history
  • Loading branch information
anhoder committed Sep 5, 2022
1 parent 31d840a commit f31178f
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GOLANG_VERSION=1.18.2
GOLANG_VERSION=1.19
GO111MODULE=on
12 changes: 12 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
- HOMEBREW_NAME=go-musicfox
builds:
- id: go-musicfox-linux-amd64
main: ./cmd/musicfox
binary: musicfox
hooks:
pre:
Expand All @@ -16,6 +17,8 @@ builds:
- amd64
goos:
- linux
ldflags:
- -s -w -X constants.AppVersion={{.Version}}
# - id: go-musicfox-linux-arm64
# binary: musicfox
# hooks:
Expand All @@ -30,29 +33,38 @@ builds:
# - CC=aarch64-linux-gnu-gcc
# - CXX=aarch64-linux-gnu-g++
- id: go-musicfox-windows-amd64
main: ./cmd/musicfox
binary: musicfox
goarch:
- amd64
goos:
- windows
ldflags:
- -s -w -X constants.AppVersion={{.Version}}
env:
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
- id: go-musicfox-darwin-arm64
main: ./cmd/musicfox
binary: musicfox
goarch:
- arm64
goos:
- darwin
ldflags:
- -s -w -X constants.AppVersion={{.Version}}
env:
- CC=oa64-clang
- CXX=oa64-clang++
- id: go-musicfox-darwin-amd64
main: ./cmd/musicfox
binary: musicfox
goarch:
- amd64
goos:
- darwin
ldflags:
- -s -w -X constants.AppVersion={{.Version}}
env:
- CC=o64-clang
- CXX=o64-clang++
Expand Down
2 changes: 1 addition & 1 deletion cmd/musicfox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"github.com/gookit/gcli/v2"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/pkg/commands"
"go-musicfox/pkg/constants"
"go-musicfox/pkg/ui"
"go-musicfox/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion configs/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package configs

import (
"github.com/gookit/ini/v2"
"go-musicfox/constants"
"go-musicfox/pkg/constants"
"time"
)

Expand Down
5 changes: 3 additions & 2 deletions constants/constants.go → pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"time"
)

// AppVersion Inject by -ldflags
var AppVersion = "2.2.1"

const AppName = "musicfox"
const AppVersion = "2.2.1"
const AppVersionInt = 20201
const AppDescription = "<cyan>Musicfox - 命令行版网易云音乐</>"
const AppShowStartup = true
const AppGithubUrl = "https://github.com/anhoder/go-musicfox"
Expand Down
18 changes: 10 additions & 8 deletions utils/player.go → pkg/player/player.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package utils
package player

import (
"fmt"
"go-musicfox/utils"
"io"
"net/http"
"os"
"time"

"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/flac"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/vorbis"
"github.com/faiface/beep/wav"
"io"
"net/http"
"os"
"time"
)

// State 播放器状态
Expand Down Expand Up @@ -46,7 +48,7 @@ type Player struct {
CurMusic UrlMusic
ctrl *beep.Ctrl
volume *effects.Volume
Timer *Timer
Timer *utils.Timer
timeChan chan time.Duration
done chan struct{}

Expand Down Expand Up @@ -87,7 +89,7 @@ func (p *Player) listen() {
cacheRFile, cacheWFile *os.File
)

cacheFile := fmt.Sprintf("%s/music_cache", GetLocalDataDir())
cacheFile := fmt.Sprintf("%s/music_cache", utils.GetLocalDataDir())

for {
select {
Expand Down Expand Up @@ -179,7 +181,7 @@ func (p *Player) listen() {
speaker.Play(p.volume)

// 启动计时器
p.Timer = New(Options{
p.Timer = utils.New(utils.Options{
Duration: 24 * time.Hour,
TickerInternal: 200 * time.Millisecond,
OnRun: func(started bool) {},
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/last_signin_date.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package storage

import "go-musicfox/constants"
import (
"go-musicfox/pkg/constants"
)

type LastSignIn struct {}

Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/play_mode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package storage

import "go-musicfox/constants"
import (
"go-musicfox/pkg/constants"
)

type PlayMode struct {}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/player_snapshot.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package storage

import (
"go-musicfox/constants"
"go-musicfox/pkg/constants"
"go-musicfox/pkg/structs"
)

Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package storage

import "go-musicfox/constants"
import (
"go-musicfox/pkg/constants"
)

type User struct {}

Expand Down
20 changes: 10 additions & 10 deletions pkg/ui/main_ui.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package ui

import (
"fmt"
tea "github.com/anhoder/bubbletea"
"github.com/mattn/go-runewidth"
"github.com/muesli/termenv"
"fmt"
tea "github.com/anhoder/bubbletea"
"github.com/mattn/go-runewidth"
"github.com/muesli/termenv"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/utils"
"math"
"strings"
"time"
"unicode/utf8"
"go-musicfox/pkg/constants"
"go-musicfox/utils"
"math"
"strings"
"time"
"unicode/utf8"
)

// ModelType 显示模型的类型
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/menu_check_update.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ui

import (
"go-musicfox/constants"
"go-musicfox/utils"
"go-musicfox/pkg/constants"
"go-musicfox/utils"
)

type CheckUpdateMenu struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/menu_help.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ui

import (
"go-musicfox/constants"
"go-musicfox/utils"
"go-musicfox/pkg/constants"
"go-musicfox/utils"
)

type HelpMenu struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ui/netease.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/mattn/go-runewidth"
"github.com/telanflow/cookiejar"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/pkg/structs"
"go-musicfox/pkg/constants"
db2 "go-musicfox/pkg/storage"
"go-musicfox/pkg/structs"
"go-musicfox/utils"
"strconv"
"time"
Expand Down
15 changes: 8 additions & 7 deletions pkg/ui/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"github.com/anhoder/netease-music/service"
"github.com/muesli/termenv"
"go-musicfox/constants"
"go-musicfox/pkg/structs"
"go-musicfox/pkg/constants"
"go-musicfox/pkg/player"
db2 "go-musicfox/pkg/storage"
"go-musicfox/pkg/structs"
"go-musicfox/utils"
"math"
"strconv"
Expand Down Expand Up @@ -285,11 +286,11 @@ func spaceKeyHandle(m *NeteaseModel) {
}

switch m.player.State {
case utils.Paused:
case player.Paused:
m.player.Resume()
case utils.Playing:
case player.Playing:
m.player.Paused()
case utils.Stopped:
case player.Stopped:
_ = m.player.PlaySong(m.player.playlist[m.player.curSongIndex], DurationNext)
}

Expand All @@ -298,9 +299,9 @@ func spaceKeyHandle(m *NeteaseModel) {

if inPlayingMenu && songs[selectedIndex].Id == m.player.playlist[m.player.curSongIndex].Id {
switch m.player.State {
case utils.Paused:
case player.Paused:
m.player.Resume()
case utils.Playing:
case player.Playing:
m.player.Paused()
}
} else {
Expand Down
17 changes: 9 additions & 8 deletions pkg/ui/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"github.com/mattn/go-runewidth"
"github.com/muesli/termenv"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/pkg/structs"
"go-musicfox/pkg/constants"
lyric2 "go-musicfox/pkg/lyric"
"go-musicfox/pkg/player"
db2 "go-musicfox/pkg/storage"
"go-musicfox/pkg/structs"
"go-musicfox/utils"
"math"
"math/rand"
Expand Down Expand Up @@ -61,14 +62,14 @@ type Player struct {
playErrCount int // 错误计数,当错误连续超过5次,停止播放
mode PlayMode

*utils.Player // 播放器
*player.Player // 播放器
}

func NewPlayer(model *NeteaseModel) *Player {
player := &Player{
model: model,
mode: PmListLoop,
Player: utils.NewPlayer(),
Player: player.NewPlayer(),
}

// done监听
Expand Down Expand Up @@ -182,7 +183,7 @@ func (p *Player) songView() string {
builder.WriteString(strings.Repeat(" ", p.model.menuStartColumn-4))
builder.WriteString(SetFgStyle(fmt.Sprintf("[%s] ", p.mode), termenv.ANSIBrightMagenta))
}
if p.State == utils.Playing {
if p.State == player.Playing {
builder.WriteString(SetFgStyle("♫ ♪ ♫ ♪ ", termenv.ANSIBrightYellow))
} else {
builder.WriteString(SetFgStyle("_ _ z Z Z ", termenv.ANSIBrightRed))
Expand Down Expand Up @@ -327,7 +328,7 @@ func (p *Player) PlaySong(song structs.Song, duration PlayDirection) error {
musicType, err2 := jsonparser.GetString(response, "data", "[0]", "type")
musicType = strings.ToLower(musicType)
if err1 != nil || err2 != nil || (musicType != "mp3" && musicType != "flac") {
p.State = utils.Stopped
p.State = player.Stopped
p.progressRamp = []string{}
p.playErrCount++
if p.playErrCount >= 3 {
Expand All @@ -348,9 +349,9 @@ func (p *Player) PlaySong(song structs.Song, duration PlayDirection) error {

switch musicType {
case "mp3":
p.Player.Play(utils.Mp3, url, song.Duration)
p.Player.Play(player.Mp3, url, song.Duration)
case "flac":
p.Player.Play(utils.Flac, url, song.Duration)
p.Player.Play(player.Flac, url, song.Duration)
}

var artistNames []string
Expand Down
20 changes: 10 additions & 10 deletions pkg/ui/startup.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package ui

import (
"fmt"
tea "github.com/anhoder/bubbletea"
"github.com/fogleman/ease"
"github.com/muesli/termenv"
"fmt"
tea "github.com/anhoder/bubbletea"
"github.com/fogleman/ease"
"github.com/muesli/termenv"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/utils"
"math"
"strings"
"time"
"unicode/utf8"
"go-musicfox/pkg/constants"
"go-musicfox/utils"
"math"
"strings"
"time"
"unicode/utf8"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/ui_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/lucasb-eyer/go-colorful"
"github.com/muesli/termenv"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/pkg/constants"
ds2 "go-musicfox/pkg/structs"
"go-musicfox/utils"
"math/rand"
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"go-musicfox/pkg/constants"
"io"
"net/http"
"os"
Expand All @@ -16,7 +17,6 @@ import (

"github.com/buger/jsonparser"
"go-musicfox/configs"
"go-musicfox/constants"
ds2 "go-musicfox/pkg/structs"
)

Expand Down

0 comments on commit f31178f

Please sign in to comment.