@@ -13,6 +13,7 @@ import (
1313 "sync"
1414 "time"
1515
16+ "github.com/sirupsen/logrus"
1617 log "github.com/sirupsen/logrus"
1718
1819 "github.com/buger/jsonparser"
@@ -603,11 +604,13 @@ type mediaItem struct {
603604 filename string
604605 contentType string
605606 contentURL string
607+ transcode bool
606608}
607609
608610func (a * Application ) loadAndServeFiles (filenames []string , contentType string , transcode bool ) ([]mediaItem , error ) {
609611 mediaItems := make ([]mediaItem , len (filenames ))
610612 for i , filename := range filenames {
613+ transcodeFile := transcode
611614 if _ , err := os .Stat (filename ); err != nil {
612615 return nil , errors .Wrapf (err , "unable to find %q" , filename )
613616 }
@@ -620,32 +623,28 @@ func (a *Application) loadAndServeFiles(filenames []string, contentType string,
620623 -
621624 */
622625 knownFileType := a .knownFileType (filename )
623- if ! knownFileType && contentType == "" && ! transcode {
626+ if ! knownFileType && contentType == "" && ! transcodeFile {
624627 return nil , fmt .Errorf ("unknown content-type for %q, either specify a content-type or set transcode to true" , filename )
625628 }
626629
627- // Set the content-type
628- // This assumes that a conten-type was passed through, and that it
629- // doesn't need to be transcoded. This is for media files without
630- // file extensions.
631- // TODO: Is this correct behaviour?
630+ // If we have a content-type specified we should always
631+ // attempt to use that
632632 if contentType != "" {
633- transcode = false
634633 } else if knownFileType {
635634 // If this is a media file we know the chromecast can play,
636635 // then we don't need to transcode it.
637636 contentType , _ = a .possibleContentType (filename )
638- transcode = false
639- }
640-
641- if transcode {
637+ transcodeFile = false
638+ } else if transcodeFile {
642639 contentType = "video/mp4"
643640 }
644641
645642 mediaItems [i ] = mediaItem {
646643 filename : filename ,
647644 contentType : contentType ,
645+ transcode : transcodeFile ,
648646 }
647+ fmt .Printf ("TRANSCODE_DEBUG: %#v\n " , mediaItems [i ])
649648 // Add the filename to the list of filenames that go-chromecast will serve.
650649 a .mediaFilenames = append (a .mediaFilenames , filename )
651650 }
@@ -666,7 +665,7 @@ func (a *Application) loadAndServeFiles(filenames []string, contentType string,
666665 // We can only set the content url after the server has started, otherwise we have
667666 // no way to know the port used.
668667 for i , m := range mediaItems {
669- mediaItems [i ].contentURL = fmt .Sprintf ("http://%s:%d?media_file=%s&live_streaming=%t" , localIP , a .serverPort , m .filename , transcode )
668+ mediaItems [i ].contentURL = fmt .Sprintf ("http://%s:%d?media_file=%s&live_streaming=%t" , localIP , a .serverPort , m .filename , m . transcode )
670669 }
671670
672671 return mediaItems , nil
@@ -803,7 +802,14 @@ func (a *Application) serveLiveStreaming(w http.ResponseWriter, r *http.Request,
803802 w .Header ().Set ("Transfer-Encoding" , "chunked" )
804803
805804 if err := cmd .Run (); err != nil {
806- log .WithField ("package" , "application" ).WithField ("filename" , filename ).WithError (err ).Error ("error transcoding" )
805+ if e , ok := err .(* exec.ExitError ); ok {
806+ log .WithField ("package" , "application" ).WithFields (logrus.Fields {
807+ "filename" : filename ,
808+ "stderr" : string (e .Stderr ),
809+ }).WithError (err ).Error ("error transcoding" )
810+ } else {
811+ log .WithField ("package" , "application" ).WithField ("filename" , filename ).WithError (err ).Error ("error transcoding" )
812+ }
807813 }
808814
809815}
0 commit comments