Small tweaks

This commit is contained in:
Matthieu Grieger 2015-04-09 13:52:32 -07:00
parent 26a9d78fac
commit b37937769b
3 changed files with 22 additions and 21 deletions

View file

@ -1,6 +1,6 @@
all: mumbledj
mumbledj: main.go commands.go parseconfig.go strings.go song.go playlist.go songqueue.go cache.go
mumbledj: main.go commands.go parseconfig.go strings.go services/base.go services/youtube/song.go services/youtube/playlist.go songqueue.go cache.go
go get github.com/nitrous-io/goop
rm -rf Goopfile.lock
goop install

View file

@ -15,6 +15,8 @@ import (
"strconv"
"strings"
"github.com/matthieugrieger/mumbledj/services/youtube"
"github.com/layeh/gumble/gumble"
)
@ -184,17 +186,15 @@ func add(user *gumble.User, username, url string) {
}
if matchFound {
if newSong, err := NewSong(username, shortUrl, nil); err == nil {
if err := dj.queue.AddSong(newSong); err == nil {
dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, username, newSong.title), false)
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentSong().Download(); err == nil {
dj.queue.CurrentSong().Play()
} else {
dj.SendPrivateMessage(user, AUDIO_FAIL_MSG)
dj.queue.CurrentSong().Delete()
dj.queue.OnSongFinished()
}
if newSong, err := youtube.NewSong(username, shortUrl, nil); err == nil {
dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, username, newSong.title), false)
if dj.queue.Len() == 1 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentSong().Download(); err == nil {
dj.queue.CurrentSong().Play()
} else {
dj.SendPrivateMessage(user, AUDIO_FAIL_MSG)
dj.queue.CurrentSong().Delete()
dj.queue.OnSongFinished()
}
}
} else if fmt.Sprint(err) == "video exceeds the maximum allowed duration." {
@ -210,7 +210,7 @@ func add(user *gumble.User, username, url string) {
if dj.HasPermission(username, dj.conf.Permissions.AdminAddPlaylists) {
shortUrl = re.FindStringSubmatch(url)[1]
oldLength := dj.queue.Len()
if newPlaylist, err := NewPlaylist(username, shortUrl); err == nil {
if newPlaylist, err := youtube.NewPlaylist(username, shortUrl); err == nil {
dj.client.Self.Channel.Send(fmt.Sprintf(PLAYLIST_ADDED_HTML, username, newPlaylist.title), false)
if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() {
if err := dj.queue.CurrentSong().Download(); err == nil {
@ -372,7 +372,7 @@ func reset(username string) {
func numSongs() {
songCount := 0
dj.queue.Traverse(func(i int, song *Song) {
songCount += 1
songCount++
})
dj.client.Self.Channel.Send(fmt.Sprintf(NUM_SONGS_HTML, songCount), false)
}
@ -454,5 +454,4 @@ func deleteSongs() error {
}
return nil
}
return nil
}

View file

@ -9,22 +9,24 @@ package main
import (
"errors"
"github.com/matthieugrieger/mumbledj/services"
)
// SongQueue type declaration.
type SongQueue struct {
queue []*Song
queue []*services.Song
}
// Initializes a new queue and returns the new SongQueue.
func NewSongQueue() *SongQueue {
return &SongQueue{
queue: make([]*Song, 0),
queue: make([]*services.Song, 0),
}
}
// Adds a Song to the SongQueue.
func (q *SongQueue) AddSong(s *Song) error {
func (q *SongQueue) AddSong(s *services.Song) error {
beforeLen := q.Len()
q.queue = append(q.queue, s)
if len(q.queue) == beforeLen+1 {
@ -35,7 +37,7 @@ func (q *SongQueue) AddSong(s *Song) error {
}
// Returns the current Song.
func (q *SongQueue) CurrentSong() *Song {
func (q *SongQueue) CurrentSong() *services.Song {
return q.queue[0]
}
@ -54,7 +56,7 @@ func (q *SongQueue) NextSong() {
}
// Peeks at the next Song and returns it.
func (q *SongQueue) PeekNext() (*Song, error) {
func (q *SongQueue) PeekNext() (*services.Song, error) {
if q.Len() > 1 {
return q.queue[1], nil
} else {
@ -69,7 +71,7 @@ func (q *SongQueue) Len() int {
// A traversal function for SongQueue. Allows a visit function to be passed in which performs
// the specified action on each queue item.
func (q *SongQueue) Traverse(visit func(i int, s *Song)) {
func (q *SongQueue) Traverse(visit func(i int, s *services.Song)) {
for sQueue, queueSong := range q.queue {
visit(sQueue, queueSong)
}