Skip to content

Commit

Permalink
feat: add entire genre; show item counts in queue and genre columns
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxserxxx committed Oct 18, 2024
1 parent a53c700 commit 25aded6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 22 deletions.
4 changes: 3 additions & 1 deletion gui_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (ui *Ui) addSongToQueue(entity *subsonic.SubsonicEntity) {
TrackNumber: entity.Track,
CoverArtId: entity.CoverArtId,
DiscNumber: entity.DiscNumber,
Year: entity.Year,
}
ui.player.AddToQueue(queueItem)
}
Expand All @@ -188,6 +189,7 @@ func makeSongHandler(entity *subsonic.SubsonicEntity, ui *Ui, fallbackArtist str
track := entity.Track
coverArtId := entity.CoverArtId
disc := entity.DiscNumber
year := entity.Year

response, err := ui.connection.GetAlbum(entity.Parent)
album := ""
Expand All @@ -205,7 +207,7 @@ func makeSongHandler(entity *subsonic.SubsonicEntity, ui *Ui, fallbackArtist str
}

return func() {
if err := ui.player.PlayUri(id, uri, title, artist, album, duration, track, disc, coverArtId); err != nil {
if err := ui.player.PlayUri(id, uri, title, artist, album, duration, track, disc, coverArtId, year); err != nil {
ui.logger.PrintError("SongHandler Play", err)
return
}
Expand Down
5 changes: 2 additions & 3 deletions help_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ artist, album/genre, or song tab
Left previous column
Right next column
/ start search
a recursively add item to quue
g toggle genre search
In album tab
Enter/a recursively add item to quue
Enter recursively add item to quue
In genre tab
Enter shows songs with genre
In song tab
Enter/a adds song to queue
search field
Enter search for text
`
4 changes: 2 additions & 2 deletions mpvplayer/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (p *Player) PlayNextTrack() error {
return nil
}

func (p *Player) PlayUri(id, uri, title, artist, album string, duration, track, disc int, coverArtId string) error {
p.queue = []QueueItem{{id, uri, title, artist, duration, album, track, coverArtId, disc}}
func (p *Player) PlayUri(id, uri, title, artist, album string, duration, track, disc int, coverArtId string, year int) error {
p.queue = []QueueItem{{id, uri, title, artist, duration, album, track, coverArtId, disc, year}}
p.replaceInProgress = true
if ip, e := p.IsPaused(); ip && e == nil {
if err := p.Pause(); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions mpvplayer/queue_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type QueueItem struct {
TrackNumber int
CoverArtId string
DiscNumber int
Year int
}

var _ remote.TrackInterface = (*QueueItem)(nil)
Expand Down Expand Up @@ -60,3 +61,7 @@ func (q QueueItem) GetTrackNumber() int {
func (q QueueItem) GetDiscNumber() int {
return q.DiscNumber
}

func (q QueueItem) GetYear() int {
return q.Year
}
2 changes: 2 additions & 0 deletions page_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (q *QueuePage) updateQueue() {
q.queueList.ScrollToBeginning()
}

q.queueList.Box.SetTitle(fmt.Sprintf(" queue (%d) ", q.queueList.GetRowCount()))
r, c := q.queueList.GetSelection()
q.changeSelection(r, c)
}
Expand Down Expand Up @@ -443,6 +444,7 @@ var songInfoTemplateString = `[blue::b]Title:[-:-:-:-] [green::i]{{.Title}}[-:-:
[blue::b]Artist:[-:-:-:-] [::i]{{.Artist}}[-:-:-:-]
[blue::b]Album:[-:-:-:-] [::i]{{.GetAlbum}}[-:-:-:-]
[blue::b]Disc:[-:-:-:-] [::i]{{.GetDiscNumber}}[-:-:-:-]
[blue::b]Year:[-:-:-:-] [::i]{{.GetYear}}[-:-:-:-]
[blue::b]Track:[-:-:-:-] [::i]{{.GetTrackNumber}}[-:-:-:-]
[blue::b]Duration:[-:-:-:-] [::i]{{formatTime .Duration}}[-:-:-:-] `

Expand Down
55 changes: 39 additions & 16 deletions page_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (ui *Ui) createSearchPage() *SearchPage {
if searchPage.queryGenre {
searchPage.albumList.SetTitle(" album matches ")
} else {
searchPage.albumList.SetTitle(" genres ")
searchPage.populateGenres()
searchPage.albumList.SetTitle(fmt.Sprintf(" genres (%d) ", searchPage.albumList.GetItemCount()))
searchPage.ui.app.SetFocus(searchPage.albumList)
}
searchPage.queryGenre = !searchPage.queryGenre
Expand Down Expand Up @@ -150,7 +150,12 @@ func (ui *Ui) createSearchPage() *SearchPage {
switch event.Rune() {
case 'a':
if searchPage.queryGenre {
return event
idx := searchPage.albumList.GetCurrentItem()
if idx < searchPage.albumList.GetItemCount() {
genre, _ := searchPage.albumList.GetItemText(idx)
searchPage.addGenreToQueue(genre)
}
return nil
}
idx := searchPage.albumList.GetCurrentItem()
searchPage.logger.Printf("albumList adding (%d) %s", idx, searchPage.albums[idx].Name)
Expand All @@ -163,8 +168,8 @@ func (ui *Ui) createSearchPage() *SearchPage {
if searchPage.queryGenre {
searchPage.albumList.SetTitle(" album matches ")
} else {
searchPage.albumList.SetTitle(" genres ")
searchPage.populateGenres()
searchPage.albumList.SetTitle(fmt.Sprintf(" genres (%d) ", searchPage.albumList.GetItemCount()))
searchPage.ui.app.SetFocus(searchPage.albumList)
}
searchPage.queryGenre = !searchPage.queryGenre
Expand Down Expand Up @@ -201,8 +206,8 @@ func (ui *Ui) createSearchPage() *SearchPage {
if searchPage.queryGenre {
searchPage.albumList.SetTitle(" album matches ")
} else {
searchPage.albumList.SetTitle(" genres ")
searchPage.populateGenres()
searchPage.albumList.SetTitle(fmt.Sprintf(" genres (%d) ", searchPage.albumList.GetItemCount()))
searchPage.ui.app.SetFocus(searchPage.albumList)
}
searchPage.queryGenre = !searchPage.queryGenre
Expand Down Expand Up @@ -250,6 +255,8 @@ func (s *SearchPage) search(search chan string) {
var query string
var artOff, albOff, songOff int
more := make(chan bool, 5)
var res *subsonic.SubsonicResponse
var err error
for {
// quit searching if we receive an interrupt
select {
Expand All @@ -265,11 +272,11 @@ func (s *SearchPage) search(search chan string) {
}
case <-more:
}
var res *subsonic.SubsonicResponse
var err error
if s.queryGenre {
s.logger.Printf("genre %q %d", query, songOff)
res, err = s.ui.connection.GetSongsByGenre(query, songOff, "")
if len(res.SongsByGenre.Song) == 0 {
s.logger.Printf("found a total of %d songs", songOff)
continue
}
} else {
Expand All @@ -286,19 +293,19 @@ func (s *SearchPage) search(search chan string) {
return
}

query = strings.ToLower(query)
s.ui.app.QueueUpdate(func() {
if s.queryGenre {
if songOff == 0 {
s.artistList.Box.SetTitle(" artist matches ")
s.albumList.Box.SetTitle(" genres ")
}
for _, song := range res.SongsByGenre.Song {
s.songList.AddItem(tview.Escape(song.Title), "", 0, nil)
s.songs = append(s.songs, &song)
}
s.songList.Box.SetTitle(fmt.Sprintf(" genre song matches (%d) ", len(s.songs)))
songOff += len(res.SongsByGenre.Song)
} else {
query = strings.ToLower(query)
for _, artist := range res.SearchResults.Artist {
if strings.Contains(strings.ToLower(artist.Name), query) {
s.artistList.AddItem(tview.Escape(artist.Name), "", 0, nil)
Expand All @@ -320,21 +327,37 @@ func (s *SearchPage) search(search chan string) {
}
}
s.songList.Box.SetTitle(fmt.Sprintf(" song matches (%d) ", len(s.songs)))
artOff += len(res.SearchResults.Artist)
albOff += len(res.SearchResults.Album)
songOff += len(res.SearchResults.Song)
}
more <- true
})

if !s.queryGenre {
artOff += len(res.SearchResults.Artist)
albOff += len(res.SearchResults.Album)
songOff += len(res.SearchResults.Song)
} else {
songOff += len(res.SongsByGenre.Song)
}
s.ui.app.Draw()
more <- true
}
}

func (s *SearchPage) addGenreToQueue(query string) {
var songOff int
for {
res, err := s.ui.connection.GetSongsByGenre(query, songOff, "")
if err != nil {
s.logger.PrintError("SearchPage.addGenreToQueue", err)
return
}
if len(res.SongsByGenre.Song) == 0 {
break
}
for _, song := range res.SongsByGenre.Song {
s.ui.addSongToQueue(&song)
}
songOff += len(res.SongsByGenre.Song)
}
s.logger.Printf("added a total of %d songs to the queue for %q", songOff, query)
s.ui.queuePage.UpdateQueue()
}

func (s *SearchPage) addArtistToQueue(entity subsonic.Ider) {
response, err := s.ui.connection.GetArtist(entity.ID())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions subsonic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ type SubsonicEntity struct {
DiscNumber int `json:"discNumber"`
Path string `json:"path"`
CoverArtId string `json:"coverArt"`
Year int `json:"year"`
}

func (s SubsonicEntity) ID() string {
Expand Down

0 comments on commit 25aded6

Please sign in to comment.