-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/load-app: Load chromecast App and Content ID
Add a new command to load a specific app on the chromecast and play the content id. This should be useful for loading media on arbitrary chromecast apps. Updates: #90
- Loading branch information
Showing
5 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright © 2021 Jonathan Pentecost <[email protected]> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vishen/go-chromecast/ui" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// loadAppCmd represents the load command | ||
var loadAppCmd = &cobra.Command{ | ||
Use: "load-app <app-id> <content-id>", | ||
Short: "Load and play content on a chromecast app", | ||
Long: `Load and play content on a chromecast app. This requires | ||
the chromecast receiver app to be specified. An older list can be found | ||
here https://gist.github.com/jloutsenhizer/8855258. | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) != 2 { | ||
return fmt.Errorf("requires exactly two arguments") | ||
} | ||
app, err := castApplication(cmd, args) | ||
if err != nil { | ||
fmt.Printf("unable to get cast application: %v\n", err) | ||
return nil | ||
} | ||
|
||
// Optionally run a UI when playing this media: | ||
runWithUI, _ := cmd.Flags().GetBool("with-ui") | ||
if runWithUI { | ||
go func() { | ||
if err := app.LoadApp(args[0], args[1]); err != nil { | ||
logrus.WithError(err).Fatal("unable to load media") | ||
} | ||
}() | ||
|
||
ccui, err := ui.NewUserInterface(app) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("unable to prepare a new user-interface") | ||
} | ||
return ccui.Run() | ||
} | ||
|
||
// Otherwise just run in CLI mode: | ||
if err := app.LoadApp(args[0], args[1]); err != nil { | ||
fmt.Printf("unable to load media: %v\n", err) | ||
return nil | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(loadAppCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters