Skip to content

Commit

Permalink
Merge pull request #3 from jmillerv/web-radio
Browse files Browse the repository at this point in the history
Add web radio support
  • Loading branch information
jmillerv committed Dec 1, 2021
2 parents 2ffc6a8 + 1ef03bc commit f348d0d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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 go-mp3 dependency.


## Supported Content

Expand All @@ -17,17 +22,17 @@ 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
- [ ] End web radio signal
- [x] Local File Support
- [ ] Randomized Programming
- [ ] Scheduled Programming
- [x] Local Folder support
- [ ] Remote file support
- [ ] Skip signal
- [ ] Stop signal
- [ ] Logging Options
- [ ] Recently played content cache

## Config Setup

Expand Down
6 changes: 5 additions & 1 deletion content/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
60 changes: 55 additions & 5 deletions content/web_radio.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit f348d0d

Please sign in to comment.