Trying to work out why music can not be downloaded
This commit is contained in:
parent
5f9e778ac1
commit
dbc4583794
|
@ -1,7 +1,4 @@
|
||||||
machine:
|
machine:
|
||||||
go:
|
|
||||||
version:
|
|
||||||
1.4.2
|
|
||||||
environment:
|
environment:
|
||||||
PATH: $PATH:$HOME/bin/
|
PATH: $PATH:$HOME/bin/
|
||||||
LD_RUN_PATH: $LD_RUN_PATH:$HOME/opus/lib
|
LD_RUN_PATH: $LD_RUN_PATH:$HOME/opus/lib
|
||||||
|
|
|
@ -159,6 +159,13 @@ func parseCommand(user *gumble.User, username, command string) {
|
||||||
} else {
|
} else {
|
||||||
dj.SendPrivateMessage(user, NO_PERMISSION_MSG)
|
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:
|
default:
|
||||||
dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG)
|
dj.SendPrivateMessage(user, COMMAND_DOESNT_EXIST_MSG)
|
||||||
}
|
}
|
||||||
|
|
26
test.go
26
test.go
|
@ -6,19 +6,31 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test(password, ip, port string) {
|
type Test struct {
|
||||||
testYoutubeSong(password, ip, port)
|
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{
|
return gumble.NewClient(&gumble.Config{
|
||||||
Username: uname,
|
Username: uname,
|
||||||
Password: password,
|
Password: t.password,
|
||||||
Address: ip + ":" + port})
|
Address: t.ip + ":" + t.port})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testYoutubeSong(password, ip, port string) {
|
func (t Test) testYoutubeSong() {
|
||||||
dummyClient := createClient("dummy", password, ip, port)
|
dummyClient := t.createClient("dummy")
|
||||||
dummyClient.Connect()
|
dummyClient.Connect()
|
||||||
dummyUser := dj.client.Users.Find("dummy")
|
dummyUser := dj.client.Users.Find("dummy")
|
||||||
|
|
||||||
|
|
|
@ -38,14 +38,15 @@ type YouTubeDLPlaylist struct {
|
||||||
func (dl *YouTubeDLSong) Download() error {
|
func (dl *YouTubeDLSong) Download() error {
|
||||||
|
|
||||||
// Checks to see if song is already downloaded
|
// 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) {
|
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.id+".m4a"), "--format", "m4a", "--", dl.url)
|
cmd := exec.Command("youtube-dl", "--output", fmt.Sprintf(`~/.mumbledj/songs/%s`, dl.Filename()), "--format", "m4a", dl.url)
|
||||||
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()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Verbose("youtube-dl: " + err.Error())
|
||||||
return errors.New("Song download failed.")
|
return errors.New("Song download failed.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -58,18 +59,16 @@ func (dl *YouTubeDLSong) Play() {
|
||||||
offsetDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", dl.offset))
|
offsetDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", dl.offset))
|
||||||
dj.audioStream.Offset = offsetDuration
|
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 {
|
if err := dj.audioStream.Play(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
} 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)
|
message = fmt.Sprintf(message, dl.thumbnail, dl.url, dl.title, dl.duration, dl.submitter)
|
||||||
if isNil(dl.playlist) {
|
if !isNil(dl.playlist) {
|
||||||
dj.client.Self.Channel.Send(message+`</table>`, false)
|
message = fmt.Sprintf(message+`<tr><td align="center">From playlist "%s"</td></tr>`, dl.playlist.Title())
|
||||||
} else {
|
|
||||||
message += `<tr><td align="center">From playlist "%s"</td></tr></table>`
|
|
||||||
dj.client.Self.Channel.Send(fmt.Sprintf(message, dl.playlist.Title()), false)
|
|
||||||
}
|
}
|
||||||
|
dj.client.Self.Channel.Send(message+`</table>`, false)
|
||||||
Verbose("Now playing " + dl.title)
|
Verbose("Now playing " + dl.title)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -82,7 +81,7 @@ func (dl *YouTubeDLSong) Play() {
|
||||||
// Delete deletes the song from ~/.mumbledj/songs if the cache is disabled.
|
// Delete deletes the song from ~/.mumbledj/songs if the cache is disabled.
|
||||||
func (dl *YouTubeDLSong) Delete() error {
|
func (dl *YouTubeDLSong) Delete() error {
|
||||||
if dj.conf.Cache.Enabled == false {
|
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.Stat(filePath); err == nil {
|
||||||
if err := os.Remove(filePath); err == nil {
|
if err := os.Remove(filePath); err == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
Reference in a new issue