@@ -16,7 +16,6 @@ package cmd
1616
1717import (
1818 "bufio"
19- "fmt"
2019 "io/ioutil"
2120 "os"
2221 "path/filepath"
@@ -25,7 +24,6 @@ import (
2524 "strings"
2625 "time"
2726
28- "github.com/sirupsen/logrus"
2927 "github.com/spf13/cobra"
3028 "github.com/vishen/go-chromecast/ui"
3129)
@@ -46,21 +44,18 @@ chromecast.
4644If the media file is an unplayable media type by the chromecast, this
4745will attempt to transcode the media file to mp4 using ffmpeg. This requires
4846that ffmpeg is installed.` ,
49- RunE : func (cmd * cobra.Command , args []string ) error {
47+ Run : func (cmd * cobra.Command , args []string ) {
5048 if len (args ) != 1 {
51- return fmt . Errorf ("requires exactly one argument, should be the folder to play media from" )
49+ exit ("requires exactly one argument, should be the folder to play media from\n " )
5250 }
5351 if fileInfo , err := os .Stat (args [0 ]); err != nil {
54- logrus .Printf ("unable to find %q: %v\n " , args [0 ], err )
55- return nil
52+ exit ("unable to find %q: %v\n " , args [0 ], err )
5653 } else if ! fileInfo .Mode ().IsDir () {
57- logrus .Printf ("%q is not a directory\n " , args [0 ])
58- return nil
54+ exit ("%q is not a directory\n " , args [0 ])
5955 }
6056 app , err := castApplication (cmd , args )
6157 if err != nil {
62- logrus .Printf ("unable to get cast application: %v\n " , err )
63- return nil
58+ exit ("unable to get cast application: %v\n " , err )
6459 }
6560
6661 contentType , _ := cmd .Flags ().GetString ("content-type" )
@@ -70,8 +65,7 @@ that ffmpeg is installed.`,
7065 selection , _ := cmd .Flags ().GetBool ("select" )
7166 files , err := ioutil .ReadDir (args [0 ])
7267 if err != nil {
73- logrus .Printf ("unable to list files from %q: %v" , args [0 ], err )
74- return nil
68+ exit ("unable to list files from %q: %v\n " , args [0 ], err )
7569 }
7670 filesToPlay := make ([]mediaFile , 0 , len (files ))
7771 for _ , f := range files {
@@ -144,21 +138,21 @@ that ffmpeg is installed.`,
144138
145139 indexToPlayFrom := 0
146140 if selection {
147- logrus . Println ("Will play the following items, select where to start from:" )
141+ outputInfo ("Will play the following items, select where to start from:" )
148142 for i , f := range filenames {
149143 lastPlayed := "never"
150144 if lp , ok := app .PlayedItems ()[f ]; ok {
151145 t := time .Unix (lp .Started , 0 )
152146 lastPlayed = t .String ()
153147 }
154- logrus . Printf ("%d) %s: last played %q\n " , i + 1 , f , lastPlayed )
148+ outputInfo ("%d) %s: last played %q\n " , i + 1 , f , lastPlayed )
155149 }
156150 reader := bufio .NewReader (os .Stdin )
157151 for {
158- logrus . Printf ("Enter selection: " )
152+ outputInfo ("Enter selection: " )
159153 text , err := reader .ReadString ('\n' )
160154 if err != nil {
161- logrus . Printf ( "error reading console: %v\n " , err )
155+ outputError ( " reading console: %v\n " , err )
162156 continue
163157 }
164158 i , err := strconv .Atoi (strings .TrimSpace (text ))
@@ -199,29 +193,29 @@ that ffmpeg is installed.`,
199193 for _ , f := range filenames [indexToPlayFrom :] {
200194 s += "- " + f + "\n "
201195 }
202- logrus . Print (s )
196+ outputInfo (s )
203197
204198 // Optionally run a UI when playing this media:
205199 runWithUI , _ := cmd .Flags ().GetBool ("with-ui" )
206200 if runWithUI {
207201 go func () {
208202 if err := app .QueueLoad (filenames [indexToPlayFrom :], contentType , transcode ); err != nil {
209- logrus . WithError ( err ). Fatal ( "unable to play playlist on cast application" )
203+ exit ( "unable to play playlist on cast application: %v \n " , err )
210204 }
211205 }()
212206
213207 ccui , err := ui .NewUserInterface (app )
214208 if err != nil {
215- logrus .WithError (err ).Fatal ("unable to prepare a new user-interface" )
209+ exit ("unable to prepare a new user-interface: %v\n " , err )
210+ }
211+ if err := ccui .Run (); err != nil {
212+ exit ("unable to run ui: %v\n " , err )
216213 }
217- return ccui .Run ()
218214 }
219215
220216 if err := app .QueueLoad (filenames [indexToPlayFrom :], contentType , transcode ); err != nil {
221- logrus .Printf ("unable to play playlist on cast application: %v\n " , err )
222- return nil
217+ exit ("unable to play playlist on cast application: %v\n " , err )
223218 }
224- return nil
225219 },
226220}
227221
0 commit comments