Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
anhoder committed Sep 5, 2022
1 parent 7d74f6e commit 31d840a
Show file tree
Hide file tree
Showing 75 changed files with 380 additions and 396 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ go-musicfox是 [musicfox](https://github.com/anhoder/musicfox) 的重写版,

## 预览

![欢迎界面](preview/img.png)
![主界面1](preview/img1.png)
![主界面2](preview/img2.png)
![欢迎界面](examples/img.png)
![主界面1](examples/img1.png)
![主界面2](examples/img2.png)

## 安装

Expand Down
10 changes: 5 additions & 5 deletions main.go → cmd/musicfox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"fmt"
"github.com/gookit/gcli/v2"
"go-musicfox/commands"
"go-musicfox/config"
"go-musicfox/configs"
"go-musicfox/constants"
"go-musicfox/ui"
"go-musicfox/pkg/commands"
"go-musicfox/pkg/ui"
"go-musicfox/utils"
)

Expand All @@ -17,7 +17,7 @@ func main() {
app.Description = constants.AppDescription

// 加载config
config.ConfigRegistry = utils.LoadIniConfig()
configs.ConfigRegistry = utils.LoadIniConfig()

logo := utils.GetAlphaAscii(app.Name)
randomColor := ui.GetPrimaryColor()
Expand All @@ -31,4 +31,4 @@ func main() {
app.DefaultCommand(playerCommand.Name)

app.Run()
}
}
6 changes: 4 additions & 2 deletions go-musicfox.ini → configs/go-musicfox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ loadingText=[加载中...]
# 歌曲码率,128000, 320000...,视网络情况而定
songBr=320000
# 主题颜色
# primaryColor=random # 随机
primaryColor=#f90022 # 经典网易云音乐红
# 随机
# primaryColor=random
# 经典网易云音乐红
primaryColor=#f90022
# 是否显示歌词
showLyric=true
# 是否显示通知信息
Expand Down
2 changes: 1 addition & 1 deletion config/registry.go → configs/registry.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package configs

import (
"github.com/gookit/ini/v2"
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
20 changes: 7 additions & 13 deletions commands/netease.go → pkg/commands/netease.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@ package commands
import (
tea "github.com/anhoder/bubbletea"
"github.com/gookit/gcli/v2"
"go-musicfox/config"
"go-musicfox/ui"
"go-musicfox/configs"
"go-musicfox/pkg/ui"
)

func NewPlayerCommand() *gcli.Command {

return &gcli.Command{
Name: "netease",
// allow color tag and {$cmd} will be replace to 'demo'
UseFor: "Command line player for Netease Cloud Music",
Func: runPlayer,
Func: runPlayer,
}
}

func runPlayer(cmd *gcli.Command, args []string) error {
neteaseModel := ui.NewNeteaseModel(config.ConfigRegistry.StartupLoadingDuration)
func runPlayer(_ *gcli.Command, _ []string) error {
neteaseModel := ui.NewNeteaseModel(configs.ConfigRegistry.StartupLoadingDuration)
program := tea.NewProgram(neteaseModel)
neteaseModel.BindProgram(program)
program.EnterAltScreen()
defer program.ExitAltScreen()
if err := program.Start(); err != nil {
return err
}

return nil
}
return program.Start()
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions db/ky_model.go → pkg/storage/ky_model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package db
package storage

type KVModel interface {
Model
GetKey() string
}
}
4 changes: 2 additions & 2 deletions db/last_signin_date.go → pkg/storage/last_signin_date.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package storage

import "go-musicfox/constants"

Expand All @@ -14,4 +14,4 @@ func (p LastSignIn) GetTableName() string {

func (p LastSignIn) GetKey() string {
return "last_sign_in"
}
}
4 changes: 2 additions & 2 deletions db/local_db.go → pkg/storage/local_db.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package storage

import (
"errors"
Expand Down Expand Up @@ -71,4 +71,4 @@ func (dm *LocalDBManager) GetDBFromCache(db interface{}) (localDB *LocalDB, err
}

return localDB, nil
}
}
4 changes: 2 additions & 2 deletions db/model.go → pkg/storage/model.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package storage

type Model interface {
GetDbName() string
Expand All @@ -8,4 +8,4 @@ type Model interface {
// IDSetter set id
type IDSetter interface {
SetID(ID uint64)
}
}
4 changes: 2 additions & 2 deletions db/play_mode.go → pkg/storage/play_mode.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package storage

import "go-musicfox/constants"

Expand All @@ -14,4 +14,4 @@ func (p PlayMode) GetTableName() string {

func (p PlayMode) GetKey() string {
return "play_mode"
}
}
8 changes: 4 additions & 4 deletions db/player_snapshot.go → pkg/storage/player_snapshot.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package db
package storage

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

type PlayerSnapshot struct {
CurSongIndex int `json:"cur_song_index"`
Playlist []ds.Song `json:"playlist"`
CurSongIndex int `json:"cur_song_index"`
Playlist []structs.Song `json:"playlist"`
//PlayingMenuKey string `json:"playing_menu_key"`
}

Expand Down
18 changes: 3 additions & 15 deletions db/table.go → pkg/storage/table.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package storage

import (
"encoding/json"
Expand Down Expand Up @@ -32,16 +32,10 @@ func (table *table) AllMap(model Model, callback IteratorCallback) (err error) {
}

err = bucket.ForEach(func(k, v []byte) error {
if err = callback(k, v); err != nil {
return err
}

return nil
return callback(k, v)
})

return
})

