From f60be9df234697c7110824068470c80fe77edbb5 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Tue, 30 Nov 2021 23:36:43 -0700 Subject: [PATCH 1/6] update readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 35019de..a0ae9fe 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ The use case I built this for was automating content for an AM radio station I r Under the hood, this uses [beep](https://github.com/faiface/beep) to play the files. That package relies on [Oto](https://github.com/hajimehoshi/oto) which has dependencies that may need to be installed depending on the system you're running go-dj off of. +### Incompatibility Warning +MPEG 2.5 is not supported because of underlying dependencies. + ## Supported Content ### Local Files @@ -26,8 +29,10 @@ Folders are also supported and make the same directory assumptions as local file - [x] Local Folder support - [ ] Remote file support - [ ] Skip signal +- [ ] Play previous signal - [ ] Stop signal - [ ] Logging Options +- [ ] Recently played content cache ## Config Setup From e3b6b140661271d082e4f183669468a034e5a13e Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Wed, 1 Dec 2021 15:08:40 -0700 Subject: [PATCH 2/6] update readme --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0ae9fe..0268bea 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ The use case I built this for was automating content for an AM radio station I r ## Dependencies Under the hood, this uses [beep](https://github.com/faiface/beep) to play the files. That package relies on [Oto](https://github.com/hajimehoshi/oto) which has dependencies that may need to be installed depending on the system you're running go-dj off of. +[MPV](mpv.io) is used to support web radio streams. There are plans to remove this by making a package for dealing with web streams. ### Incompatibility Warning -MPEG 2.5 is not supported because of underlying dependencies. +MPEG 2.5 is not supported because of underlying go-mp3 dependency. + ## Supported Content @@ -20,16 +22,13 @@ Local files are support and the config assumes that they are located in the same Folders are also supported and make the same directory assumptions as local files. ## Roadmap -- [ ] Announcements - [ ] Podcast Support -- [ ] Web Radio Station Support +- [x] Web Radio Station Support - [x] Local File Support - [ ] Randomized Programming - [ ] Scheduled Programming - [x] Local Folder support - [ ] Remote file support -- [ ] Skip signal -- [ ] Play previous signal - [ ] Stop signal - [ ] Logging Options - [ ] Recently played content cache From 51cdfef4980186510f2bc93a95ee757c0f5e8038 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Wed, 1 Dec 2021 15:09:58 -0700 Subject: [PATCH 3/6] feat(program): add WebRadio --- content/program.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/content/program.go b/content/program.go index 8219483..df51fc4 100644 --- a/content/program.go +++ b/content/program.go @@ -37,7 +37,11 @@ func (p *Program) mediaFactory() Media { case *Podcast: panic("implement me") case *WebRadio: - panic("implement me") + radio := m.(*WebRadio) + radio.Name = p.Name + radio.URL = p.Source + log.Debugf("returning WebRadio: %v", formatter.StructToString(radio)) + return radio } return nil } From 567a66d16c1a3f96a563dd19e153a21da6f990d0 Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Wed, 1 Dec 2021 15:14:44 -0700 Subject: [PATCH 4/6] feat(web_radio): implement Get() and Play() --- content/web_radio.go | 60 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/content/web_radio.go b/content/web_radio.go index 6005681..bcc3e26 100644 --- a/content/web_radio.go +++ b/content/web_radio.go @@ -1,18 +1,68 @@ package content -// Not yet implemented +// This package uses a different library under the hood than beep for playing radio content. +// The plan is to eventually make a custom beep.StreamCloser for the use case of an infinite radio stream +// inspiration for this solution came from https://github.com/jcheng8/goradio + +import ( + log "github.com/sirupsen/logrus" + "io" + "os/exec" +) + +const player = "mpv" type WebRadio struct { - Name string - URL string + Name string + URL string + Player wrCommand +} + +type wrCommand struct { + playerName string + url string + isPlaying bool + command *exec.Cmd + in io.WriteCloser + out io.ReadCloser + pipeChan chan io.ReadCloser } +var wrc wrCommand + func (w *WebRadio) Get() { - panic("implement me") + var err error + wrc.playerName = player + wrc.url = w.URL + wrc.command = exec.Command(wrc.playerName, "-quiet", "-playlist", wrc.url) + wrc.in, err = wrc.command.StdinPipe() + if err != nil { + log.WithError(err).Error("error creating standard pipe in") + } + wrc.out, err = wrc.command.StdoutPipe() + if err != nil { + log.WithError(err).Error("error creating standard pipe out") + } + wrc.isPlaying = false + w.Player = wrc } func (w *WebRadio) Play() { - panic("implement me") + log.Infof("streaming from URL %v ", w.URL) + if !w.Player.isPlaying { + err := w.Player.command.Start() + if err != nil { + log.WithError(err).Error("error starting web radio player") + } + w.Player.isPlaying = true + done := make(chan bool) + func() { + w.Player.pipeChan <- w.Player.out + done <- true + }() + <-done + } + } func (w *WebRadio) Stop() { From 30441c484236bfbc244128d9f1c2185fe116be5f Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Wed, 1 Dec 2021 15:14:54 -0700 Subject: [PATCH 5/6] chore: update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0268bea..88dd1a4 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Folders are also supported and make the same directory assumptions as local file ## Roadmap - [ ] Podcast Support - [x] Web Radio Station Support +- [ ] End web radio signal - [x] Local File Support - [ ] Randomized Programming - [ ] Scheduled Programming From 1ef03bc002cb58736dcea5ae3f4cd6653411193d Mon Sep 17 00:00:00 2001 From: Jeremiah Date: Wed, 1 Dec 2021 15:15:01 -0700 Subject: [PATCH 6/6] chore: update gomod --- go.mod | 1 + go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/go.mod b/go.mod index a1175fa..56dc530 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/faiface/beep v1.1.0 // indirect github.com/google/martian v2.1.0+incompatible github.com/gopherjs/gopherwasm v1.0.0 // indirect + github.com/gordonklaus/portaudio v0.0.0-20200911161147-bb74aa485641 // indirect github.com/jmillerv/go-utilities v0.0.0-20211009175413-077cd5304cea github.com/mmcdole/gofeed v1.1.3 // indirect github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index ee9d715..4fc2dc3 100644 --- a/go.sum +++ b/go.sum @@ -159,6 +159,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherwasm v1.0.0/go.mod h1:SkZ8z7CWBz5VXbhJel8TxCmAcsQqzgWGR/8nMhyhZSI= +github.com/gordonklaus/portaudio v0.0.0-20200911161147-bb74aa485641 h1:B7ADnac3Yy6Vtcp2mstnsjUtarYcjy4AL0R6eNEhZAk= +github.com/gordonklaus/portaudio v0.0.0-20200911161147-bb74aa485641/go.mod h1:HfYnZi/ARQKG0dwH5HNDmPCHdLiFiBf+SI7DbhW7et4= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hajimehoshi/go-mp3 v0.3.0 h1:fTM5DXjp/DL2G74HHAs/aBGiS9Tg7wnp+jkU38bHy4g= github.com/hajimehoshi/go-mp3 v0.3.0/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=