-
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.
Merge pull request 'feat: add support for resuming audio' (#1) from f…
…eat/resume into main Reviewed-on: https://codeberg.org/tomkoid/audstopper/pulls/1
- Loading branch information
Showing
10 changed files
with
163 additions
and
18 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,36 @@ | ||
package audio | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"codeberg.org/tomkoid/audstopper/internal/config" | ||
) | ||
|
||
type Player struct { | ||
Name string | ||
PauseCommand []string | ||
ResumeCommand []string | ||
} | ||
|
||
func listPlayers(config *config.Config) []Player { | ||
var players []Player | ||
|
||
// if these binaries exist on the running system | ||
if _, err := exec.LookPath("mpc"); err == nil && config.Mpc { | ||
players = append(players, Player{ | ||
Name: "mpc", | ||
PauseCommand: []string{"mpc", "pause"}, | ||
ResumeCommand: []string{"mpc", "play"}, | ||
}) | ||
} | ||
|
||
if _, err := exec.LookPath("playerctl"); err == nil && config.PlayerCtl { | ||
players = append(players, Player{ | ||
Name: "playerctl", | ||
PauseCommand: []string{"playerctl", "pause"}, | ||
ResumeCommand: []string{"playerctl", "resume"}, | ||
}) | ||
} | ||
|
||
return players | ||
} |
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,39 @@ | ||
package audio | ||
|
||
import ( | ||
"strings" | ||
|
||
"codeberg.org/tomkoid/audstopper/internal/tools" | ||
) | ||
|
||
func isPlaying(player string) (bool, []string) { | ||
playing := false | ||
players := []string{} | ||
|
||
if player == "playerctl" { | ||
output, err := tools.RunCommand("playerctl", "status") | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
if string(output) == "Playing\n" { | ||
playing = true | ||
players = append(players, player) | ||
} | ||
} | ||
if player == "mpc" { | ||
output, err := tools.RunCommand("mpc", "status") | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
println(string(output)) | ||
if strings.Contains(string(output), "[playing]") { | ||
playing = true | ||
players = append(players, player) | ||
} | ||
} | ||
|
||
// log.Printf("returned from isplaying: %v", players) | ||
return playing, players | ||
} |
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,24 @@ | ||
package audio | ||
|
||
import ( | ||
"log" | ||
|
||
"codeberg.org/tomkoid/audstopper/internal/config" | ||
"codeberg.org/tomkoid/audstopper/internal/tools" | ||
) | ||
|
||
func resumeAudio(config *config.Config, givenPlayers []string) { | ||
log.Println("Resuming audio.") | ||
|
||
for _, player := range listPlayers(config) { | ||
for _, givenPlayer := range givenPlayers { | ||
if player.Name == givenPlayer { | ||
log.Printf("Resuming audio for %s\n", givenPlayer) | ||
_, err := tools.RunCommand(player.ResumeCommand[0], player.ResumeCommand[1:]...) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package config | ||
|
||
type Config struct { | ||
Resume bool `toml:"resume"` | ||
Mpc bool `toml:"mpc"` | ||
PlayerCtl bool `toml:"playerctl"` | ||
} |
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