diff --git a/README.md b/README.md index 08f8a24..f990e73 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A simple terminal UI player for [di.fm Premium](http://di.fm) ![App Screenshot](https://user-images.githubusercontent.com/3331648/81481515-bb668400-91fe-11ea-8a7c-39e1bb76c55d.png) -# Dependencies +# Dependencies ## PulseAudio @@ -19,7 +19,7 @@ ln -s $(brew info pulseaudio | grep "/usr/local/Cellar" | awk '{print $1}')//hom brew services start pulseaudio ``` -### Linux +### Linux `apt install pulseaudio` @@ -42,16 +42,22 @@ If your `$GOPATH` is not set, see https://github.com/golang/go/wiki/SettingGOPAT # Authenticate -There are two authentication options +There are two authentication options - Enter your username and password directly into `di-tui` - If you're justifiably uncomfortable with entering your username/password into this application, copy your "Listen Key" from (https://www.di.fm/settings) and create the following file: -## ~/.config/di-tui/config.yml +## ~/.config/di-tui/config.yml ```yml token: +album_art: ``` +| key | description | +| --- | ----------- | +| token | Your di.fm authentication "Listen Key" found at https://www.di.fm/settings | +| album_art | Turn album art on or off | + # Run `di-tui` diff --git a/app/app.go b/app/app.go index dd4f3cd..1564689 100644 --- a/app/app.go +++ b/app/app.go @@ -12,6 +12,7 @@ import ( "reflect" "github.com/acaloiaro/di-tui/components" + "github.com/acaloiaro/di-tui/config" "github.com/acaloiaro/di-tui/context" "github.com/acaloiaro/di-tui/difm" "github.com/michiwend/gomusicbrainz" @@ -21,12 +22,16 @@ import ( // Art fetches album art for the given track, converts it to ASCII, and return the ASCII stringified album art func Art(artist, track string) (art string) { + if !config.AlbumArt() { + return + } + // create a new WS2Client. client, err := gomusicbrainz.NewWS2Client( "https://musicbrainz.org/ws/2", "di-tui", "0.0.1", - "http://github.com/acaloiaro/di-tui") + "https://github.com/acaloiaro/di-tui") if err != nil { return @@ -36,7 +41,7 @@ func Art(artist, track string) (art string) { searchString := fmt.Sprintf(`artist:"%s" release:"%s"`, artist, track) mbResp, _ := client.SearchRelease(searchString, 1, -1) if len(mbResp.Releases) == 0 { - err = fmt.Errorf("no releases foudn for the artist (%s) and track (%s)", artist, track) + err = fmt.Errorf("no releases found for the artist (%s) and track (%s)", artist, track) return } @@ -132,15 +137,21 @@ func TogglePause(ctx *context.AppContext) { ctx.IsPlaying = !ctx.IsPlaying } -// UpdateNowPlaying updates the application's now playing view with the currently playing channel +// UpdateNowPlaying updates the application's now playing view with the currently playing channel and album art +// Artist and track information are fetched separately from album art, allowing for a more responsive UI func UpdateNowPlaying(chn *components.ChannelItem, ctx *context.AppContext) { - ctx.CurrentChannel = chn - cp := difm.GetCurrentlyPlaying(ctx) - albumArt := Art(cp.Track.Artist, cp.Track.Title) - - ctx.View.App.QueueUpdateDraw(func() { - ctx.View.NowPlaying.Channel = chn - ctx.View.NowPlaying.Track = cp.Track - ctx.View.NowPlaying.Art = albumArt - }) + go func() { + ctx.CurrentChannel = chn + cp := difm.GetCurrentlyPlaying(ctx) + + ctx.View.App.QueueUpdateDraw(func() { + ctx.View.NowPlaying.Channel = chn + ctx.View.NowPlaying.Track = cp.Track + }) + + albumArt := Art(cp.Track.Artist, cp.Track.Title) + ctx.View.App.QueueUpdateDraw(func() { + ctx.View.NowPlaying.Art = albumArt + }) + }() } diff --git a/config/config.go b/config/config.go index c217052..d7ef6c9 100644 --- a/config/config.go +++ b/config/config.go @@ -14,12 +14,25 @@ func init() { viper.AddConfigPath("$HOME/.config/di-tui") viper.AddConfigPath("$HOME/.di-tui/") viper.AddConfigPath(".") + + viper.SetDefault("album_art", true) + err := viper.ReadInConfig() if err != nil { saveConfig() } } +// AlbumArt returns true if album art should be fetched when a new song begins playing +func AlbumArt() bool { + return viper.GetBool("album_art") +} + +// GetToken returns the di.fm API token if one is available +func GetToken() (token string) { + return viper.GetString("token") +} + // SaveToken persists the di.fm API token to disk func SaveToken(token string) { viper.Set("username", "") @@ -29,11 +42,6 @@ func SaveToken(token string) { saveConfig() } -// GetToken returns the di.fm API token if one is available -func GetToken() (token string) { - return viper.GetString("token") -} - func saveConfig() { viper.SetConfigFile(configFilePath()) viper.SetConfigType("yaml")