Compare commits

...

4 Commits

Author SHA1 Message Date
29b1603886 Update README 2018-11-03 01:57:59 +01:00
131930f45b Increase playlist re-read pause 2018-11-03 01:04:22 +01:00
783fce1175 Fix metadata timeouts 2018-11-03 00:54:50 +01:00
23683424a6 Show station name even on metadata error 2018-11-02 22:56:43 +01:00
2 changed files with 16 additions and 13 deletions

View File

@@ -2,7 +2,9 @@ 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.
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.
Packages
--------

25
main.go
View File

@@ -122,21 +122,22 @@ 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 = "Error: " + err.Error()
interval = 30 * time.Second
current = name + " - " + err.Error()
interval = maxInterval
} else {
current = meta.title
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
interval = time.Duration(meta.timeout) * time.Millisecond
if interval > maxInterval {
interval = maxInterval
}
}
if current != last {
@@ -149,7 +150,7 @@ func metaProc(ctx context.Context, name string, out chan<- string) {
}
select {
case <-time.After(time.Duration(interval) * time.Millisecond):
case <-time.After(interval):
case <-ctx.Done():
return
}
@@ -179,9 +180,9 @@ func urlProc(ctx context.Context, playlistURL string, out chan<- string) {
return
}
}
// 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)
// 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)
}
}