Fixing build issues

This commit is contained in:
MichaelOultram 2015-07-28 13:29:14 +01:00
parent d5687e0c06
commit b780052726
3 changed files with 9 additions and 4 deletions

View file

@ -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. // dj variable declaration. This is done outside of main() to allow global use.
var dj = mumbledj{ var dj = mumbledj{
keepAlive: make(chan bool), keepAlive: make(chan bool),

View file

@ -110,7 +110,7 @@ type YouTubeSong struct {
// NewYouTubeSong gathers the metadata for a song extracted from a YouTube video, and returns // NewYouTubeSong gathers the metadata for a song extracted from a YouTube video, and returns
// the song. // 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 apiResponse *jsonq.JsonQuery
var err error var err error
url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=%s&key=%s", 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, duration: durationString,
thumbnail: thumbnail, thumbnail: thumbnail,
skippers: make([]string, 0), skippers: make([]string, 0),
playlist: &list, playlist: playlist,
dontSkip: false, dontSkip: false,
} }
dj.queue.AddSong(song) dj.queue.AddSong(song)
@ -236,7 +236,7 @@ func (s *YouTubeSong) Play() {
if err := dj.audioStream.Play(); err != nil { if err := dj.audioStream.Play(); err != nil {
panic(err) panic(err)
} else { } else {
if s.Playlist() == nil { if s.Playlist() == &nil {
message := ` message := `
<table> <table>
<tr> <tr>

View file

@ -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. // NextSong moves to the next Song in SongQueue. NextSong() removes the first Song in the queue.
func (q *SongQueue) NextSong() { func (q *SongQueue) NextSong() {
if s, err := q.PeekNext(); err == nil { 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() { if q.CurrentSong().Playlist().ID() != s.Playlist().ID() {
q.CurrentSong().Playlist().DeleteSkippers() q.CurrentSong().Playlist().DeleteSkippers()
} }