mirror of
https://github.com/Apologieze/Benri.git
synced 2026-01-18 17:17:21 +01:00
Fully working discord presence
This commit is contained in:
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
curd "AnimeGUI/curdInteg"
|
||||
"AnimeGUI/src/anilist"
|
||||
"AnimeGUI/src/config"
|
||||
"AnimeGUI/src/richPresence"
|
||||
"AnimeGUI/verniy"
|
||||
"fmt"
|
||||
"github.com/charmbracelet/log"
|
||||
@@ -207,6 +209,7 @@ func playingAnimeLoop(playingAnime curd.Anime, animeData *verniy.MediaList, savi
|
||||
fmt.Println(playingAnime.Ep.Player.PlaybackTime, "ah oue")
|
||||
// Get video duration
|
||||
go func() {
|
||||
defer richPresence.SetMenuActivity()
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
if playingAnime.Ep.Duration == 0 {
|
||||
@@ -231,6 +234,7 @@ func playingAnimeLoop(playingAnime curd.Anime, animeData *verniy.MediaList, savi
|
||||
} else {
|
||||
log.Error("Error seeking video: playback time is", playingAnime.Ep.Player.PlaybackTime)
|
||||
}
|
||||
//richPresence.ResetTime()
|
||||
break
|
||||
} else {
|
||||
log.Error("Error: duration is not a float64")
|
||||
@@ -239,6 +243,7 @@ func playingAnimeLoop(playingAnime curd.Anime, animeData *verniy.MediaList, savi
|
||||
}
|
||||
}
|
||||
|
||||
presenceAnime := richPresence.PresenceAnime{Name: playingAnime.Title.English, Ep: playingAnime.Ep.Number, ImageLink: *animeData.Media.CoverImage.Large, PlaybackTime: 0, Duration: playingAnime.Ep.Duration, TotalEp: playingAnime.TotalEpisodes}
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
timePos, err := curd.MPVSendCommand(playingAnime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"})
|
||||
@@ -270,6 +275,10 @@ func playingAnimeLoop(playingAnime curd.Anime, animeData *verniy.MediaList, savi
|
||||
if timing, ok := timePos.(float64); ok {
|
||||
playingAnime.Ep.Player.PlaybackTime = int(timing + 0.5)
|
||||
log.Infof("Video position: %d seconds", playingAnime.Ep.Player.PlaybackTime)
|
||||
if config.Setting.DiscordPresence {
|
||||
presenceAnime.PlaybackTime = playingAnime.Ep.Player.PlaybackTime
|
||||
richPresence.SetAnimeActivity(&presenceAnime)
|
||||
}
|
||||
} else {
|
||||
log.Error("Error: time-pos is not a float64")
|
||||
}
|
||||
@@ -278,7 +287,6 @@ func playingAnimeLoop(playingAnime curd.Anime, animeData *verniy.MediaList, savi
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
func UpdateProgressHandler(anime curd.Anime) {
|
||||
|
||||
@@ -41,6 +41,7 @@ var (
|
||||
episodeNumber = widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
||||
episodeLastPlayback = widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{})
|
||||
playButton *widget.Button
|
||||
moreActionButton *widget.Button
|
||||
changedToken bool
|
||||
mpvPresent bool
|
||||
grayScaleList uint8 = 35
|
||||
@@ -56,7 +57,7 @@ func main() {
|
||||
// Initialize lockfile
|
||||
lock := initLock()
|
||||
defer lock.Unlock()
|
||||
go fsnotifyNewAppDetection()
|
||||
go newAppDetection()
|
||||
}
|
||||
|
||||
go dowloadMPV()
|
||||
@@ -306,7 +307,7 @@ func initMainApp() {
|
||||
playButton.IconPlacement = widget.ButtonIconTrailingText
|
||||
playButton.Importance = widget.HighImportance
|
||||
|
||||
moreActionButton := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), func() {
|
||||
moreActionButton = widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), func() {
|
||||
openPlayMorePopUp()
|
||||
})
|
||||
playContainer := container.NewPadded(container.NewBorder(nil, nil, layout.NewSpacer(), moreActionButton, playButton))
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"AnimeGUI/src/config"
|
||||
"AnimeGUI/src/richPresence"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -20,7 +21,10 @@ func initSettingDialog() {
|
||||
config.SetBool(config.TrayIconKey, b)
|
||||
fmt.Println(config.Setting.TrayIcon)
|
||||
})
|
||||
checkDiscordPresence := widget.NewCheck("", func(b bool) { config.SetBool(config.DiscordPresence, b) })
|
||||
checkDiscordPresence := widget.NewCheck("", func(b bool) {
|
||||
config.SetBool(config.DiscordPresence, b)
|
||||
richPresence.InitDiscordRichPresence()
|
||||
})
|
||||
|
||||
checkSkipOpening.SetChecked(config.Setting.SkipOpening)
|
||||
checkSkipEnding.SetChecked(config.Setting.SkipEnding)
|
||||
|
||||
@@ -41,5 +41,5 @@ func openPlayMorePopUp() {
|
||||
//sizeW := window.Canvas().Size()
|
||||
//sizePopup := playMorePopUp.Size()
|
||||
//playMorePopUp.ShowAtPosition(fyne.Position{sizeW.Width - sizePopup.Width - 50, sizeW.Height - sizePopup.Height - 50})
|
||||
playMorePopUp.ShowAtRelativePosition(fyne.Position{X: 0, Y: -110}, playButton)
|
||||
playMorePopUp.ShowAtRelativePosition(fyne.Position{X: 0, Y: -110}, moreActionButton)
|
||||
}
|
||||
|
||||
@@ -2,18 +2,41 @@ package richPresence
|
||||
|
||||
import (
|
||||
"AnimeGUI/src/config"
|
||||
"fmt"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/hugolgst/rich-go/client"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PresenceAnime struct {
|
||||
Name string
|
||||
Ep int
|
||||
TotalEp int
|
||||
ImageLink string
|
||||
PlaybackTime int
|
||||
Duration int
|
||||
}
|
||||
|
||||
type PresenceState int
|
||||
|
||||
const (
|
||||
MainMenu PresenceState = iota
|
||||
Watching
|
||||
)
|
||||
|
||||
const advert = "Free, open-source, crossplatform Anime streaming app :D"
|
||||
|
||||
var timeNow = time.Now()
|
||||
|
||||
func ResetTime() {
|
||||
timeNow = time.Now()
|
||||
func ResetTime(waitingTime int) {
|
||||
go func() {
|
||||
time.Sleep(time.Duration(waitingTime) * time.Second)
|
||||
timeNow = time.Now()
|
||||
}()
|
||||
}
|
||||
func InitDiscordRichPresence() {
|
||||
if !config.Setting.DiscordPresence {
|
||||
client.Logout()
|
||||
return
|
||||
}
|
||||
err := client.Login("1046397185467621418")
|
||||
@@ -26,11 +49,12 @@ func InitDiscordRichPresence() {
|
||||
}
|
||||
|
||||
func SetMenuActivity() {
|
||||
log.Info("Main Menu Activity presence")
|
||||
err := client.SetActivity(client.Activity{
|
||||
Details: "In Main Menu",
|
||||
State: "Free, open-source, crossplatform Anime streaming app :D",
|
||||
State: advert,
|
||||
LargeImage: "https://apologize.fr/benri/icon.jpg",
|
||||
LargeText: "Free, open-source, crossplatform Anime streaming app :D",
|
||||
LargeText: advert,
|
||||
/*SmallImage: "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx170942-B77wUSM1jQTu.jpg",
|
||||
SmallText: "And this is the small image",*/
|
||||
/*Party: &client.Party{
|
||||
@@ -59,14 +83,20 @@ func SetMenuActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
func SetActivity() {
|
||||
func SetAnimeActivity(anime *PresenceAnime) {
|
||||
//zeroTime := time.Now()
|
||||
if anime == nil {
|
||||
SetMenuActivity()
|
||||
return
|
||||
}
|
||||
|
||||
err := client.SetActivity(client.Activity{
|
||||
State: "Episode 12/24 - 12min 3s",
|
||||
Details: "Blue Box",
|
||||
LargeImage: "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx170942-B77wUSM1jQTu.jpg",
|
||||
LargeText: "This is the large image :D",
|
||||
/*SmallImage: "https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx170942-B77wUSM1jQTu.jpg",
|
||||
SmallText: "And this is the small image",*/
|
||||
State: fmt.Sprintf("%s remaining", numberToTime(anime.Duration-anime.PlaybackTime)),
|
||||
Details: fmt.Sprintf("%s Episode %d/%d", anime.Name, anime.Ep, anime.TotalEp),
|
||||
LargeImage: anime.ImageLink,
|
||||
LargeText: anime.Name,
|
||||
SmallImage: "https://apologize.fr/benri/icon.jpg",
|
||||
SmallText: advert,
|
||||
/*Party: &client.Party{
|
||||
ID: "-1",
|
||||
Players: 15,
|
||||
@@ -92,3 +122,9 @@ func SetActivity() {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func numberToTime(seconds int) string {
|
||||
minutes := seconds / 60
|
||||
seconds %= 60
|
||||
return fmt.Sprintf("%dmin %ds", minutes, seconds)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func initLock() lockfile.Lockfile {
|
||||
return lock
|
||||
}
|
||||
|
||||
func fsnotifyNewAppDetection() {
|
||||
func newAppDetection() {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Error("Error creating watcher", "error", err)
|
||||
|
||||
Reference in New Issue
Block a user