clone

a desktop tv and program guide for over-the-air broadcasts: what's on air, what your tuner gets, live tv, recordings

Read channel numbers Tvheadend writes as strings

FelineStateMachine committed 3febc87
A scanned ATSC channel's number comes back as "14.1" rather than the
packed integer, which stopped the antenna lineup from loading. Names lose
the padding some stations send.
commit
3febc87e2cc69b4c3bf7ca3bd1e3e33ca717aaa0
parent
1b49589c385a1f85374e287f46985396a4fe37aa
author
FelineStateMachine <226808055+FelineStateMachine@users.noreply.github.com>
2 files changed, +51 -6
Minternal/tvh/setup_test.go26+++++++++++++++++++++++++
Minternal/tvh/tvh.go31++++++++++++++++++++++++------
M internal/tvh/setup_test.go +26 -0
M internal/tvh/tvh.go +25 -6
@@ -7,6 +7,7 @@ package tvh
77 88 import (99 "bytes"10+ "cmp"1011 "context"1112 "encoding/json"1213 "fmt"
@@ -57,11 +58,11 @@ type Channel struct {
5758 func (c *Client) Channels(ctx context.Context) ([]Channel, error) {5859 var body struct {5960 Entries []struct {60- UUID string `json:"uuid"`61- Name string `json:"name"`62- Number int64 `json:"number"`63- Enabled bool `json:"enabled"`64- Services []string `json:"services"`61+ UUID string `json:"uuid"`62+ Name string `json:"name"`63+ Number gridNumber `json:"number"`64+ Enabled bool `json:"enabled"`65+ Services []string `json:"services"`6566 } `json:"entries"`6667 }6768 if err := c.get(ctx, "/api/channel/grid", url.Values{"limit": {"5000"}}, &body); err != nil {
@@ -69,7 +70,7 @@ func (c *Client) Channels(ctx context.Context) ([]Channel, error) {
6970 }7071 out := make([]Channel, 0, len(body.Entries))7172 for _, e := range body.Entries {72- out = append(out, Channel{UUID: e.UUID, Name: e.Name, Number: FormatNumber(e.Number), Enabled: e.Enabled, Services: e.Services})73+ out = append(out, Channel{UUID: e.UUID, Name: strings.TrimSpace(e.Name), Number: cmp.Or(string(e.Number), "0"), Enabled: e.Enabled, Services: e.Services})7374 }7475 return out, nil7576 }
@@ -100,6 +101,24 @@ func (c *Client) ServiceStreams(ctx context.Context, serviceUUID string) ([]Stre
100101 return out, nil101102 }102103 104+// gridNumber is a channel number as the channel grid writes it: a packed105+// integer (7000001), or for a real ATSC channel a string ("7.1").106+type gridNumber string107+108+func (n *gridNumber) UnmarshalJSON(raw []byte) error {109+ var s string110+ if err := json.Unmarshal(raw, &s); err == nil {111+ *n = gridNumber(strings.TrimSpace(s))112+ return nil113+ }114+ var packed int64115+ if err := json.Unmarshal(raw, &packed); err != nil {116+ return fmt.Errorf("channel number %s: %w", raw, err)117+ }118+ *n = gridNumber(FormatNumber(packed))119+ return nil120+}121+103122 // FormatNumber renders a packed channel number: 7000001 → "7.1", 27 → "27".104123 func FormatNumber(n int64) string {105124 major, minor := n/numberSplit, n%numberSplit