-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
218 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hilli/go-kef-w2/kefw2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// muteCmd toggles the mute state of the speakers | ||
var pauseCmd = &cobra.Command{ | ||
Use: "pause", | ||
Short: "Pause playback when on WiFi source", | ||
Long: `Pause playback when on WiFi source`, | ||
Args: cobra.MaximumNArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
currentSource, err := currentSpeaker.Source() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
if currentSource != kefw2.SourceWiFi { | ||
fmt.Println("Not on WiFi source, not resuming playback") | ||
os.Exit(0) | ||
} | ||
if isPlaying, err := currentSpeaker.IsPlaying(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} else if !isPlaying { | ||
fmt.Println("Not playing, not pausing") | ||
os.Exit(0) | ||
} | ||
err = currentSpeaker.PlayPause() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(pauseCmd) | ||
} |
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,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hilli/go-kef-w2/kefw2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// muteCmd toggles the mute state of the speakers | ||
var playCmd = &cobra.Command{ | ||
Use: "play", | ||
Short: "Resume playback when on WiFi source if paused", | ||
Long: `Resume playback when on WiFi source if paused`, | ||
Args: cobra.MaximumNArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
currentSource, err := currentSpeaker.Source() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
if currentSource != kefw2.SourceWiFi { | ||
fmt.Println("Not on WiFi source, not resuming playback") | ||
os.Exit(0) | ||
} | ||
err = currentSpeaker.PlayPause() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(playCmd) | ||
} |
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,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hilli/go-kef-w2/kefw2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// volumeCmd represents the volume command | ||
var statusCmd = &cobra.Command{ | ||
Use: "status", | ||
Aliases: []string{"info", "state", "st"}, | ||
Short: "Status of the speakers", | ||
Long: `Status of the speakers`, | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
status, err := currentSpeaker.SpeakerState() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("State:", status) | ||
source, err := currentSpeaker.Source() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Source:", source) | ||
if source == kefw2.SourceWiFi { | ||
pd, err := currentSpeaker.PlayerData() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Audio Transport:", pd.MediaRoles.Title) | ||
fmt.Println("Artist:", pd.TrackRoles.MediaData.MetaData.Artist) | ||
fmt.Println("Album:", pd.TrackRoles.MediaData.MetaData.Album) | ||
fmt.Println("Track:", pd.TrackRoles.Title) | ||
fmt.Println("Duration:", pd.Status.Duration) | ||
fmt.Println("PlayID:", pd.PlayID.TimeStamp) | ||
fmt.Println("Album Art:", pd.TrackRoles.Icon) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(statusCmd) | ||
} |
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,87 @@ | ||
package kefw2 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type PlayerData struct { | ||
State string `json:"state"` | ||
Status PlayerResource `json:"status"` | ||
TrackRoles PlayerTrackRoles `json:"trackRoles"` | ||
Controls PlayerControls `json:"controls"` | ||
MediaRoles PlayerMediaRoles `json:"mediaRoles"` | ||
PlayID PlayerPlayID `json:"playId"` | ||
} | ||
|
||
type PlayerResource struct { | ||
Duration int `json:"duration"` | ||
} | ||
|
||
type PlayerTrackRoles struct { | ||
Icon string `json:"icon"` | ||
MediaData PlayerMediaData `json:"mediaData"` | ||
Title string `json:"title"` | ||
} | ||
|
||
type PlayerMediaData struct { | ||
ActiveResource PlayerResource `json:"activeResource"` | ||
MetaData PlayerMetaData `json:"metaData"` | ||
Resources []PlayerResource `json:"resources"` | ||
} | ||
|
||
type PlayerMetaData struct { | ||
Artist string `json:"artist"` | ||
Album string `json:"album"` | ||
} | ||
|
||
type PlayerControls struct { | ||
Previous bool `json:"previous"` | ||
Pause bool `json:"pause"` | ||
Next bool `json:"next_"` | ||
} | ||
|
||
type PlayerMediaRoles struct { | ||
AudioType string `json:"audioType"` | ||
DoNotTrack bool `json:"doNotTrack"` | ||
Type string `json:"type"` | ||
MediaData PlayerMediaRolesMetaData `json:"mediaData"` | ||
Title string `json:"title"` | ||
} | ||
|
||
type PlayerMediaRolesMetaData struct { | ||
MetaData PlayerMediaRolesMedieDataMetaData `json:"metaData"` | ||
Resources []PlayerMimeResource `json:"resources"` | ||
} | ||
|
||
type PlayerMediaRolesMedieDataMetaData struct { | ||
ServiceID string `json:"serviceId"` | ||
Live bool `json:"live"` | ||
PlayLogicPath string `json:"playLogicPath"` | ||
} | ||
|
||
type PlayerMimeResource struct { | ||
MimeType string `json:"mimeType"` | ||
URI string `json:"uri"` | ||
} | ||
|
||
type PlayerPlayID struct { | ||
TimeStamp int `json:"timestamp"` | ||
SystemMemberId string `json:"systemMemberId"` | ||
} | ||
|
||
func (s *KEFSpeaker) PlayerData() (PlayerData, error) { | ||
var playersData []PlayerData | ||
var err error | ||
playersJson, err := s.getData("player:player/data") | ||
if err != nil { | ||
return PlayerData{}, fmt.Errorf("error getting player data: %s", err) | ||
} | ||
err = json.Unmarshal(playersJson, &playersData) | ||
if err != nil { | ||
// fmt.Printf("jsonData: %+v\n", string(playersJson)) | ||
return PlayerData{}, fmt.Errorf("error unmarshaling player data: %s", err) | ||
} | ||
playerData := playersData[0] | ||
return playerData, nil | ||
} |