Skip to content

Commit

Permalink
Merge pull request #40 from jmillerv/example-config
Browse files Browse the repository at this point in the history
Add documentation
  • Loading branch information
jmillerv committed Dec 27, 2022
2 parents c5edc82 + a44e1ce commit 6239300
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ the config.yml.
### Web Radio
The `web_radio` file is able to take in a web radio address and play it through your go-dj.

**Note** thus far only .pls streams are provably working. An outstanding [issue](https://github.com/jmillerv/go-dj/issues/37) exists to dig into why some other
streams don't work.

## Feature Requests
I've built this out for my specific use case and released it to the public when I considered it feature complete. Suggestions are welcome for adding additional features.

Expand Down
45 changes: 45 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: 0.0.1
content:
PlayedPodcastTTL: "1m" # defaults to a month
CheckInterval: "1m" # defaults to 1 minute
Programs:
- Name: "Indie Pop Rocks"
Type: "web_radio"
Source: "https://somafm.com/indiepop.pls"
Timeslot:
Begin: "12:00AM"
End: "12:00PM"
- Name: "Tech Won't Save Us"
Type: "podcast"
Timeslot:
Begin: "12:00 AM"
End: "11:59:00 PM"
Source: "https://feeds.buzzsprout.com/1004689.rss"
- Name: "Democracy Now!"
Type: "podcast"
Timeslot:
Begin: "12:00 AM"
End: "11:59:00 PM"
Source: "https://www.democracynow.org/podcast.xml"
- Name: "gettysburg10"
Type: "file"
Timeslot:
Begin: "3:05:00 PM"
End: "10:00:00 PM"
Source: "./static/gettysburg10.wav"
- Name: "Piano Six Seconds"
Type: "file"
Timeslot:
Begin: "12:00:00 AM"
End: "11:59:00 PM"
Source: "./static/piano_six_seconds.mp3"
- Name: "exile (feat. Bon Iver)"
Type: "file"
Timeslot:
Begin: "9:54:00 PM"
End: "9:58:00 PM"
Source: "./static/04 exile (feat. bon iver).mp3"
- Name: "Taylor Swift Folder"
Type: "folder"
Timeslot: "afternoon"
Source: "./static/taylor_swift"
File renamed without changes.
131 changes: 131 additions & 0 deletions content/podcast_episodes_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package content

// file labeled _internal_test because none of these functions are public.

import (
"github.com/mmcdole/gofeed"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func Test_contains(t *testing.T) {
type args struct {
guids []string
episodeGuid string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Success: Returns True",
args: args{},
want: true,
},
{
name: "Success: Returns False",
args: args{},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := contains(tt.args.guids, tt.args.episodeGuid)
assert.ObjectsAreEqual(tt.want, got)
})
}
}

func Test_podcastCacheData_fromCache(t *testing.T) {
type fields struct {
Guids []string
TTY string
CacheDate time.Time
}
type args struct {
cacheData any
}
tests := []struct {
name string
fields fields
args args
want *podcastCacheData
}{
{},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &podcastCacheData{
Guids: tt.fields.Guids,
TTY: tt.fields.TTY,
CacheDate: tt.fields.CacheDate,
}
assert.Equalf(t, tt.want, p.fromCache(tt.args.cacheData), "fromCache(%v)", tt.args.cacheData)
})
}
}

func Test_podcasts_getNewestEpisode(t *testing.T) {
type fields struct {
Episodes []*gofeed.Item
}
tests := []struct {
name string
fields fields
want episode
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &podcasts{
Episodes: tt.fields.Episodes,
}
assert.Equalf(t, tt.want, p.getNewestEpisode(), "getNewestEpisode()")
})
}
}

func Test_podcasts_getOldestEpisode(t *testing.T) {
type fields struct {
Episodes []*gofeed.Item
}
tests := []struct {
name string
fields fields
want episode
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &podcasts{
Episodes: tt.fields.Episodes,
}
assert.Equalf(t, tt.want, p.getOldestEpisode(), "getOldestEpisode()")
})
}
}

func Test_podcasts_getRandomEpisode(t *testing.T) {
type fields struct {
Episodes []*gofeed.Item
}
tests := []struct {
name string
fields fields
want episode
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &podcasts{
Episodes: tt.fields.Episodes,
}
assert.Equalf(t, tt.want, p.getRandomEpisode(), "getRandomEpisode()")
})
}
}
81 changes: 81 additions & 0 deletions docs/first_time_setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Running go-dj on a fresh machine

These instructions come from getting this working on a fresh install of [DietPi]() running on a [Raspberry Pi 3 B+]() There
is an existing ticket to automate this process for ease of use.


## Install Go
1. mkdir ~/tmp
2. cd ~/tmp
3. wget https://go.dev/dl/go1.19.4.src.tar.gz
4. sudo tar -C /usr/local -xzf go1.19.4.src.tar.gz
5. add export PATH=$PATH:/usr/local/go/bin to .profile
6. source ~/.profile
7. go version
returns `go version go1.19.4 linux/arm64`

## Install dependencies
These are the dependencies that I installed during the process of troubleshooting. I need to go through and confirm what is/is not needed.

1. `sudo apt install libasound2 -y`
2. `sudo apt install alsa-utils -y`
3. `sudo apt-get install -y -qq libasound2-dev libssl-dev libpulse-dev libdbus-1-dev portaudio19-dev`
4. `sudo apt install build-essential`
5. `sudo apt install mpv` // this installs many of the previous packages, but I did this as step 5 when testing.

## Clone Repo
1. `cd ~/`
2. `mkdir dev`
3. `git clone https://github.com/jmillerv/go-dj`

## Build
1. `cd ~/dev/go-dj`
2. `go build`
3 chmod +x ./go-dj

## Add a config
1. cd ~/dev/go-dj
2. `mv config.example.yml config.yml`
3. populate the yaml with your desired content

## Configure your timezone
This will be different based on your OS and you may have done this during setup. I missed setting it to mine during the boot, so files weren't playing when I expected.

## Configure audio outputs
DietPi doesn't have the soundcards installed by default, I had to do this to get sound out of the 3.5mm jack. go-dj outputs to
wherever the default audio is sent to.

### Test your speakers
The following command will test the speakers without playing loud noise
`speaker-test -t wav -c 6`

To end the test press `ctrl+c`

## Run

./go-dj s

## Run on reboot
Should your SBC go down, you'll likely not want to have to reboot the daemon yourself.

1. open crontab
`crontab -e`
2. add command to file
`@rebott cd ~/dev/go && ./go-dj s`

## Killing the program
### Kill Signal
`Ctrl+C` will usually be enough to stop the program; however, there are known issues where it does not.

### Kill the process

Should you run into issues, knowing how to kill the program is useful

1. Get the process ID

`ps aux | grep go-dj`
should yeild something that looks like
`root 22328 0.0 1.2 1240808 12436 pts/0 Sl+ 02:03 0:00 ./go-dj s`

2. stop the process with the procdess ID
`kill -9 22328`
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
configFile = "config.dev.yml"
configFile = "config.yml"
)

func main() {
Expand Down

0 comments on commit 6239300

Please sign in to comment.