-
Notifications
You must be signed in to change notification settings - Fork 107
/
structs.go
121 lines (107 loc) · 3.25 KB
/
structs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
)
// DiscoveryData contains data about telly to expose in the HDHomeRun format for Plex detection.
type DiscoveryData struct {
FriendlyName string
Manufacturer string
ModelNumber string
FirmwareName string
TunerCount int
FirmwareVersion string
DeviceID string
DeviceAuth string
BaseURL string
LineupURL string
}
// UPNP returns the UPNP representation of the DiscoveryData.
func (d *DiscoveryData) UPNP() UPNP {
return UPNP{
SpecVersion: upnpVersion{
Major: 1, Minor: 0,
},
URLBase: d.BaseURL,
Device: upnpDevice{
DeviceType: "urn:schemas-upnp-org:device:MediaServer:1",
FriendlyName: d.FriendlyName,
Manufacturer: d.Manufacturer,
ModelName: d.ModelNumber,
ModelNumber: d.ModelNumber,
UDN: fmt.Sprintf("uuid:%s", d.DeviceID),
},
}
}
// LineupStatus exposes the status of the channel lineup.
type LineupStatus struct {
ScanInProgress convertibleBoolean
ScanPossible convertibleBoolean `json:",omitempty"`
Source string `json:",omitempty"`
SourceList []string `json:",omitempty"`
Progress int `json:",omitempty"` // Percent complete
Found int `json:",omitempty"` // Number of found channels
}
type upnpVersion struct {
Major int32 `xml:"major"`
Minor int32 `xml:"minor"`
}
type upnpDevice struct {
DeviceType string `xml:"deviceType"`
FriendlyName string `xml:"friendlyName"`
Manufacturer string `xml:"manufacturer"`
ModelName string `xml:"modelName"`
ModelNumber string `xml:"modelNumber"`
SerialNumber string `xml:"serialNumber"`
UDN string `xml:"UDN"`
}
// UPNP describes the UPNP/SSDP XML.
type UPNP struct {
XMLName xml.Name `xml:"urn:schemas-upnp-org:device-1-0 root"`
SpecVersion upnpVersion `xml:"specVersion"`
URLBase string `xml:"URLBase"`
Device upnpDevice `xml:"device"`
}
type convertibleBoolean bool
func (bit *convertibleBoolean) MarshalJSON() ([]byte, error) {
var bitSetVar int8
if *bit {
bitSetVar = 1
}
return json.Marshal(bitSetVar)
}
func (bit *convertibleBoolean) UnmarshalJSON(data []byte) error {
asString := string(data)
if asString == "1" || asString == "true" {
*bit = true
} else if asString == "0" || asString == "false" {
*bit = false
} else {
return fmt.Errorf("Boolean unmarshal error: invalid input %s", asString)
}
return nil
}
// MarshalXML used to determine if the element is present or not. see https://stackoverflow.com/a/46516243
func (bit *convertibleBoolean) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
var bitSetVar int8
if *bit {
bitSetVar = 1
}
return e.EncodeElement(bitSetVar, start)
}
// UnmarshalXML used to determine if the element is present or not. see https://stackoverflow.com/a/46516243
func (bit *convertibleBoolean) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var asString string
if decodeErr := d.DecodeElement(&asString, &start); decodeErr != nil {
return decodeErr
}
if asString == "1" || asString == "true" {
*bit = true
} else if asString == "0" || asString == "false" {
*bit = false
} else {
return fmt.Errorf("Boolean unmarshal error: invalid input %s", asString)
}
return nil
}