diff --git a/flagfuncs.go b/flagfuncs.go index fbdd1062..618fad8f 100644 --- a/flagfuncs.go +++ b/flagfuncs.go @@ -110,7 +110,7 @@ func checkTflag() error { return err } } else { - // Validate URL before proceeding + // Validate URL before proceeding. _, err := url.ParseRequestURI(*targetPtr) if err != nil { return err diff --git a/go2tv.go b/go2tv.go index c5c0b1a4..b49fc873 100644 --- a/go2tv.go +++ b/go2tv.go @@ -82,11 +82,11 @@ func main() { s := httphandlers.NewServer(whereToListen) // We pass the tvdata here as we need the callback handlers to be able to - // react to the different Media Renderer states + // react to the different media renderer states. go func() { s.ServeFiles(serverStarted, absVideoFile, absSubtitlesFile, &httphandlers.TVPayload{Soapcalls: *tvdata}) }() - // Wait for HTTP server to properly initialize + // Wait for HTTP server to properly initialize. <-serverStarted if err := tvdata.SendtoTV("Play"); err != nil { @@ -95,7 +95,7 @@ func main() { } initializeCloseHandler(*tvdata) - // Sleep forever + // Sleep forever. select {} } @@ -106,7 +106,7 @@ func loadSSDPservices() error { } counter := 0 for _, srv := range list { - // We only care about the AVTransport services + // We only care about the AVTransport services. if srv.Type == "urn:schemas-upnp-org:service:AVTransport:1" { counter++ devices[counter] = []string{srv.Server, srv.Location} diff --git a/httphandlers/httphandlers.go b/httphandlers/httphandlers.go index 7acaff0d..038208cc 100644 --- a/httphandlers/httphandlers.go +++ b/httphandlers/httphandlers.go @@ -13,13 +13,13 @@ import ( "github.com/alexballas/go2tv/soapcalls" ) -// filesToServe defines the files we need to serve +// filesToServe defines the files we need to serve. type filesToServe struct { Video string Subtitles string } -// HTTPserver - new http.Server instance +// HTTPserver - new http.Server instance. type HTTPserver struct { http *http.Server mux *http.ServeMux @@ -27,12 +27,12 @@ type HTTPserver struct { // TVPayload - We need some of the soapcalls magic in // this package too. We need to expose the ControlURL -// to the callback handler +// to the callback handler. type TVPayload struct { Soapcalls soapcalls.TVPayload } -// ServeFiles - Start HTTP server and serve file +// ServeFiles - Start HTTP server and serve the files. func (s *HTTPserver) ServeFiles(serverStarted chan<- struct{}, videoPath, subtitlesPath string, tvpayload *TVPayload) { files := &filesToServe{ @@ -55,7 +55,7 @@ func (s *HTTPserver) ServeFiles(serverStarted chan<- struct{}, videoPath, subtit } -// StopServeFiles - Kill the HTTP server +// StopServeFiles - Kill the HTTP server. func (s *HTTPserver) StopServeFiles() { s.http.Close() } @@ -124,13 +124,13 @@ func (p *TVPayload) callbackHandler(w http.ResponseWriter, req *http.Request) { return } - // If the uuid is not one of the UUIDs we storred in + // If the uuid is not one of the UUIDs we stored in // soapcalls.InitialMediaRenderersStates it means that // probably it expired and there is not much we can do // with it. Trying to send an unsubscribe for those will // probably result in a 412 error as per the upnpn documentation // http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf - // (page 94) + // (page 94). if soapcalls.InitialMediaRenderersStates[uuid] == true { p.Soapcalls.Mu.Lock() soapcalls.MediaRenderersStates[uuid] = map[string]string{ @@ -145,7 +145,6 @@ func (p *TVPayload) callbackHandler(w http.ResponseWriter, req *http.Request) { if newstate == "PLAYING" { fmt.Println("Received: Playing") } - if newstate == "PAUSED_PLAYBACK" { fmt.Println("Received: Paused") } @@ -154,12 +153,12 @@ func (p *TVPayload) callbackHandler(w http.ResponseWriter, req *http.Request) { p.Soapcalls.UnsubscribeSoapCall(uuid) os.Exit(0) } - // TODO - Properly reply to that + // TODO - Properly reply to that. fmt.Fprintf(w, "OK\n") return } -// NewServer - create a new HTTP server +// NewServer - create a new HTTP server. func NewServer(a string) HTTPserver { srv := HTTPserver{ http: &http.Server{Addr: a}, diff --git a/soapcalls/soapbuilders.go b/soapcalls/soapbuilders.go index ba5dbf6c..f966a059 100644 --- a/soapcalls/soapbuilders.go +++ b/soapcalls/soapbuilders.go @@ -6,7 +6,7 @@ import ( "fmt" ) -// PlayEnvelope - As in Play Pause Stop +// PlayEnvelope - As in Play Pause Stop. type PlayEnvelope struct { XMLName xml.Name `xml:"s:Envelope"` Schema string `xml:"xmlns:s,attr"` @@ -28,7 +28,7 @@ type PlayAction struct { Speed string } -// StopEnvelope - As in Play Pause Stop +// StopEnvelope - As in Play Pause Stop. type StopEnvelope struct { XMLName xml.Name `xml:"s:Envelope"` Schema string `xml:"xmlns:s,attr"` @@ -189,7 +189,7 @@ func setAVTransportSoapBuild(videoURL, subtitleURL string) ([]byte, error) { fmt.Println(err) return make([]byte, 0), err } - // That looks like an issue just with my SamsungTV + // That looks like an issue just with my Samsung TV. b = bytes.ReplaceAll(b, []byte("""), []byte(`"`)) b = bytes.ReplaceAll(b, []byte("&"), []byte("&")) diff --git a/soapcalls/soapcallers.go b/soapcalls/soapcallers.go index 75daddf7..063afdad 100644 --- a/soapcalls/soapcallers.go +++ b/soapcalls/soapcallers.go @@ -12,13 +12,13 @@ import ( "time" ) -// MediaRenderersStates - We hold the states and uuids here +// MediaRenderersStates - We hold the states and uuids here. var MediaRenderersStates = make(map[string]map[string]string) -// InitialMediaRenderersStates - Just storing the subscription uuids here +// InitialMediaRenderersStates - Just storing the subscription uuids here. var InitialMediaRenderersStates = make(map[string]interface{}) -// TVPayload - this is the heard of Go2TV +// TVPayload - this is the heard of Go2TV. type TVPayload struct { TransportURL string VideoURL string @@ -57,7 +57,7 @@ func (p *TVPayload) setAVTransportSoapCall() error { return nil } -// PlayStopSoapCall - Build and call the play soap call +// PlayStopSoapCall - Build and call the play soap call. func (p *TVPayload) playStopSoapCall(action string) error { parsedURLtransport, err := url.Parse(p.TransportURL) if err != nil { @@ -95,7 +95,7 @@ func (p *TVPayload) playStopSoapCall(action string) error { } // SubscribeSoapCall - Subscribe to a media renderer -// If we explicetely pass the uuid, then we refresh it instead. +// If we explicitly pass the uuid, then we refresh it instead. func (p *TVPayload) SubscribeSoapCall(uuidInput string) error { parsedURLcontrol, err := url.Parse(p.ControlURL) @@ -144,7 +144,7 @@ func (p *TVPayload) SubscribeSoapCall(uuidInput string) error { uuid = strings.TrimLeft(uuid, "uuid:") // We don't really need to initialize or set - // the State if we're just refreshing the uuid + // the State if we're just refreshing the uuid. if uuidInput == "" { p.Mu.Lock() InitialMediaRenderersStates[uuid] = true @@ -161,8 +161,8 @@ func (p *TVPayload) SubscribeSoapCall(uuidInput string) error { return nil } -// UnsubscribeSoapCall - exported that as we use it for the callback stuff -// in the httphandlers package +// UnsubscribeSoapCall - exported that as we use +// it for the callback stuff in the httphandlers package. func (p *TVPayload) UnsubscribeSoapCall(uuid string) error { parsedURLcontrol, err := url.Parse(p.ControlURL) if err != nil { @@ -197,7 +197,7 @@ func (p *TVPayload) UnsubscribeSoapCall(uuid string) error { return nil } -// RefreshLoopUUIDSoapCall - Refresh the UUID +// RefreshLoopUUIDSoapCall - Refresh the UUID. func (p *TVPayload) RefreshLoopUUIDSoapCall(uuid, timeout string) error { var triggerTime int timeoutInt, err := strconv.Atoi(timeout) @@ -205,7 +205,7 @@ func (p *TVPayload) RefreshLoopUUIDSoapCall(uuid, timeout string) error { return err } - // Refresh token after after Timeout / 2 seconds + // Refresh token after after Timeout / 2 seconds. if timeoutInt > 1 { triggerTime = timeoutInt / 2 } @@ -226,7 +226,7 @@ func (p *TVPayload) refreshLoopUUIDAsyncSoapCall(uuid string) func() { } } -// SendtoTV - Send to tv +// SendtoTV - Send to TV. func (p *TVPayload) SendtoTV(action string) error { if action == "Play" { if err := p.SubscribeSoapCall(""); err != nil { @@ -239,7 +239,7 @@ func (p *TVPayload) SendtoTV(action string) error { } if action == "Stop" { - // Cleaning up all uuids on force stop + // Cleaning up all uuids on force stop. for uuids := range MediaRenderersStates { p.UnsubscribeSoapCall(uuids) } diff --git a/soapcalls/xmlparsers.go b/soapcalls/xmlparsers.go index de62ce63..7b77f8c8 100644 --- a/soapcalls/xmlparsers.go +++ b/soapcalls/xmlparsers.go @@ -8,13 +8,13 @@ import ( "net/url" ) -// Root - root node +// Root - root node. type Root struct { XMLName xml.Name `xml:"root"` Device Device `xml:"device"` } -// Device - device node (we should only expect one?) +// Device - device node (we should only expect one?). type Device struct { XMLName xml.Name `xml:"device"` ServiceList ServiceList `xml:"serviceList"` @@ -26,7 +26,7 @@ type ServiceList struct { Services []Service `xml:"service"` } -// Service - service node +// Service - service node. type Service struct { XMLName xml.Name `xml:"service"` Type string `xml:"serviceType"` @@ -59,7 +59,7 @@ type EventTransportState struct { Value string `xml:"val,attr"` } -// DMRextractor - Get the AVTransport URL from the main DMR xml +// DMRextractor - Get the AVTransport URL from the main DMR xml. func DMRextractor(dmrurl string) (string, string, error) { var root Root @@ -95,7 +95,7 @@ func DMRextractor(dmrurl string) (string, string, error) { return "", "", errors.New("Something broke somewhere - wrong DMR URL?") } -// EventNotifyParser - Parse the Notify messages from the Media Renderer +// EventNotifyParser - Parse the Notify messages from the media renderer. func EventNotifyParser(xmlbody string) (string, string, error) { var root EventPropertySet err := xml.Unmarshal([]byte(xmlbody), &root)