Commit 63acf5bf authored by Mike Jones's avatar Mike Jones 🌶

Song plays

parent c1cfbc44
......@@ -22,7 +22,7 @@ func main() {
gauntlet.New(config, db)
out := gauntlet.Run("ne7split", `aplays Odraza "Esperalem tkane"`)
out := gauntlet.Run("ne7split", `splays Begrime Exemious "Noose for a Monarch"`)
log.Println(out)
......
......@@ -2,9 +2,10 @@ package command
import (
"fmt"
"strconv"
"github.com/boltdb/bolt"
"github.com/n7st/lastfm-go/lastfm"
"strconv"
"git.netsplit.uk/stella-irc/modlastfm/internal/app/modlastfm/util"
)
......
......@@ -8,6 +8,8 @@ import (
"github.com/n7st/lastfm-go/lastfm"
)
const statLineF = "%s by %s has %s total plays, of which %s are %s's (%s)"
func (f *Fn) NowPlaying(message string, username string) string {
resp, err := f.LastFM.User.GetRecentTracks(lastfm.P{
"autocorrect": 1,
......@@ -51,14 +53,20 @@ func (f *Fn) UserAlbumStats(message string, username string) string {
return f.fmtUserAlbumStats(username, userAlbumInfo)
}
func (f *Fn) fmtUserArtistStats(username string, info lastfm.ArtistGetInfo) string {
return fmt.Sprintf("%s have %s total plays, of which %s are %s's (%s)",
info.Name,
info.Stats.Plays,
info.Stats.UserPlays,
username,
fmtPlaycountPercentage(info.Stats.UserPlays, info.Stats.Plays),
)
func (f *Fn) UserTrackStats(message string, username string) string {
artist, songTitle := extractTitles(message)
if artist == "" || songTitle == "" {
return `Format: splays Artist Name "Song Title"`
}
userTrackInfo, err := f.getUserTrackInfo(username, artist, songTitle)
if err != nil {
return fmtError(err)
}
return f.fmtUserTrackStats(username, userTrackInfo)
}
// formats a "now playing" string from recent user tracks, e.g.:
......@@ -107,8 +115,18 @@ func (f *Fn) fmtNowPlaying(username string, np lastfm.UserGetRecentTracks) strin
)
}
func (f *Fn) fmtUserArtistStats(username string, info lastfm.ArtistGetInfo) string {
return fmt.Sprintf("%s have %s total plays, of which %s are %s's (%s)",
info.Name,
info.Stats.Plays,
info.Stats.UserPlays,
username,
fmtPlaycountPercentage(info.Stats.UserPlays, info.Stats.Plays),
)
}
func (f *Fn) fmtUserAlbumStats(username string, album lastfm.AlbumGetInfo) string {
return fmt.Sprintf("%s by %s has %s total plays, of which %s are %s's (%s)",
return fmt.Sprintf(statLineF,
album.Name,
album.Artist,
album.PlayCount,
......@@ -118,6 +136,17 @@ func (f *Fn) fmtUserAlbumStats(username string, album lastfm.AlbumGetInfo) strin
)
}
func (f *Fn) fmtUserTrackStats(username string, track lastfm.TrackGetInfo) string {
return fmt.Sprintf(statLineF,
track.Artist.Name,
track.Name,
track.PlayCount,
track.UserPlayCount,
username,
fmtPlaycountPercentage(track.UserPlayCount, track.PlayCount),
)
}
func (f *Fn) getUserTrackInfo(username string, artist string, track string) (lastfm.TrackGetInfo, error) {
return f.LastFM.Track.GetInfo(lastfm.P{
"artist": artist,
......
......@@ -25,9 +25,17 @@ func New(c *util.Config, db *bolt.DB) {
"l": fn.NowPlaying,
"np": fn.NowPlaying,
"nowplaying": fn.NowPlaying,
//"topw": fn.UserTopWeek,
//"topm": fn.UserTopMonth,
//"topy": fn.UserTopYear,
//"topa": fn.UserTopAll,
"plays": fn.UserArtistStats,
"aplays": fn.UserAlbumStats,
"splays": fn.UserTrackStats,
//"artist": fn.ArtistInfo,
//"band": fn.ArtistInfo,
//"similar": fn.SimilarArtists,
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment