Skip to content

Commit

Permalink
comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexballas committed Feb 15, 2021
1 parent bcaf664 commit 9160416
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion flagfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go2tv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -95,7 +95,7 @@ func main() {
}

initializeCloseHandler(*tvdata)
// Sleep forever
// Sleep forever.
select {}
}

Expand All @@ -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}
Expand Down
19 changes: 9 additions & 10 deletions httphandlers/httphandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ 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
}

// 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{
Expand All @@ -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()
}
Expand Down Expand Up @@ -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{
Expand All @@ -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")
}
Expand All @@ -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},
Expand Down
6 changes: 3 additions & 3 deletions soapcalls/soapbuilders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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("&#34;"), []byte(`"`))
b = bytes.ReplaceAll(b, []byte("&amp;"), []byte("&"))

Expand Down
24 changes: 12 additions & 12 deletions soapcalls/soapcallers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -197,15 +197,15 @@ 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)
if err != nil {
return err
}

// Refresh token after after Timeout / 2 seconds
// Refresh token after after Timeout / 2 seconds.
if timeoutInt > 1 {
triggerTime = timeoutInt / 2
}
Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions soapcalls/xmlparsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9160416

Please sign in to comment.