Compare commits

..

No commits in common. "29b160388678213201460638fcc58f3a7ce1199f" and "33f7405404bc2f648c6e814bbeb5fea0ac62e0d7" have entirely different histories.

2 changed files with 13 additions and 16 deletions

View File

@ -2,9 +2,7 @@ bbc-on-ice
==========
'bbc-on-ice' is a SHOUTcast (ICY protocol) bridge for BBC radio streams.
It adds metadata to the stream so that media players can display it. There are
some inherent technical limitations to how accurate the information can be
but it's definitely better to have an approximate title than nothing.
It adds metadata to the stream so that media players can display it.
Packages
--------

25
main.go
View File

@ -122,22 +122,21 @@ func resolveM3U8(target string) (out []string, err error) {
func metaProc(ctx context.Context, name string, out chan<- string) {
defer close(out)
// "polling_timeout" seems to normally be 25 seconds, which is a lot,
// especially considering all the possible additional buffering.
const maxInterval = 5 * time.Second
var current, last string
var interval time.Duration
for {
meta, err := getMeta(name)
if err != nil {
current = name + " - " + err.Error()
interval = maxInterval
current = "Error: " + err.Error()
interval = 30 * time.Second
} else {
current = meta.title
interval = time.Duration(meta.timeout) * time.Millisecond
if interval > maxInterval {
interval = maxInterval
interval = time.Duration(meta.timeout)
// It seems to normally use 25 seconds which is a lot,
// especially considering all the possible additional buffering.
if interval > 5000 {
interval = 5000
}
}
if current != last {
@ -150,7 +149,7 @@ func metaProc(ctx context.Context, name string, out chan<- string) {
}
select {
case <-time.After(interval):
case <-time.After(time.Duration(interval) * time.Millisecond):
case <-ctx.Done():
return
}
@ -180,9 +179,9 @@ func urlProc(ctx context.Context, playlistURL string, out chan<- string) {
return
}
}
// Media players will happily buffer the whole playlist at once,
// a small (less than target duration) additional pause is appropriate.
time.Sleep(3 * time.Second)
// I expect this to be mainly driven by the buffered channel but
// a small (less than target duration) additional pause will not hurt.
time.Sleep(1 * time.Second)
}
}