commit
c95f194a90
@ -111,27 +111,31 @@ func PrintArtistTree(a map[string]map[string]map[string]string) {
|
|||||||
|
|
||||||
// Adds All tracks from a specified album to a playlist
|
// Adds All tracks from a specified album to a playlist
|
||||||
func AddAlbum(a map[string]map[string]map[string]string, alb string, artist string) {
|
func AddAlbum(a map[string]map[string]map[string]string, alb string, artist string) {
|
||||||
|
clist := Conn.BeginCommandList()
|
||||||
for _, v := range a[artist][alb] {
|
for _, v := range a[artist][alb] {
|
||||||
err := Conn.Add(v)
|
clist.Add(v)
|
||||||
if err != nil {
|
|
||||||
notify.Notify.Send("Could Not Add Song : " + v)
|
|
||||||
}
|
}
|
||||||
|
if err := clist.End(); err != nil {
|
||||||
|
notify.Notify.Send("Could Not Add Album : " + alb)
|
||||||
|
} else {
|
||||||
|
notify.Notify.Send("Album Added: " + alb)
|
||||||
}
|
}
|
||||||
notify.Notify.Send("Album Added : " + alb)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds All tracks from a specified artist to a playlist
|
// Adds All tracks from a specified artist to a playlist
|
||||||
func AddArtist(a map[string]map[string]map[string]string, artist string) {
|
func AddArtist(a map[string]map[string]map[string]string, artist string) {
|
||||||
|
clist := Conn.BeginCommandList()
|
||||||
if val, ok := a[artist]; ok {
|
if val, ok := a[artist]; ok {
|
||||||
for _, v := range val {
|
for _, v := range val {
|
||||||
for _, path := range v {
|
for _, path := range v {
|
||||||
err := Conn.Add(path)
|
clist.Add(path)
|
||||||
if err != nil {
|
|
||||||
notify.Notify.Send("Could Not Add Song : " + path)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := clist.End(); err != nil {
|
||||||
|
notify.Notify.Send("Could Not Add Artist : " + artist)
|
||||||
|
} else {
|
||||||
|
notify.Notify.Send("Artist Added: " + artist)
|
||||||
}
|
}
|
||||||
notify.Notify.Send("Artist Added : " + artist)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
main.go
25
main.go
@ -22,16 +22,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
config.ReadConfig()
|
config.ReadConfig()
|
||||||
var mpdConnectionError error
|
var mpdConnectionError error
|
||||||
del := ""
|
client.Conn, mpdConnectionError = mpd.Dial(utils.GetNetwork())
|
||||||
nt := viper.GetString("NETWORK_TYPE")
|
|
||||||
port := viper.GetString("MPD_PORT")
|
|
||||||
if nt == "tcp" {
|
|
||||||
del = ":"
|
|
||||||
} else if nt == "unix" && port != "" {
|
|
||||||
port = ""
|
|
||||||
}
|
|
||||||
client.Conn, mpdConnectionError = mpd.Dial(nt,
|
|
||||||
viper.GetString("NETWORK_ADDRESS")+del+port)
|
|
||||||
if mpdConnectionError != nil {
|
if mpdConnectionError != nil {
|
||||||
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
||||||
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
||||||
@ -60,9 +51,6 @@ func main() {
|
|||||||
// Generating the Directory Tree for File Navigation.
|
// Generating the Directory Tree for File Navigation.
|
||||||
client.DirTree = client.GenerateDirectoryTree(fileMap)
|
client.DirTree = client.GenerateDirectoryTree(fileMap)
|
||||||
|
|
||||||
// Default View upon Opening is of Playlist.
|
|
||||||
views.PView.Update(ui.Ui.ExpandedView)
|
|
||||||
|
|
||||||
var Volume int64
|
var Volume int64
|
||||||
var Random, Repeat bool
|
var Random, Repeat bool
|
||||||
var SeekOffset = viper.GetInt("SEEK_OFFSET")
|
var SeekOffset = viper.GetInt("SEEK_OFFSET")
|
||||||
@ -120,7 +108,8 @@ func main() {
|
|||||||
|
|
||||||
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
||||||
// the Draw Function
|
// the Draw Function
|
||||||
views.SetCurrentView(views.PView)
|
views.PView.StartWatcher()
|
||||||
|
views.SetCurrentView(&views.PView)
|
||||||
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||||
views.GetCurrentView().Update(ui.Ui.ExpandedView)
|
views.GetCurrentView().Update(ui.Ui.ExpandedView)
|
||||||
return ui.Ui.ExpandedView.GetInnerRect()
|
return ui.Ui.ExpandedView.GetInnerRect()
|
||||||
@ -150,7 +139,11 @@ func main() {
|
|||||||
if err := Conn.Clear(); err != nil {
|
if err := Conn.Clear(); err != nil {
|
||||||
notify.Notify.Send("Could not Clear the Playlist")
|
notify.Notify.Send("Could not Clear the Playlist")
|
||||||
} else {
|
} else {
|
||||||
notify.Notify.Send("Playlist Cleared")
|
if views.PView.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
||||||
|
utils.Print("RED", "Couldn't get the current Playlist.\n")
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
notify.Notify.Send("Playlist Cleared!")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"previousSong": func() {
|
"previousSong": func() {
|
||||||
@ -197,7 +190,7 @@ func main() {
|
|||||||
views.FView.Update(ui.Ui.ExpandedView)
|
views.FView.Update(ui.Ui.ExpandedView)
|
||||||
},
|
},
|
||||||
"navigateToPlaylist": func() {
|
"navigateToPlaylist": func() {
|
||||||
views.SetCurrentView(views.PView)
|
views.SetCurrentView(&views.PView)
|
||||||
ui.Ui.Navbar.Select(0, 0)
|
ui.Ui.Navbar.Select(0, 0)
|
||||||
views.PView.Update(ui.Ui.ExpandedView)
|
views.PView.Update(ui.Ui.ExpandedView)
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type winsize struct {
|
type winsize struct {
|
||||||
@ -174,3 +176,15 @@ func Unique(intSlice []int) []int {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetNetwork() (string, string) {
|
||||||
|
del := ""
|
||||||
|
nt := viper.GetString("NETWORK_TYPE")
|
||||||
|
port := viper.GetString("MPD_PORT")
|
||||||
|
if nt == "tcp" {
|
||||||
|
del = ":"
|
||||||
|
} else if nt == "unix" && port != "" {
|
||||||
|
port = ""
|
||||||
|
}
|
||||||
|
return nt, viper.GetString("NETWORK_ADDRESS") + del + port
|
||||||
|
}
|
||||||
|
@ -6,10 +6,12 @@ import (
|
|||||||
"github.com/aditya-K2/gomp/ui"
|
"github.com/aditya-K2/gomp/ui"
|
||||||
"github.com/aditya-K2/gomp/utils"
|
"github.com/aditya-K2/gomp/utils"
|
||||||
"github.com/aditya-K2/tview"
|
"github.com/aditya-K2/tview"
|
||||||
|
"github.com/fhs/gompd/v2/mpd"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlaylistView struct {
|
type PlaylistView struct {
|
||||||
|
Playlist []mpd.Attrs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PlaylistView) GetViewName() string {
|
func (s PlaylistView) GetViewName() string {
|
||||||
@ -47,21 +49,24 @@ func (p PlaylistView) Quit() {
|
|||||||
|
|
||||||
func (p PlaylistView) FocusBuffSearchView() {}
|
func (p PlaylistView) FocusBuffSearchView() {}
|
||||||
|
|
||||||
func (p PlaylistView) DeleteSongFromPlaylist() {
|
func (p *PlaylistView) DeleteSongFromPlaylist() {
|
||||||
UI := ui.Ui
|
UI := ui.Ui
|
||||||
CONN := client.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
if err := CONN.Delete(r, -1); err != nil {
|
if err := CONN.Delete(r, -1); err != nil {
|
||||||
notify.Notify.Send("Could not Remove the Song from Playlist")
|
notify.Notify.Send("Could not Remove the Song from Playlist")
|
||||||
|
} else {
|
||||||
|
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
||||||
|
utils.Print("RED", "Couldn't get the current Playlist.\n")
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PlaylistView) Update(inputTable *tview.Table) {
|
func (p PlaylistView) Update(inputTable *tview.Table) {
|
||||||
CONN := client.Conn
|
|
||||||
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
|
||||||
|
|
||||||
inputTable.Clear()
|
inputTable.Clear()
|
||||||
for i, j := range _playlistAttr {
|
for i, j := range p.Playlist {
|
||||||
_, _, w, _ := inputTable.GetInnerRect()
|
_, _, w, _ := inputTable.GetInnerRect()
|
||||||
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
||||||
inputTable.SetCell(i, 0,
|
inputTable.SetCell(i, 0,
|
||||||
@ -80,3 +85,38 @@ func (p PlaylistView) Update(inputTable *tview.Table) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PlaylistView) StartWatcher() {
|
||||||
|
var err error
|
||||||
|
if p.Playlist == nil {
|
||||||
|
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
||||||
|
utils.Print("RED", "Watcher couldn't get the current Playlist.\n")
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nt, addr := utils.GetNetwork()
|
||||||
|
w, err := mpd.NewWatcher(nt, addr, "", "playlist")
|
||||||
|
if err != nil {
|
||||||
|
utils.Print("RED", "Could Not Start Watcher.\n")
|
||||||
|
utils.Print("GREEN", "Please check your MPD Info in config File.\n")
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for err := range w.Error {
|
||||||
|
notify.Notify.Send(err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for subsystem := range w.Event {
|
||||||
|
if subsystem == "playlist" {
|
||||||
|
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
|
||||||
|
utils.Print("RED", "Watcher couldn't get the current Playlist.\n")
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user