From b78005272673f41a38b84373bab2fb82819811e1 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 13:29:14 +0100 Subject: [PATCH] Fixing build issues --- main.go | 5 +++++ service_youtube.go | 6 +++--- songqueue.go | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 982d3a3..0979126 100644 --- a/main.go +++ b/main.go @@ -146,6 +146,11 @@ func Verbose(msg string) { } } +func isNil(a interface{}) bool { + defer func() { recover() }() + return a == nil || reflect.ValueOf(a).IsNil() +} + // dj variable declaration. This is done outside of main() to allow global use. var dj = mumbledj{ keepAlive: make(chan bool), diff --git a/service_youtube.go b/service_youtube.go index 5f53800..0303488 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -110,7 +110,7 @@ type YouTubeSong struct { // NewYouTubeSong gathers the metadata for a song extracted from a YouTube video, and returns // the song. -func NewYouTubeSong(user, id, offset string, list *YouTubePlaylist) (*YouTubeSong, error) { +func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTubeSong, error) { var apiResponse *jsonq.JsonQuery var err error url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=%s&key=%s", @@ -193,7 +193,7 @@ func NewYouTubeSong(user, id, offset string, list *YouTubePlaylist) (*YouTubeSon duration: durationString, thumbnail: thumbnail, skippers: make([]string, 0), - playlist: &list, + playlist: playlist, dontSkip: false, } dj.queue.AddSong(song) @@ -236,7 +236,7 @@ func (s *YouTubeSong) Play() { if err := dj.audioStream.Play(); err != nil { panic(err) } else { - if s.Playlist() == nil { + if s.Playlist() == &nil { message := ` diff --git a/songqueue.go b/songqueue.go index 5cf9e8d..67db542 100644 --- a/songqueue.go +++ b/songqueue.go @@ -43,7 +43,7 @@ func (q *SongQueue) CurrentSong() Song { // NextSong moves to the next Song in SongQueue. NextSong() removes the first Song in the queue. func (q *SongQueue) NextSong() { if s, err := q.PeekNext(); err == nil { - if (q.CurrentSong().Playlist() != nil) && (s.Playlist() != nil) { + if !isNil(q.CurrentSong().Playlist()) && !isNil(s.Playlist()) { if q.CurrentSong().Playlist().ID() != s.Playlist().ID() { q.CurrentSong().Playlist().DeleteSkippers() }