Started adding verbose messages for the console
This commit is contained in:
parent
c15b06064f
commit
63b3b51288
8
Goopfile.lock
Normal file
8
Goopfile.lock
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
code.google.com/p/gcfg #c2d3050044d0
|
||||||
|
github.com/golang/protobuf #0f7a9caded1fb3c9cc5a9b4bcf2ff633cc8ae644
|
||||||
|
github.com/jmoiron/jsonq #7c27c8eb9f6831555a4209f6a7d579159e766a3c
|
||||||
|
github.com/layeh/gopus #2f86fa22bc209cc0ccbc6418dfbad9199e3dbc78
|
||||||
|
github.com/layeh/gumble/gumble #8b9989d9c4090874546c45ceaa6ff21e95705bc4
|
||||||
|
github.com/layeh/gumble/gumble_ffmpeg #c9fcce8fc4b71c7c53a5d3d9d48a1e001ad19a19
|
||||||
|
github.com/layeh/gumble/gumbleutil #abf58b0ea8b2661897f81cf69c2a6a3e37152d74
|
||||||
|
github.com/timshannon/go-openal #f4fbb66b2922de93753ac8069ff62d20a56a7450
|
5
main.go
5
main.go
|
@ -35,6 +35,7 @@ type mumbledj struct {
|
||||||
homeDir string
|
homeDir string
|
||||||
playlistSkips map[string][]string
|
playlistSkips map[string][]string
|
||||||
cache *SongCache
|
cache *SongCache
|
||||||
|
verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnConnect event. First moves MumbleDJ into the default channel specified
|
// OnConnect event. First moves MumbleDJ into the default channel specified
|
||||||
|
@ -164,7 +165,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var address, port, username, password, channel, pemCert, pemKey, accesstokens string
|
var address, port, username, password, channel, pemCert, pemKey, accesstokens string
|
||||||
var insecure bool
|
var insecure, verbose bool
|
||||||
|
|
||||||
flag.StringVar(&address, "server", "localhost", "address for Mumble server")
|
flag.StringVar(&address, "server", "localhost", "address for Mumble server")
|
||||||
flag.StringVar(&port, "port", "64738", "port for Mumble server")
|
flag.StringVar(&port, "port", "64738", "port for Mumble server")
|
||||||
|
@ -175,6 +176,7 @@ func main() {
|
||||||
flag.StringVar(&pemKey, "key", "", "path to user PEM key for MumbleDJ")
|
flag.StringVar(&pemKey, "key", "", "path to user PEM key for MumbleDJ")
|
||||||
flag.StringVar(&accesstokens, "accesstokens", "", "list of access tokens for channel auth")
|
flag.StringVar(&accesstokens, "accesstokens", "", "list of access tokens for channel auth")
|
||||||
flag.BoolVar(&insecure, "insecure", false, "skip certificate checking")
|
flag.BoolVar(&insecure, "insecure", false, "skip certificate checking")
|
||||||
|
flag.BoolVar(&verbose, "verbose", false, "prints out debug messages to the console")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
dj.config = gumble.Config{
|
dj.config = gumble.Config{
|
||||||
|
@ -201,6 +203,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
dj.defaultChannel = strings.Split(channel, "/")
|
dj.defaultChannel = strings.Split(channel, "/")
|
||||||
|
dj.verbose = &verbose
|
||||||
|
|
||||||
dj.client.Attach(gumbleutil.Listener{
|
dj.client.Attach(gumbleutil.Listener{
|
||||||
Connect: dj.OnConnect,
|
Connect: dj.OnConnect,
|
||||||
|
|
|
@ -131,6 +131,11 @@ func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTub
|
||||||
dontSkip: false,
|
dontSkip: false,
|
||||||
}
|
}
|
||||||
dj.queue.AddSong(song)
|
dj.queue.AddSong(song)
|
||||||
|
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("%s added track %s\n", song.Submitter, song.Title())
|
||||||
|
}
|
||||||
|
|
||||||
return song, nil
|
return song, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("Song exceeds the maximum allowed duration.")
|
return nil, errors.New("Song exceeds the maximum allowed duration.")
|
||||||
|
@ -139,14 +144,31 @@ func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTub
|
||||||
// Download downloads the song via youtube-dl if it does not already exist on disk.
|
// Download downloads the song via youtube-dl if it does not already exist on disk.
|
||||||
// All downloaded songs are stored in ~/.mumbledj/songs and should be automatically cleaned.
|
// All downloaded songs are stored in ~/.mumbledj/songs and should be automatically cleaned.
|
||||||
func (s *YouTubeSong) Download() error {
|
func (s *YouTubeSong) Download() error {
|
||||||
|
|
||||||
|
// Checks to see if song is already downloaded
|
||||||
if _, err := os.Stat(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, s.Filename())); os.IsNotExist(err) {
|
if _, err := os.Stat(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, s.Filename())); os.IsNotExist(err) {
|
||||||
|
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("Downloading %s\n", s.Title)
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf(`~/.mumbledj/songs/%s`, s.Filename()), "--format", "m4a", "--", s.ID())
|
cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf(`~/.mumbledj/songs/%s`, s.Filename()), "--format", "m4a", "--", s.ID())
|
||||||
if err := cmd.Run(); err == nil {
|
if err := cmd.Run(); err == nil {
|
||||||
if dj.conf.Cache.Enabled {
|
if dj.conf.Cache.Enabled {
|
||||||
dj.cache.CheckMaximumDirectorySize()
|
dj.cache.CheckMaximumDirectorySize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("%s downloaded\n", s.Title())
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("%s failed to download\n", s.Title())
|
||||||
|
}
|
||||||
|
|
||||||
return errors.New("Song download failed.")
|
return errors.New("Song download failed.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -199,6 +221,11 @@ func (s *YouTubeSong) Play() {
|
||||||
dj.client.Self.Channel.Send(fmt.Sprintf(message, s.Thumbnail(), s.ID(),
|
dj.client.Self.Channel.Send(fmt.Sprintf(message, s.Thumbnail(), s.ID(),
|
||||||
s.Title(), s.Duration(), s.Submitter(), s.Playlist().Title()), false)
|
s.Title(), s.Duration(), s.Submitter(), s.Playlist().Title()), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("Now playing %s\n", s.Title())
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
dj.audioStream.Wait()
|
dj.audioStream.Wait()
|
||||||
dj.queue.OnSongFinished()
|
dj.queue.OnSongFinished()
|
||||||
|
@ -212,6 +239,9 @@ func (s *YouTubeSong) Delete() error {
|
||||||
filePath := fmt.Sprintf("%s/.mumbledj/songs/%s.m4a", dj.homeDir, s.ID())
|
filePath := fmt.Sprintf("%s/.mumbledj/songs/%s.m4a", dj.homeDir, s.ID())
|
||||||
if _, err := os.Stat(filePath); err == nil {
|
if _, err := os.Stat(filePath); err == nil {
|
||||||
if err := os.Remove(filePath); err == nil {
|
if err := os.Remove(filePath); err == nil {
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("Deleting %s\n", s.Title())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.New("Error occurred while deleting audio file.")
|
return errors.New("Error occurred while deleting audio file.")
|
||||||
|
@ -402,6 +432,9 @@ func NewYouTubePlaylist(user, id string) (*YouTubePlaylist, error) {
|
||||||
dontSkip: false,
|
dontSkip: false,
|
||||||
}
|
}
|
||||||
dj.queue.AddSong(playlistSong)
|
dj.queue.AddSong(playlistSong)
|
||||||
|
if dj.verbose {
|
||||||
|
fmt.Printf("%s added song %s\n", playlistSong.Submitter, playlistSong.Title())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return playlist, nil
|
return playlist, nil
|
||||||
|
|
Reference in a new issue