Trying to work out why music can not be downloaded

This commit is contained in:
MichaelOultram 2015-08-12 19:49:03 +01:00
parent 5f9e778ac1
commit dbc4583794
4 changed files with 35 additions and 20 deletions

View file

@ -1,7 +1,4 @@
machine:
go:
version:
1.4.2
environment:
PATH: $PATH:$HOME/bin/
LD_RUN_PATH: $LD_RUN_PATH:$HOME/opus/lib

View file

@ -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)
}

26
test.go
View file

@ -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")

View file

@ -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 := `<table><tr> <td align="center"><img src="%s" width=150 /></td></tr><tr><td align="center"><b><a href="%s">%s</a> (%s)</b></td></tr><tr><td align="center">Added by %s</td></tr>`
message := `<table><tr><td align="center"><img src="%s" width=150 /></td></tr><tr><td align="center"><b><a href="%s">%s</a> (%s)</b></td></tr><tr><td align="center">Added by %s</td></tr>`
message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.duration, dl.submitter)
if isNil(dl.playlist) {
dj.client.Self.Channel.Send(message+`</table>`, false)
} else {
message += `<tr><td align="center">From playlist "%s"</td></tr></table>`
dj.client.Self.Channel.Send(fmt.Sprintf(message, dl.playlist.Title()), false)
if !isNil(dl.playlist) {
message = fmt.Sprintf(message+`<tr><td align="center">From playlist "%s"</td></tr>`, dl.playlist.Title())
}
dj.client.Self.Channel.Send(message+`</table>`, 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