return
}

Expand Down Expand Up @@ -74,11 +68,7 @@ func (table *table) IncrAdd(model Model, data IDSetter) (id uint64, err error) {
return bucket.Put(utils.IDToBin(id), buf)
})

if err != nil {
return
}

return id, nil
return id, err
}

// Set edit one line
Expand Down Expand Up @@ -164,7 +154,6 @@ func (table *table) Get(model Model, key []byte) (value []byte, err error) {
value = bucket.Get(key)
return nil
})

return
}

Expand All @@ -182,7 +171,6 @@ func checkBucket(bucket *bolt.Bucket, bucketName string) error {
if bucket == nil {
return errors.New(fmt.Sprintf("Bucket(%s) not exists!", bucketName))
}

return nil
}

4 changes: 2 additions & 2 deletions db/user.go → pkg/storage/user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package storage

import "go-musicfox/constants"

Expand All @@ -14,4 +14,4 @@ func (u User) GetTableName() string {

func (u User) GetKey() string {
return "cur_user"
}
}
4 changes: 2 additions & 2 deletions ds/album.go → pkg/structs/album.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down Expand Up @@ -67,4 +67,4 @@ func NewAlbumFromAlbumJson(json []byte) (Album, error) {
}, "artists")

return album, nil
}
}
4 changes: 2 additions & 2 deletions ds/artist.go → pkg/structs/artist.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down Expand Up @@ -28,4 +28,4 @@ func NewArtist(json []byte) (Artist, error) {
}

return artist, nil
}
}
4 changes: 2 additions & 2 deletions ds/dj_category.go → pkg/structs/dj_category.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down Expand Up @@ -29,4 +29,4 @@ func NewDjCategoryFromJson(json []byte) (DjCategory, error) {
}

return category, nil
}
}
4 changes: 2 additions & 2 deletions ds/dj_radio.go → pkg/structs/dj_radio.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down Expand Up @@ -46,4 +46,4 @@ func NewDjRadioFromJson(json []byte) (DjRadio, error) {
}

return radio, nil
}
}
2 changes: 1 addition & 1 deletion ds/playlist.go → pkg/structs/playlist.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down
4 changes: 2 additions & 2 deletions ds/rank.go → pkg/structs/rank.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"encoding/json"
Expand All @@ -24,4 +24,4 @@ func NewRankFromJson(jsonBytes []byte) (Rank, error) {
}

return rank, nil
}
}
4 changes: 2 additions & 2 deletions ds/song.go → pkg/structs/song.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down Expand Up @@ -302,4 +302,4 @@ func NewSongFromDjRankProgramJson(json []byte) (Song, error) {
}, "program", "mainSong", "artists")

return song, nil
}
}
4 changes: 2 additions & 2 deletions ds/user.go → pkg/structs/user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ds
package structs

import (
"errors"
Expand Down Expand Up @@ -89,4 +89,4 @@ func NewUserFromSearchResultJson(json []byte) (User, error) {
}

return user, nil
}
}
File renamed without changes.
8 changes: 4 additions & 4 deletions ui/loading.go → pkg/ui/loading.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ui
import (
"fmt"
"github.com/muesli/termenv"
"go-musicfox/config"
"go-musicfox/configs"
"strings"
"unicode/utf8"
)
Expand All @@ -23,7 +23,7 @@ func NewLoading(m *NeteaseModel) *Loading {
func (loading *Loading)start() {
termenv.MoveCursor(loading.model.menuTitleStartRow, 0)

loading.curLen = utf8.RuneCountInString(loading.model.menuTitle) + utf8.RuneCountInString(" " + config.ConfigRegistry.MainLoadingText)
loading.curLen = utf8.RuneCountInString(loading.model.menuTitle) + utf8.RuneCountInString(" " + configs.ConfigRegistry.MainLoadingText)

var repeatSpace string
if loading.model.menuTitleStartColumn > 0 {
Expand All @@ -32,7 +32,7 @@ func (loading *Loading)start() {
fmt.Printf("%s%s%s",
repeatSpace,
SetFgStyle(loading.model.menuTitle, termenv.ANSIBrightGreen),
SetFgStyle(" " + config.ConfigRegistry.MainLoadingText, termenv.ANSIBrightBlack))
SetFgStyle(" " + configs.ConfigRegistry.MainLoadingText, termenv.ANSIBrightBlack))

termenv.MoveCursor(0, 0)
}
Expand All @@ -57,4 +57,4 @@ func (loading *Loading)complete() {
strings.Repeat(" ", spaceLen))

termenv.MoveCursor(0, 0)
}
}
Loading

0 comments on commit 31d840a

Please sign in to comment.