Skip to content

Commit

Permalink
Merge pull request #2 from jmillerv/local-folder
Browse files Browse the repository at this point in the history
Implement Local Folder Functionality
  • Loading branch information
jmillerv committed Nov 7, 2021
2 parents c4390fd + e7c5eb2 commit 7ee9979
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ 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.

## Supported Content

### Local Files
Local files are support and the config assumes that they are located in the same directory as the deamon.

### Local Folder
Folders are also supported and make the same directory assumptions as local files.

## Roadmap
- [ ] Announcements
- [ ] Podcast Support
- [ ] Web Radio Station Support
- [x] Local File Support
- [ ] Randomized Programming
- [ ] Scheduled Programming
- [ ] Local Folder support
- [x] Local Folder support
- [ ] Remote file support
- [ ] Skip signal
- [ ] Stop signal

## Config Setup

Expand Down
2 changes: 0 additions & 2 deletions content/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"time"
)

// Not yet implemented

type LocalFile struct {
Name string
Content *os.File
Expand Down
49 changes: 49 additions & 0 deletions content/folder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package content

import (
log "github.com/sirupsen/logrus"
"io/fs"
"io/ioutil"
)

// The folder structure exists because I didn't want to load an entire folder's worth
// of songs into memory like the LocalFile struct does.

// Folder is a struct for parsing folders that implements the Media interface
type Folder struct {
Name string
Content *[]fs.FileInfo
Path string
}

func (f *Folder) Get() {
log.Infof("buffering files from %s", f.Path)
folder, err := ioutil.ReadDir(f.Path)
if err != nil {
log.WithError(err).Error("unable to read folder from path")
}
f.Content = &folder
}

func (f *Folder) Play() {
// loop through the folder and play each as a local file
for _, file := range *f.Content {
l := f.getLocalFile(file)
l.Play()
}

panic("implement me")
}

func (f *Folder) Stop() {
panic("implement me")
}

func (f *Folder) getLocalFile(file fs.FileInfo) *LocalFile {
l := &LocalFile{
Name: file.Name(),
Path: f.Path + "/" + file.Name(),
}
l.Get()
return l
}
2 changes: 2 additions & 0 deletions content/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
announcementContent MediaType = "announcement"
webRadioContent MediaType = "web_radio"
fileContent MediaType = "file"
folderContent MediaType = "folder"
)

type MediaType string
Expand All @@ -14,6 +15,7 @@ var MediaTypeMap = map[MediaType]Media{
announcementContent: new(Announcement),
webRadioContent: new(WebRadio),
fileContent: new(LocalFile),
folderContent: new(Folder),
}

type Media interface {
Expand Down
6 changes: 6 additions & 0 deletions content/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func (p *Program) mediaFactory() Media {
switch m.(type) {
case *Announcement:
panic("implement me")
case *Folder:
folder := m.(*Folder)
folder.Name = p.Name
folder.Path = p.Source
log.Debugf("returning Folder: %v", formatter.StructToString(folder))
return folder
case *LocalFile:
file := m.(*LocalFile)
file.Name = p.Name
Expand Down

0 comments on commit 7ee9979

Please sign in to comment.