Skip to content

Commit

Permalink
Merge pull request #33 from jmillerv/29-add-oldest-random-support-to-…
Browse files Browse the repository at this point in the history
…podcastplayorder

29 add oldest random support to podcastplayorder
  • Loading branch information
jmillerv authored Dec 11, 2022
2 parents ec2e2b7 + 0117136 commit e95da93
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 85 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ At the moment go-dj only supports local files.
go-dj recognizes four types of content `file`, `folder`, `podcast`, `web_radio`


### File
The `file` type is intended to be a local file; however, I see the use case for being able to pull files from URLs and will
eventually add that functionality

### Podcast
The `podcast` file is for podcasts with published RSS feeds. go-dj will parse the RSS and select from there.

The podcast type defaults to playing newest. If the oldest or random flags are passed, podcasts will play in those orders.
An improvement on this would be to allow this to be set on a per podcast basis in 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.

## Feature Requests
Expand Down
28 changes: 0 additions & 28 deletions content/announcement.go

This file was deleted.

46 changes: 0 additions & 46 deletions content/announcement_test.go

This file was deleted.

9 changes: 3 additions & 6 deletions content/podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Podcast struct {
Name string
URL string
Player streamPlayer
PlayOrder PlayOrder // options: newest, oldest, random
PlayOrder PlayOrder
}

type PlayOrder string
Expand All @@ -43,15 +43,12 @@ func (p *Podcast) Get() error {
ep = pods.getNewestEpisode()
break
case playOrderOldest:
log.Panic("implement me")
//ep = pods.getOldestEpisode()
ep = pods.getOldestEpisode()
case playOrderRandom:
log.Panic("implement me")
//ep = pods.getRandomEpisode()
ep = pods.getRandomEpisode()
}

// setup podcast stream
log.Infof("extension: %v", ep.EpExtension)
podcastStream.playerName = streamPlayerName
podcastStream.url = ep.EpURL
podcastStream.command = exec.Command(podcastStream.playerName, "-quiet", podcastStream.url)
Expand Down
8 changes: 4 additions & 4 deletions content/podcast_episodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (p *podcasts) getNewestEpisode() episode {
return newestEpisode
}

func (p *podcasts) getOldestEpisode() *episode {
var oldestEpisode *episode
func (p *podcasts) getOldestEpisode() episode {
var oldestEpisode episode
var date *time.Time
// TODO if played, log that it's in the cache, and skip to the next episode
for _, ep := range p.Episodes {
Expand All @@ -43,8 +43,8 @@ func (p *podcasts) getOldestEpisode() *episode {
return oldestEpisode
}

func (p *podcasts) getRandomEpisode() *episode {
var randomEpisode *episode
func (p *podcasts) getRandomEpisode() episode {
var randomEpisode episode
rand.Seed(time.Now().UnixNano())
item := p.Episodes[rand.Intn(len(p.Episodes))]
// TODO if played, log that it's in the cache, and skip to the next episode
Expand Down
14 changes: 13 additions & 1 deletion content/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type Program struct {
Type MediaType
}

var (
PodcastPlayOrderRandom bool
PodcastPlayerOrderOldest bool
)

func (p *Program) GetMedia() Media {
media := p.mediaFactory()
return media
Expand All @@ -36,7 +41,14 @@ func (p *Program) mediaFactory() Media {
podcast := m.(*Podcast)
podcast.Name = p.Name
podcast.URL = p.Source
podcast.PlayOrder = "newest" // TODO: Add support for random, oldest, and set from PlayOrder from config.
podcast.PlayOrder = playOrderNewest // default
if PodcastPlayerOrderOldest == true {
podcast.PlayOrder = playOrderOldest
}
if PodcastPlayOrderRandom == true {
podcast.PlayOrder = playOrderRandom
}

log.Debugf("returning podcast: %v", formatter.StructToString(podcast))
return podcast
case *WebRadio:
Expand Down
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ func main() {
Hidden: false,
Destination: &content.Shuffled,
},
cli.BoolFlag{
Name: "pod-oldest",
Usage: "podcasts will play starting with the oldest first",
Required: false,
Hidden: false,
Destination: &content.PodcastPlayerOrderOldest,
},
cli.BoolFlag{
Name: "pod-random",
Usage: "podcasts will play in a random order",
Required: false,
Hidden: false,
Destination: &content.PodcastPlayOrderRandom,
},
},
},
},
Expand All @@ -59,3 +73,9 @@ func main() {
log.Fatal(err)
}
}

func init() {
content.Shuffled = false
content.PodcastPlayerOrderOldest = false
content.PodcastPlayOrderRandom = false
}

0 comments on commit e95da93

Please sign in to comment.