From dbc458379412c8a46bc13337484c79a081eb45ab Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Wed, 12 Aug 2015 19:49:03 +0100 Subject: [PATCH] Trying to work out why music can not be downloaded --- circle.yml | 3 --- commands.go | 7 +++++++ test.go | 26 +++++++++++++++++++------- youtube_dl.go | 19 +++++++++---------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/circle.yml b/circle.yml index baa1a4b..fa81c7e 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,4 @@ machine: - go: - version: - 1.4.2 environment: PATH: $PATH:$HOME/bin/ LD_RUN_PATH: $LD_RUN_PATH:$HOME/opus/lib diff --git a/commands.go b/commands.go index 22121e2..5dc19b7 100644 --- a/commands.go +++ b/commands.go @@ -159,6 +159,13 @@ func parseCommand(user *gumble.User, username, command string) { } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } + // Test command (WORKAROUND) + case "test": + if dj.HasPermission(username, dj.conf.Permissions.AdminKill) && test != nil { + test.testYoutubeSong() + } else { + dj.SendPrivateMessage(user, NO_PERMISSION_MSG) + } default: dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG) } diff --git a/test.go b/test.go index c9b40ec..8b41a8a 100644 --- a/test.go +++ b/test.go @@ -6,19 +6,31 @@ import ( "time" ) -func Test(password, ip, port string) { - testYoutubeSong(password, ip, port) +type Test struct { + password string + ip string + port string } -func createClient(uname, password, ip, port string) *gumble.Client { +var test Test + +func Test(password, ip, port string) { + test = Test{ + password: password, + ip: ip, + port: port, + } +} + +func (t Test) createClient(uname) *gumble.Client { return gumble.NewClient(&gumble.Config{ Username: uname, - Password: password, - Address: ip + ":" + port}) + Password: t.password, + Address: t.ip + ":" + t.port}) } -func testYoutubeSong(password, ip, port string) { - dummyClient := createClient("dummy", password, ip, port) +func (t Test) testYoutubeSong() { + dummyClient := t.createClient("dummy") dummyClient.Connect() dummyUser := dj.client.Users.Find("dummy") diff --git a/youtube_dl.go b/youtube_dl.go index b7afff2..a661df4 100644 --- a/youtube_dl.go +++ b/youtube_dl.go @@ -38,14 +38,15 @@ type YouTubeDLPlaylist struct { func (dl *YouTubeDLSong) Download() error { // Checks to see if song is already downloaded - if _, err := os.Stat(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.id+".m4a")); os.IsNotExist(err) { - cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf(`~/.mumbledj/songs/%s`, dl.id+".m4a"), "--format", "m4a", "--", dl.url) + if _, err := os.Stat(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.Filename())); os.IsNotExist(err) { + cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf(`~/.mumbledj/songs/%s`, dl.Filename()), "--format", "m4a", dl.url) if err := cmd.Run(); err == nil { if dj.conf.Cache.Enabled { dj.cache.CheckMaximumDirectorySize() } return nil } + Verbose("youtube-dl: " + err.Error()) return errors.New("Song download failed.") } return nil @@ -58,18 +59,16 @@ func (dl *YouTubeDLSong) Play() { offsetDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", dl.offset)) dj.audioStream.Offset = offsetDuration } - dj.audioStream.Source = gumble_ffmpeg.SourceFile(fmt.Sprintf("%s/.mumbledj/songs/%s.m4a", dj.homeDir, dl.id)) + dj.audioStream.Source = gumble_ffmpeg.SourceFile(fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.Filename())) if err := dj.audioStream.Play(); err != nil { panic(err) } else { - message := `` + message := `
%s (%s)
Added by %s
` message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.duration, dl.submitter) - if isNil(dl.playlist) { - dj.client.Self.Channel.Send(message+`
%s (%s)
Added by %s
`, false) - } else { - message += `From playlist "%s"` - dj.client.Self.Channel.Send(fmt.Sprintf(message, dl.playlist.Title()), false) + if !isNil(dl.playlist) { + message = fmt.Sprintf(message+`From playlist "%s"`, dl.playlist.Title()) } + dj.client.Self.Channel.Send(message+``, false) Verbose("Now playing " + dl.title) go func() { @@ -82,7 +81,7 @@ func (dl *YouTubeDLSong) Play() { // Delete deletes the song from ~/.mumbledj/songs if the cache is disabled. func (dl *YouTubeDLSong) Delete() error { if dj.conf.Cache.Enabled == false { - filePath := fmt.Sprintf("%s/.mumbledj/songs/%s.m4a", dj.homeDir, dl.id) + filePath := fmt.Sprintf("%s/.mumbledj/songs/%s", dj.homeDir, dl.Filename()) if _, err := os.Stat(filePath); err == nil { if err := os.Remove(filePath); err == nil { return nil