Skip to content

Commit

Permalink
Paused status
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraient committed Nov 1, 2024
1 parent 993df79 commit 2e6e6ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
13 changes: 11 additions & 2 deletions cmd/curd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func main() {
if err != nil {
internal.Log("Error getting anime ID and image: "+err.Error(), logFile)
}
err = internal.DiscordPresence(discordClientId, anime)
err = internal.DiscordPresence(discordClientId, anime, false)
if err != nil {
internal.Log("Error setting Discord presence: "+err.Error(), logFile)
}
Expand Down Expand Up @@ -264,7 +264,16 @@ func main() {
case <-skipLoopDone:
return
default:
err = internal.DiscordPresence(discordClientId, anime)
isPaused, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "pause"})
if err != nil {
internal.Log("Error getting pause status: "+err.Error(), logFile)
}
if isPaused == nil {
isPaused = true
} else {
isPaused = isPaused.(bool)
}
err = internal.DiscordPresence(discordClientId, anime, isPaused.(bool))
if err != nil {
// internal.Log("Error setting Discord presence: "+err.Error(), logFile)
}
Expand Down
26 changes: 18 additions & 8 deletions internal/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ import (
"github.com/hugolgst/rich-go/client"
)

func DiscordPresence(clientId string, anime Anime) error {
func DiscordPresence(clientId string, anime Anime, IsPaused bool) error {
err := client.Login(clientId)
if err != nil {
return err
}

err = client.SetActivity(client.Activity{
Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text
LargeImage: anime.CoverImage,
LargeText: GetAnimeName(anime), // Would display while hovering over the large image
State: fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d",
var state string
if IsPaused {
state = fmt.Sprintf("\nEpisode %d - %d:%02d (Paused)",
anime.Ep.Number,
ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime),
anime.Ep.Player.PlaybackTime % 60,
)
} else {
state = fmt.Sprintf("\nEpisode %d - %d:%02d / %d:%02d",
anime.Ep.Number,
ConvertSecondsToMinutes(anime.Ep.Player.PlaybackTime),
anime.Ep.Player.PlaybackTime % 60,
ConvertSecondsToMinutes(anime.Ep.Duration),
anime.Ep.Duration % 60),
anime.Ep.Duration % 60,
)
}
err = client.SetActivity(client.Activity{
Details: fmt.Sprintf("%s", GetAnimeName(anime)), // Large text
LargeImage: anime.CoverImage,
LargeText: GetAnimeName(anime), // Would display while hovering over the large image
State: state,
// SmallImage: anime.CoverImage, // Image would appear in the bottom left corner
// SmallText: fmt.Sprintf("%s", anime.Ep.Title.English), // Would display while hovering over the small image
Buttons: []*client.Button{
Expand Down

0 comments on commit 2e6e6ae

Please sign in to comment.