123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package main
- import (
- "fmt"
- "io"
- "log"
- "net/http"
- "red-green/glom"
- "github.com/beego/x2j"
- )
- func Post(where string) *http.Response {
- resp, err := http.PostForm(where, nil)
- if err != nil {
- log.Printf("POST got non 200 code, %v", err)
- }
- return resp
- }
- func Get(where string) *http.Response {
- resp, err := http.Get(where)
- if err != nil {
- log.Printf("GET got non 200 code, %v", err)
- return nil
- } else {
- return resp
- }
- }
- func KeyPress(ip, command string) string {
- return fmt.Sprintf("http://%s:8060/keypress/%s", ip, command)
- }
- func Query(ip, what string) string {
- return fmt.Sprintf("http://%s:8060/query/%s", ip, what)
- }
- func PerformKey(ip, command string) {
- Post(KeyPress(ip, command))
- }
- func GetCurrentPlay(ip string) map[string]interface{} {
- resp := Get(Query(ip, "media-player"))
- if resp == nil {
- return nil
- }
- body, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Printf("Reading from body got error, %v", err)
- }
- r := make(map[string]interface{})
- err = x2j.Unmarshal(body, &r)
- if err != nil {
- log.Printf("Got a error parsing XML, %v", err)
- }
- return r
- }
- func GetQuery(ip, command string) map[string]interface{} {
- resp := Get(Query(ip, command))
- if resp == nil {
- return nil
- }
- body, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Printf("Reading from body got error, %v", err)
- }
- r := make(map[string]interface{})
- err = x2j.Unmarshal(body, &r)
- if err != nil {
- log.Printf("Got a error parsing XML, %v", err)
- }
- return r
- }
- func DebugInfo(ip string) string {
-
- r := GetQuery(ip, "media-player")
- if r == nil {
- return ""
- }
- name, _ := glom.Glom(r, "player.plugin.-name")
- id, _ := glom.Glom(r, "player.plugin.-id")
-
-
- fmt.Printf("Name: %v (%v)\r\n", name, id)
-
- return fmt.Sprintf("%v (%v)", name, id)
- }
- func examplePost() {
- keys := GetKeys()
- _ = keys
- PerformKey("192.168.254.75", keys["mute"])
-
-
-
-
- r := GetQuery("192.168.254.75", "media-player")
- name, _ := glom.Glom(r, "player.plugin.-name")
- id, _ := glom.Glom(r, "player.plugin.-id")
- r1 := GetQuery("192.168.254.75", "tv-channels")
- chan_name, _ := glom.Glom(r1, "tv-channels.channel.name")
- chan_phy_id, _ := glom.Glom(r1, "tv-channels.channel.physical-channel")
- chan_number, _ := glom.Glom(r1, "tv-channels.channel.number")
-
- fmt.Printf("Name: %v (%v)\r\n", name, id)
- fmt.Printf("Channel: %v (%v / %v)\r\n", chan_name, chan_phy_id, chan_number)
- }
|