Browse Source

refactor(device-info): working on removing glom, supporting device info as struct

I have device-info as a structure so it's GetQuery can now return a DeviceInfo structure, unfortunatly we are not done with GetQuery, it also has media-player which needs to be handled by a MediaPlayer structure. (Then after all that we are ready to remove the dependency on glom and that struct lib it uses)

Please see issue #4
Apollo 2 years ago
parent
commit
0e62ab359c
3 changed files with 96 additions and 3 deletions
  1. 6 0
      .gitignore
  2. 74 0
      device_info.go
  3. 16 3
      poster.go

+ 6 - 0
.gitignore

@@ -29,3 +29,9 @@ WOL.txt
 
 # Exclude Log files
 *.log
+
+# Exclude temp folder for storing xml
+xmls
+
+# Exclude the roku.pid file created by daemon flag
+roku.pid

+ 74 - 0
device_info.go

@@ -0,0 +1,74 @@
+package main
+
+type DeviceInfo struct {
+	Udn                         string  `xml:"udn"`
+	SerialNumber                string  `xml:"serial-number"`
+	DeviceId                    string  `xml:"device-id"`
+	AdvertisingId               string  `xml:"advertising-id"`
+	VendorName                  string  `xml:"vendor-name"`
+	ModelName                   string  `xml:"model-name"`
+	ModelNumber                 string  `xml:"model-number"`
+	ModelRegion                 string  `xml:"model-region"`
+	IsTv                        bool    `xml:"is-tv"`
+	IsStick                     bool    `xml:"is-stick"`
+	ScreenSize                  int     `xml:"screen-size"`
+	PanelId                     int     `xml:"panel-id"`
+	UiResolution                string  `xml:"ui-resolution"`
+	TunerType                   string  `xml:"tuner-type"`
+	SupportsEthernet            bool    `xml:"supports-ethernet"`
+	WifiMac                     string  `xml:"wifi-mac"`
+	WifiDriver                  string  `xml:"wifi-driver"`
+	HasWifiExtender             bool    `xml:"has-wifi-extender"`
+	HasWifi5GSupport            bool    `xml:"has-wifi-5G-support"`
+	CanUseWifiExtender          bool    `xml:"can-use-wifi-extender"`
+	EthernetMac                 string  `xml:"ethernet-mac"`
+	NetworkType                 string  `xml:"network-type"`
+	FriendlyDeviceName          string  `xml:"friendly-device-name"` // Contains html
+	FriendlyModelName           string  `xml:"friendly-model-name"`  // Contains unicode
+	DefaultDeviceName           string  `xml:"default-device-name"`  // Contains unicode
+	UserDeviceName              string  `xml:"user-device-name"`     // Contains html
+	UserDeviceLocation          string  `xml:"user-device-location"`
+	BuildNumber                 string  `xml:"build-number"`
+	SoftwareVersion             string  `xml:"software-version"`
+	SoftwareBuild               string  `xml:"software-build"`
+	SecureDevice                bool    `xml:"secure-device"`
+	Language                    string  `xml:"language"`
+	Country                     string  `xml:"country"`
+	Locale                      string  `xml:"locale"`
+	TimeZoneAuto                bool    `xml:"time-zone-auto"`
+	TimeZone                    string  `xml:"time-zone"`
+	TimeZoneName                string  `xml:"time-zone-name"`
+	TimeZoneTz                  string  `xml:"time-zone-tz"`
+	TimeZoneOffset              int     `xml:"time-zone-offset"`
+	ClockFormat                 string  `xml:"clock-format"`
+	Uptime                      int     `xml:"uptime"`
+	PowerMode                   string  `xml:"power-mode"`
+	SupportsSuspend             bool    `xml:"supports-suspend"`
+	SupportsFindRemote          bool    `xml:"supports-find-remote"`
+	SupportsAudioGuide          bool    `xml:"supports-audio-guide"`
+	SupportsRva                 bool    `xml:"supports-rva"`
+	DeveloperEnabled            bool    `xml:"developer-enabled"`
+	KeyedDeveloperId            string  `xml:"keyed-developer-id"` // This was just a xml close with no information
+	SearchEnabled               bool    `xml:"search-enabled"`
+	SearchChannelsEnabled       bool    `xml:"search-channels-enabled"`
+	VoiceSearchEnabled          bool    `xml:"voice-search-enabled"`
+	NotificationsEnabled        bool    `xml:"notifications-enabled"`
+	NotificationsFirstUse       bool    `xml:"notifications-first-use"`
+	SupportsPrivateListening    bool    `xml:"supports-private-listening"`
+	SupportsPrivateListeningDtv bool    `xml:"supports-private-listening-dtv"`
+	SupportsWarmStandby         bool    `xml:"supports-warm-standby"`
+	HeadphonesConnected         bool    `xml:"headphones-connected"`
+	SupportsAudioSettings       bool    `xml:"supports-audio-settings"`
+	ExpertPqEnabled             float32 `xml:"expert-pq-enabled"`
+	SupportsEcsTextedit         bool    `xml:"supports-ecs-textedit"`
+	SupportsEcsMicrophone       bool    `xml:"supports-ecs-microphone"`
+	SupportsWakeOnWLan          bool    `xml:"supports-wake-on-wlan"` // Needed for sending etherwake Wake On Lan (WOL)
+	SupportsAirplay             bool    `xml:"supports-airplay"`
+	HasPlayOnRoku               bool    `xml:"has-play-on-roku"`
+	SupportUrl                  string  `xml:"support-url"` // web-link
+	GrandcentralVersion         string  `xml:"grandcentral-version"`
+	TrcVersion                  string  `xml:"trc-version"`
+	TrcChannelVersion           string  `xml:"trc-channel-version"`
+	DavinciVersion              string  `xml:"davinci-version"`
+	AvSyncCalibrationEnabled    float32 `xml:"av-sync-calibration-enabled"`
+}

+ 16 - 3
poster.go

@@ -5,6 +5,7 @@ import (
 	"io"
 	"log"
 	"net/http"
+	"os"
 	"strings"
 
 	"github.com/beanzilla/glom"
@@ -133,20 +134,32 @@ func PerformKey(ip, command string) bool {
 }
 
 func GetQuery(ip, command string) map[string]interface{} {
-	resp := Get(Query(ip, command))
+	var resp *http.Response = Get(Query(ip, command))
 	if resp == nil {
 		return nil
 	}
-	body, err := io.ReadAll(resp.Body)
+	var body []byte
+	var err error
+	body, err = io.ReadAll(resp.Body)
 	if err != nil {
 		log.Printf("Reading from body got error, %v", err)
 	}
-	r := make(map[string]interface{})
+	// Change this so it's xml parsing it into a real struct (bye glom, your too ugly)
+	var r map[string]interface{} = make(map[string]interface{})
 	err = x2j.Unmarshal(body, &r)
 	if err != nil {
 		log.Printf("Got a error parsing XML, %v", err)
 	}
 	defer resp.Body.Close()
+	// Save to file, for real pros
+	if !FileExists("xmls") {
+		os.Mkdir("xmls", 0660)
+	}
+	var filename string = fmt.Sprintf("xmls/%s.xml", command)
+	err = os.WriteFile(filename, body, 0660)
+	if err != nil {
+		log.Printf("Got a error printing out xml to file '%s', %v", filename, err)
+	}
 	return r
 }