Play It Again

Turning a radio archive into an RSS feed

I found myself listening to a number of CHRW Radio programs via their program archives feature found on the website, but the 30 minute segments and no way to track progress proved to be a less than ideal user experience. Wanting to give Go a, ahem, go, I set out to improve on the listening experience. PlayAgain downloads a list of segments for each program episode, combines them, and generates an RSS feed entry which can then be picked up by any Podcast-supporting application. I use iTunes myself.

	
package progress

import (
	"fmt"
)

const barWidth = 60

type ProgressBar struct {
	Label    string
	Complete float64
}

func (p *ProgressBar) At(value int64, limit int64) {
	p.Complete = float64(value) / float64(limit)
	p.draw()
}

func (p *ProgressBar) Done() {
	fmt.Println()
}

func NewProgressBar(label string) *ProgressBar {
	return &ProgressBar{Label: label}
}

func (p *ProgressBar) draw() {
	fmt.Printf("\r%-15s[", p.Label)

	for i := 0; i < barWidth; i++ {
		if float64(i)/float64(barWidth) > p.Complete {
			fmt.Print(" ")
		} else {
			fmt.Print("#")
		}
	}

	fmt.Printf("] %3.0f%%", p.Complete*100.0)
}
	

PlayAgain is implemented as a simple command-line utility. As the MP3 files can be rather large in side, the code above displays the download progress to provide feedback to the user. Progress is displayed as a textulized progress bar [####          ] 20%.

Check it out the entire application on GitHub. Thanks to CHRW and those involved for creating the programs I have enjoyed.