Skip to content

Commit

Permalink
Add a VHS tape for demo. Still working on finding a track in Music wi…
Browse files Browse the repository at this point in the history
…th JXA.
  • Loading branch information
hilli committed May 21, 2023
1 parent 767fa45 commit b1803f9
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
kef-virtual-hub
bin
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"recommendations": [
"humao.rest-client",
"golang.go"
"golang.go",
"idleberg.applescript"
]
}
37 changes: 37 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "go: build kefw2 cli",
"command": "task",
"args": [
"build"
],
"problemMatcher": [
"$go"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "cd ${workspaceFolder}; task build"
},
{
"type": "shell",
"label": "vhs: Create gif from tape file",
"command": "task",
"args": [
"record"
],
"problemMatcher": [
"$go"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "cd ${workspaceFolder}; task build"
}
]
}
12 changes: 12 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
# This is a Taskfile. See https://taskfile.dev

tasks:
build:
cmds:
- go build -o bin/kefw2 cmd/kefw2/kefw2.go

record:
cmds:
- rm -f ~/.config/kefw2/kefw2.yaml
- vhs docs/kefw2.tape
7 changes: 5 additions & 2 deletions cmd/kefw2/cmd/config_speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ var speakerSetDefaultCmd = &cobra.Command{
func addSpeaker(host string) (err error) {
speaker, err := kefw2.NewSpeaker(host)
if err != nil {
fmt.Println(err)
return
return fmt.Errorf("error adding speaker: %s", err)
}
speakers = append(speakers, speaker)
viper.Set("speakers", speakers)
fmt.Printf("Added speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
if len(speakers) == 1 {
viper.Set("defaultSpeaker", speaker.IPAddress)
fmt.Printf("Set default speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
}
viper.WriteConfig()
return
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/kefw2/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ THE SOFTWARE.
package cmd

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -61,6 +60,7 @@ func Execute() {
}

func init() {
rootCmd.AddCommand(ConfigCmd)
cobra.OnInitialize(initConfig)

// Find home directory.
Expand All @@ -87,7 +87,6 @@ func init() {
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

rootCmd.AddCommand(ConfigCmd)
}

// initConfig reads in config file and ENV variables if set.
Expand All @@ -102,7 +101,8 @@ func initConfig() {

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err != nil {
fmt.Fprintln(os.Stderr, "Couldn't read config file:", viper.ConfigFileUsed(), " Create one by adding a speaker: `kefw2 config speaker add IP_ADDRESS`")
// Output here interferes with the completion cmd if there is no config file.
// fmt.Fprintln(os.Stderr, "Couldn't read config file:", viper.ConfigFileUsed(), " Create one by adding a speaker: `kefw2 config speaker add IP_ADDRESS`")
return
}
// Unmarshal speakers
Expand All @@ -126,7 +126,7 @@ func initConfig() {
}
} else {
if defaultSpeaker == nil {
log.Fatal("Default speaker not found. Set it with `kefw2 config speaker default` or specify it with the --speaker (-s) flag")
log.Println("Default speaker not found. Set it with `kefw2 config speaker default` or specify it with the --speaker (-s) flag")
}
currentSpeaker = defaultSpeaker
}
Expand Down
22 changes: 15 additions & 7 deletions cmd/kefw2/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ var statusCmd = &cobra.Command{
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)
if playstate, err := currentSpeaker.IsPlaying(); err != nil {
fmt.Println("error getting playstate:", err)
} else {
if playstate {
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)
} else {
fmt.Println("Audio Transport: stopped")
}
}
}
},
}
Expand Down
47 changes: 47 additions & 0 deletions docs/airplay-music.jxa
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env osascript -l JavaScript
// Using osascript, JavaScript edition, to control Apple Music
// Finds the speaker defined in speakerToPlayOn and plays a song on it
// via AirPlay whilst disabling all other speakers (For your own sanity)

speakerToPlayOn = "Hillis Desk"

Music = Application('Music')
// Music.activate()
console.log("Music is running: ", Music.running())
airplayDevices = Music.airplayDevices;
console.log("Airplay devices count:", airplayDevices.length)

for (player in airplayDevices) {
plr = airplayDevices[player]
// console.log(" - ", airplayDevices[player].name())
if (plr.name() == speakerToPlayOn) {
console.log("Found speaker we want:", speakerToPlayOn)
console.log("Enabling", plr.name(), "as AirPlay target...")
plr.selected = true
} else {
console.log("Disabling", plr.name() ,"as AirPlay target...")
plr.selected = false
}
}

trackURL = "itmss://music.apple.com/dk/album/vamp/679279852?i=679280169"
// Music.openLocation("itmss://music.apple.com/dk/album/vamp/679279852?i=679280169")
// Music.sources.byId(73).urlTracks.byId(679280169)
// console.log("Current track: ", Music.currentTrack.name())
// props = Music.properties()

// console.log(props)

// sel = app.selection();
// sel[0].duplicate({to: pl});

// const pl = Music.UserPlaylist.make()
// pl.name = "kefw2-test"
// pl.shuffleEnabled = true
// pl.repeatEnabled = false

// console.log("Current track: ", Music.currentTrack.name())

// Music.stop()
// Music.nextTrack()
// Music.play()
53 changes: 53 additions & 0 deletions docs/kefw2.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Set Shell zsh
Output kefw2.gif
Require kefw2
Set FontSize 14

#Type "kefw2 completion zsh > /tmp/cmpzsh && source /tmp/cmpzsh"
#Enter
#Sleep 500ms
Type "kefw2 --help"
Enter
Sleep 2.5s
Type "kefw2 config speaker add 10.0.0.149"
Enter
Sleep 500ms
Type "kefw2 config speaker add 10.0.0.93"
Enter
Sleep 500ms
Type "kefw2 config speaker list"
Enter
Sleep 500ms
Type "kefw2 --help"
Enter
Sleep 500ms
Type "kefw2 status"
Enter
Sleep 500ms
Type "kefw2 source usb"
Enter
Sleep 500ms
Type "kefw2 source"
Enter
Sleep 500ms
Type" kefw2 source wifi"
Enter
Sleep 500ms
Type "echo Playing some music from somewhere else..."
Enter
Sleep 2s
Type "kefw2 status"
Enter
Sleep 5s
Type "kefw2 pause"
Enter
Sleep 1s
Type "kefw2 vol 30"
Enter
Sleep 1s
Type "kefw2 vol"
Enter
Sleep 500ms
Type "kefw2 off"
Enter
Sleep 2s
2 changes: 1 addition & 1 deletion research/commands.http
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VS Code REST Client
# KEF LS60 Wireless base URL
@baseurl = http://10.0.0.93
# KEF LSX II Wireless base URL
@baseurl = http://10.0.0.143
@baseurl = http://10.0.0.149

# roles define if you get the value part of the response or the whole response
# when you are pulling data from the speaker. setData only accepts value, sensibly enough.
Expand Down

0 comments on commit b1803f9

Please sign in to comment.