diff --git a/go.mod b/go.mod index 43788f1..8c134e4 100644 --- a/go.mod +++ b/go.mod @@ -4,34 +4,71 @@ require ( github.com/DexterLB/mpvipc v0.0.0-20210824102722-5d27ef06b6c3 github.com/channelmeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61 github.com/fluffle/goirc v1.1.1 + github.com/gorilla/websocket v1.4.2 + github.com/mattermost/mattermost-server/v5 v5.39.1 + github.com/pkg/errors v0.9.1 + github.com/slack-go/slack v0.9.5 + github.com/stretchr/testify v1.7.0 + github.com/svenwiltink/youtube-dl v2.0.0+incompatible + github.com/vansante/go-event-emitter v1.0.2 + google.golang.org/api v0.60.0 +) + +require ( + cloud.google.com/go v0.97.0 // indirect + github.com/blang/semver v3.5.1+incompatible // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dustin/go-humanize v1.0.0 // indirect + github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect + github.com/francoispqt/gojay v1.2.13 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/mock v1.6.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/gorilla/websocket v1.4.2 + github.com/googleapis/gax-go/v2 v2.1.1 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.13.6 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect + github.com/mattermost/go-i18n v1.11.0 // indirect github.com/mattermost/ldap v3.0.4+incompatible // indirect - github.com/mattermost/mattermost-server/v5 v5.39.1 + github.com/mattermost/logr v1.0.13 // indirect + github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/minio-go/v7 v7.0.15 // indirect + github.com/minio/sha256-simd v1.0.0 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pborman/uuid v1.2.1 // indirect github.com/pelletier/go-toml v1.9.4 // indirect - github.com/pkg/errors v0.9.1 - github.com/slack-go/slack v0.9.5 - github.com/stretchr/testify v1.7.0 - github.com/svenwiltink/youtube-dl v2.0.0+incompatible - github.com/vansante/go-event-emitter v1.0.2 + github.com/philhofer/fwd v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rs/xid v1.3.0 // indirect + github.com/sirupsen/logrus v1.8.1 // indirect + github.com/tinylib/msgp v1.1.6 // indirect + github.com/wiggin77/cfg v1.0.2 // indirect + github.com/wiggin77/merror v1.0.3 // indirect + github.com/wiggin77/srslog v1.0.1 // indirect + go.opencensus.io v0.23.0 // indirect go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.7.0 // indirect go.uber.org/zap v1.19.1 // indirect golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect golang.org/x/net v0.0.0-20211108170745-6635138e15ea // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect golang.org/x/sys v0.0.0-20211109065445-02f5c0300f6e // indirect golang.org/x/text v0.3.7 // indirect - google.golang.org/api v0.60.0 + google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20211104193956-4c6863e31247 // indirect google.golang.org/grpc v1.42.0 // indirect + google.golang.org/protobuf v1.27.1 // indirect gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect gopkg.in/ini.v1 v1.63.2 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) -go 1.13 +go 1.18 diff --git a/go.sum b/go.sum index be6092e..16735ea 100644 --- a/go.sum +++ b/go.sum @@ -397,7 +397,6 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/gax-go v2.0.0+incompatible h1:j0GKcs05QVmm7yesiZq2+9cxHkNK9YM6zKx4D2qucQU= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -555,7 +554,6 @@ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s= github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= @@ -1058,7 +1056,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -1071,7 +1068,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1345,7 +1341,6 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/bot/bot.go b/pkg/bot/bot.go index 7fb30fc..f3775d1 100644 --- a/pkg/bot/bot.go +++ b/pkg/bot/bot.go @@ -80,7 +80,8 @@ func (bot *MusicBot) Start() { bot.musicPlayer.AddListener(music.EventSongStartError, func(arguments ...interface{}) { song := arguments[0].(music.Song) - bot.BroadcastMessage(fmt.Sprintf("Error starting %v %v, skipping", song.Artist, song.Name)) + err := arguments[1].(error) + bot.BroadcastMessage(fmt.Sprintf("Error starting %v %v, skipping (%v)", song.Artist, song.Name, err)) }) go bot.messageLoop() diff --git a/pkg/music/player/musicplayer.go b/pkg/music/player/musicplayer.go index e5bfaff..61a4f84 100644 --- a/pkg/music/player/musicplayer.go +++ b/pkg/music/player/musicplayer.go @@ -207,7 +207,7 @@ func (player *MusicPlayer) playLoop() { if err != nil { log.Println(err) - player.EmitEvent(music.EventSongStartError, song) + player.EmitEvent(music.EventSongStartError, song, err) continue } diff --git a/pkg/music/provider/mpv/mpv.go b/pkg/music/provider/mpv/mpv.go index 843856c..1804d3e 100644 --- a/pkg/music/provider/mpv/mpv.go +++ b/pkg/music/provider/mpv/mpv.go @@ -202,9 +202,21 @@ func (player *Player) PlaySong(song music.Song) error { defer player.mutex.Unlock() waitForLoad := make(chan bool) - player.eventEmitter.ListenOnce(EventFileLoaded, func(arguments ...interface{}) { + waitForLoadListener := player.eventEmitter.ListenOnce(EventFileLoaded, func(arguments ...interface{}) { waitForLoad <- true }) + defer player.eventEmitter.RemoveListener(EventFileLoaded, waitForLoadListener) + + waitForEOF := make(chan string) + waitForEOFListener := player.eventEmitter.ListenOnce(EventFileEnded, func(arguments ...any) { + mpvEvent := arguments[0].(*mpvipc.Event) + errStr, exists := mpvEvent.ExtraData["file_error"].(string) + if !exists { + errStr = "reasons" + } + waitForEOF <- errStr + }) + defer player.eventEmitter.RemoveListener(EventFileEnded, waitForEOFListener) // Start an event listener to wait for the file to load. _, err := player.connection.Call("loadfile", song.Path, "replace") @@ -219,6 +231,8 @@ func (player *Player) PlaySong(song music.Song) error { select { case <-waitForLoad: return nil + case errStr := <-waitForEOF: + return fmt.Errorf(errStr) case <-timeoutCtx.Done(): log.Printf("MpvControl.LoadFile: Load file timeout, did not receive file-loaded event in %d", mpvMaxLoadTimeout) _, err = player.connection.Call("stop") @@ -226,10 +240,8 @@ func (player *Player) PlaySong(song music.Song) error { log.Printf("MpvControl.LoadFile: Error calling stop after timeout: %v", err) return err } - return fmt.Errorf("error loading file, mpv did not respond in time") + return fmt.Errorf("MPV timeout") } - - return nil } func (player *Player) Play() error {