Skip to content

Commit

Permalink
[feature]<main>: main features for 0.0.1 (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: o98k-ok <hggend@gmail.com>
  • Loading branch information
o98k-ok authored Mar 11, 2024
1 parent a9c08be commit c8b6502
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 64 deletions.
45 changes: 35 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# VOICE
<img src="./data/voice.png" width="100"><br>
<img src="./assets/voice.png" width="100"><br>


[![build](https://github.com/o98k-ok/voice/actions/workflows/go.yml/badge.svg)](https://github.com/o98k-ok/voice/actions/workflows/go.yml)
Expand All @@ -10,18 +10,43 @@

## Running screenshot

![sample](./data/screenshot.jpg)
### 当前播放

## Supported features
![](./assets/Pasted%20image%2020240311154007.png)

支持的功能:
1. 歌曲基本信息
2. 音乐播放进度
3. 播放切换/暂停播放

### 歌曲搜索

![](./assets/Pasted%20image%2020240311154233.png)

支持的功能:
1. B站音频搜索
2. 搜索列表展示、切换
3. 歌曲快速播放

1. 不错的终端界面
2. 音乐播放器
3. B站音频实时搜索
4. 本地音频载入
### 播放列表

![](./assets/Pasted%20image%2020240311154510.png)

1. 播放列表信息展示
2. 列表切换
3. 播放音乐切换

## Supported features

1. 终端界面
2. 命令行快捷操作
3. 音乐播放器
4. B站音频实时搜索
5. 本地音频载入

## Follow-up plan

1. 完善功能
2. 完善功能
3. 完善功能
1. 收藏功能
2. 音频下载
3. 每日推荐
4. .......
Binary file added assets/Pasted image 20240311154007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pasted image 20240311154233.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Pasted image 20240311154510.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/voice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 11 additions & 11 deletions cmd/terminal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ func main() {
player.InitPlayList(localIndex)
player.Run()

inputElem := ui.NewInputElem([]string{"ID", "标题", "时长", "BVID", "描述"}, []int{6, 30, 6, 12, 0}, localIndex)
inputElem := ui.NewInputElem(player, localIndex,
[]string{"ID", "标题", "时长", "BVID", "描述"},
[]int{6, 30, 6, 12, 0},
)
processBar := ui.NewProcessLineElem(player)
historyList := ui.NewHistoryList([]string{"标题", "描述", "时长", "BVID"}, []int{40, 60, 12, 0}, player)
historyList := ui.NewHistoryList(player,
[]string{"标题", "描述", "时长", "BVID"},
[]int{40, 60, 12, 0},
)

elems := []ui.Element{inputElem, historyList, processBar}
menu := ui.NewMenuElem([]string{"搜索", "列表", "当前"}, elems)
elems := []ui.Element{processBar, inputElem, historyList}
menu := ui.NewMenuElem([]string{"🤓 当前", "😂 搜索", "😳 列表"}, elems)
framework := ui.NewFramework(menu, elems)
go func() {
channel := inputElem.RegisterPlayer()
for {
msic := <-channel
player.DryPlay(&msic)
}
}()

program := tea.NewProgram(framework)
fmt.Println(program.Run())
}
2 changes: 1 addition & 1 deletion internal/convertor/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (ac *AfconvertConvertor) ConvertM4AToWav(reader io.Reader, writer io.Writer
}()
defer os.Remove(dstname)

c := fmt.Sprintf("afconvert %s -f WAVE -d UI8 %s", src.Name(), dstname)
c := fmt.Sprintf("afconvert %s -f WAVE -d LEI24 %s", src.Name(), dstname)
if _, _, err := system.ExecCommand(c); err != nil {
return err
}
Expand Down
104 changes: 81 additions & 23 deletions internal/ui/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package ui

import (
"container/list"
"math"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/duke-git/lancet/v2/strutil"
"github.com/o98k-ok/voice/internal/music"
"github.com/o98k-ok/voice/internal/pkg"
"github.com/o98k-ok/voice/internal/player"
Expand All @@ -14,12 +17,17 @@ type HistoryList struct {
player *player.VoicePlayer
active bool
current int

page int
limit int
}

func NewHistoryList(headers []string, widths []int, player *player.VoicePlayer) *HistoryList {
func NewHistoryList(player *player.VoicePlayer, headers []string, widths []int) *HistoryList {
return &HistoryList{
list: NewListElem(headers, widths, nil),
player: player,
page: 1,
limit: 10,
}
}

Expand All @@ -28,49 +36,69 @@ func (hl *HistoryList) Init() tea.Cmd {
}

func (hl *HistoryList) View() string {
return hl.list.View()
help := "enter play • ↓/j move down • ↑/k move up\n ← page left • → page right • tab next menu"
return lipgloss.JoinVertical(lipgloss.Center, hl.list.View(), "\n", help)
}

func (hl *HistoryList) fechList() [][]string {
if hl.player.CurrentElem == nil {
return nil
}

func (hl *HistoryList) fechByBvID(bvID string, limit int) [][]string {
var page int = 1
var values [][]string
p := hl.player.CurrentElem
hl.current = 0
for i := 0; i < 3; i++ {
if p.Prev() == nil {
break
for p := hl.player.PlayList.Front(); p != nil; p = p.Next() {
values = [][]string{}
var got bool
for i := 0; i < limit; i++ {
if p == nil {
break
}
m := p.Value.(*music.Music)
if m.BvID == bvID {
got = true
hl.current = i
hl.page = page
}
values = append(values, []string{m.Name, m.Desc, m.Duration, m.BvID})
p = p.Next()
}
p = p.Prev()
hl.current += 1
}

for i := 0; i < 10; i++ {
if p == nil {
if got {
break
}
page += 1
}
return values
}

m := p.Value.(*music.Music)
if m != nil {
func (hl *HistoryList) fechList(off, limit int) [][]string {
var page int = 1
var values [][]string
for p := hl.player.PlayList.Front(); p != nil; p = p.Next() {
values = [][]string{}
for i := 0; i < limit; i++ {
if p == nil {
break
}
m := p.Value.(*music.Music)
values = append(values, []string{m.Name, m.Desc, m.Duration, m.BvID})
p = p.Next()
}
if page == off {
break
}
p = p.Next()
page++
}
hl.current = len(values) / 2
return values
}

func (hl *HistoryList) MsgKeyBindings() map[string]map[string]func(interface{}) tea.Cmd {
return map[string]map[string]func(interface{}) tea.Cmd{
"tea.KeyMsg": {
ALLMsgKey: func(v interface{}) tea.Cmd {
if !hl.active {
if !hl.active || strutil.ContainsAny(v.(tea.KeyMsg).String(), []string{" ", "left", "right"}) {
return nil
}
hl.list.table.Focus()

hl.list.ResetList(hl.fechList())
hl.list.ResetList(hl.fechByBvID(hl.player.CurrentElem.Value.(*music.Music).BvID, 10))
var cmd tea.Cmd
hl.list.table, cmd = hl.list.table.Update(v)
return cmd
Expand Down Expand Up @@ -100,6 +128,36 @@ func (hl *HistoryList) MsgKeyBindings() map[string]map[string]func(interface{})
hl.player.NextP(p)
return nil
},
" ": func(i interface{}) tea.Cmd {
if !hl.active {
return nil
}
hl.player.Pause()
return nil
},
"right": func(i interface{}) tea.Cmd {
size := math.Ceil(float64(hl.player.PlayList.Len()) / float64(hl.limit))

if hl.page < int(size) {
hl.page += 1
}

hl.list.ResetList(hl.fechList(hl.page, hl.limit))
hl.list.table.SetCursor(hl.current)
var cmd tea.Cmd
hl.list.table, cmd = hl.list.table.Update(i)
return cmd
},
"left": func(i interface{}) tea.Cmd {
if hl.page > 1 {
hl.page -= 1
}
hl.list.ResetList(hl.fechList(hl.page, hl.limit))
hl.list.table.SetCursor(hl.current)
var cmd tea.Cmd
hl.list.table, cmd = hl.list.table.Update(i)
return cmd
},
},
}
}
Expand Down
37 changes: 18 additions & 19 deletions internal/ui/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/o98k-ok/voice/internal/convertor"
"github.com/o98k-ok/voice/internal/music"
"github.com/o98k-ok/voice/internal/pkg"
"github.com/o98k-ok/voice/internal/player"
"github.com/o98k-ok/voice/internal/storage"
)

Expand All @@ -24,13 +25,13 @@ type InputElem struct {
fetcher bilibili.Fetcher
mconvertor convertor.Convertor

playChannel chan music.Music
fetcherIdx int
active bool
storage storage.Storage
fetcherIdx int
active bool
storage storage.Storage
player *player.VoicePlayer
}

func NewInputElem(headers []string, widths []int, storage storage.Storage) *InputElem {
func NewInputElem(player *player.VoicePlayer, storage storage.Storage, headers []string, widths []int) *InputElem {
elem := textinput.New()
elem.Focus()
elem.Prompt = "> "
Expand All @@ -44,17 +45,13 @@ func NewInputElem(headers []string, widths []int, storage storage.Storage) *Inpu
mconvertor: convertor.NewAfconvertConvertor("./data"),
fetcherIdx: 1,
storage: storage,
player: player,
}
}

func (ie *InputElem) Active() bool { return ie.active }
func (ie *InputElem) SetActive(active bool) { ie.active = active }

func (ie *InputElem) RegisterPlayer() chan music.Music {
ie.playChannel = make(chan music.Music, 10)
return ie.playChannel
}

func (ie *InputElem) Init() tea.Cmd {
return textinput.Blink
}
Expand Down Expand Up @@ -119,6 +116,8 @@ func (ie *InputElem) MsgKeyBindings() map[string]map[string]func(v interface{})
case val.String() == "s":
ie.result.table.Blur()
ie.textInput.Focus()
case val.String() == " ":
ie.player.Pause()
default:
ie.result.table, cmd = ie.result.table.Update(v)
}
Expand Down Expand Up @@ -192,16 +191,16 @@ func (ie *InputElem) MsgKeyBindings() map[string]map[string]func(v interface{})
LocalPath: nameout,
Duration: msic[2],
})
if ie.playChannel != nil {
ie.playChannel <- music.Music{
Name: msic[1],
Desc: msic[4],
URL: url,
BvID: bvID,
LocalPath: nameout,
Duration: msic[2],
}

mm := music.Music{
Name: msic[1],
Desc: msic[4],
URL: url,
BvID: bvID,
LocalPath: nameout,
Duration: msic[2],
}
ie.player.DryPlay(&mm)
}(bvid, u, i)
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (pe *ProceeLineElem) MsgKeyBindings() map[string]map[string]func(interface{
return nil
},
"p": func(interface{}) tea.Cmd {
if pe.active {
p := pkg.NextN(pe.player.PlayList, pe.player.CurrentElem, -2)
pe.player.NextP(p)
}
return nil
},
},
Expand Down

0 comments on commit c8b6502

Please sign in to comment.