mirror of
https://github.com/Apologieze/Benri.git
synced 2026-01-18 17:17:21 +01:00
Omg it's actually working like crazy
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.idea
|
||||
.idea
|
||||
bin/mpv.exe
|
||||
@@ -51,13 +51,13 @@ func GetData(radio *widget.RadioGroup, username string) {
|
||||
}
|
||||
}
|
||||
|
||||
func FindList(categoryName string) []verniy.MediaList {
|
||||
func FindList(categoryName string) *[]verniy.MediaList {
|
||||
if UserData == nil {
|
||||
log.Error("No data found")
|
||||
return nil
|
||||
}
|
||||
categoryIndex := categoriesToInt[categoryName]
|
||||
return UserData[categoryIndex].Entries
|
||||
return &UserData[categoryIndex].Entries
|
||||
}
|
||||
|
||||
func AnimeToName(anime verniy.MediaList) *string {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
var localAnime []curd.Anime
|
||||
@@ -86,15 +87,19 @@ type AllAnimeIdData struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func OnPlayButtonClick(animeName string, animeData verniy.MediaList) {
|
||||
func OnPlayButtonClick(animeName string, animeData *verniy.MediaList) {
|
||||
if animeData == nil {
|
||||
log.Error("Anime data is nil")
|
||||
return
|
||||
}
|
||||
var allAnimeId string
|
||||
animeProgress := 0
|
||||
if animeData.Progress != nil {
|
||||
animeProgress = *animeData.Progress
|
||||
if animeData.Progress != nil && animeData.Media.Episodes != nil {
|
||||
animeProgress = min(*animeData.Progress, *animeData.Media.Episodes-1)
|
||||
}
|
||||
animePointer := SearchFromLocalAniId(animeData.Media.ID)
|
||||
if animePointer == nil {
|
||||
allAnimeId = searchAllAnimeData(animeName, animeData.Media.Episodes)
|
||||
allAnimeId = searchAllAnimeData(animeName, animeData.Media.Episodes, animeProgress)
|
||||
if allAnimeId == "" {
|
||||
log.Error("Failed to get allAnimeId")
|
||||
return
|
||||
@@ -112,23 +117,39 @@ func OnPlayButtonClick(animeName string, animeData verniy.MediaList) {
|
||||
}
|
||||
log.Info("AllAnimeId!!!!!:", allAnimeId)
|
||||
|
||||
if animeProgress == 0 {
|
||||
animeProgress = 1
|
||||
}
|
||||
animeProgress++
|
||||
|
||||
log.Info("Anime Progress:", animeProgress)
|
||||
|
||||
url, err := curd.GetEpisodeURL(userCurdConfig, allAnimeId, animeProgress)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
finalLink := curd.PrioritizeLink(url)
|
||||
fmt.Println(finalLink)
|
||||
|
||||
mpvSocketPath, err := curd.StartVideo(finalLink, []string{}, fmt.Sprintf("%s - Episode %d", animeName, animeProgress))
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("MPV Socket Path:", mpvSocketPath)
|
||||
playingAnime := curd.Anime{AnilistId: animeData.Media.ID, AllanimeId: allAnimeId}
|
||||
playingAnime.Ep.Player.SocketPath = mpvSocketPath
|
||||
playingAnime.Title.English = animeName
|
||||
playingAnime.Ep.Number = animeProgress - 1
|
||||
playingAnime.TotalEpisodes = *animeData.Media.Episodes
|
||||
if animePointer != nil {
|
||||
fmt.Println("AnimePointer:", animePointer.Ep.Number, playingAnime.Ep.Number)
|
||||
if animePointer.Ep.Number == playingAnime.Ep.Number {
|
||||
playingAnime.Ep.Player.PlaybackTime = animePointer.Ep.Player.PlaybackTime
|
||||
}
|
||||
}
|
||||
playingAnimeLoop(playingAnime, animeData)
|
||||
}
|
||||
|
||||
func searchAllAnimeData(animeName string, epNumber *int) string {
|
||||
func searchAllAnimeData(animeName string, epNumber *int, animeProgress int) string {
|
||||
searchAnimeResult, err := curd.SearchAnime(animeName, "sub")
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@@ -152,13 +173,88 @@ func searchAllAnimeData(animeName string, epNumber *int) string {
|
||||
keyValueArray = append(keyValueArray, AllAnimeIdData{Id: key, Name: value})
|
||||
}
|
||||
|
||||
selectCorrectLinking(keyValueArray)
|
||||
selectCorrectLinking(keyValueArray, animeName, animeProgress)
|
||||
return ""
|
||||
}
|
||||
fmt.Println(AllanimeId)
|
||||
return AllanimeId
|
||||
}
|
||||
|
||||
/*func main() {
|
||||
startCurdInteg()
|
||||
}*/
|
||||
func playingAnimeLoop(playingAnime curd.Anime, animeData *verniy.MediaList) {
|
||||
fmt.Println(playingAnime.Ep.Player.PlaybackTime, "ah oue")
|
||||
// Get video duration
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
if playingAnime.Ep.Duration == 0 {
|
||||
// Get video duration
|
||||
durationPos, err := curd.MPVSendCommand(playingAnime.Ep.Player.SocketPath, []interface{}{"get_property", "duration"})
|
||||
if err != nil {
|
||||
log.Error("Error getting video duration: " + err.Error())
|
||||
} else if durationPos != nil {
|
||||
if duration, ok := durationPos.(float64); ok {
|
||||
playingAnime.Ep.Duration = int(duration + 0.5) // Round to nearest integer
|
||||
log.Infof("Video duration: %d seconds", playingAnime.Ep.Duration)
|
||||
|
||||
if playingAnime.Ep.Player.PlaybackTime > 10 {
|
||||
_, err := curd.SeekMPV(playingAnime.Ep.Player.SocketPath, max(0, playingAnime.Ep.Player.PlaybackTime-5))
|
||||
if err != nil {
|
||||
log.Error("Error seeking video: " + err.Error())
|
||||
}
|
||||
} else {
|
||||
log.Error("Error seeking video: playback time is", playingAnime.Ep.Player.PlaybackTime)
|
||||
}
|
||||
break
|
||||
} else {
|
||||
log.Error("Error: duration is not a float64")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Info("YIPIIIIIII", playingAnime.Ep.Duration)
|
||||
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
timePos, err := curd.MPVSendCommand(playingAnime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"})
|
||||
if err != nil {
|
||||
log.Error("Error getting video position: " + err.Error())
|
||||
fmt.Println("EH en vrai", playingAnime.Ep.Player.PlaybackTime, playingAnime.Ep.Duration)
|
||||
percentageWatched := curd.PercentageWatched(playingAnime.Ep.Player.PlaybackTime, playingAnime.Ep.Duration)
|
||||
|
||||
if int(percentageWatched) >= userCurdConfig.PercentageToMarkComplete {
|
||||
playingAnime.Ep.Number++
|
||||
playingAnime.Ep.Player.PlaybackTime = 0
|
||||
var newProgress int = playingAnime.Ep.Number
|
||||
animeData.Progress = &newProgress
|
||||
go UpdateAnimeProgress(playingAnime.AnilistId, playingAnime.Ep.Number)
|
||||
episodeNumber.SetText(fmt.Sprintf("Episode %d/%d", playingAnime.Ep.Number, playingAnime.TotalEpisodes))
|
||||
}
|
||||
|
||||
err := curd.LocalUpdateAnime(databaseFile, playingAnime.AnilistId, playingAnime.AllanimeId, playingAnime.Ep.Number, playingAnime.Ep.Player.PlaybackTime, 0, playingAnime.Title.English)
|
||||
if err == nil {
|
||||
log.Info("Successfully updated database file")
|
||||
}
|
||||
break
|
||||
}
|
||||
if timePos != nil && playingAnime.Ep.Duration != 0 {
|
||||
if timing, ok := timePos.(float64); ok {
|
||||
playingAnime.Ep.Player.PlaybackTime = int(timing + 0.5)
|
||||
log.Infof("Video position: %d seconds", playingAnime.Ep.Player.PlaybackTime)
|
||||
} else {
|
||||
log.Error("Error: time-pos is not a float64")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
func UpdateAnimeProgress(animeId int, episode int) {
|
||||
err := curd.UpdateAnimeProgress(user.Token, animeId, episode)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
61
main.go
61
main.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"animeFyne/anilist"
|
||||
curd "animeFyne/curdInteg"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
@@ -22,17 +23,19 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var animeList []verniy.MediaList
|
||||
var animeList *[]verniy.MediaList
|
||||
var window fyne.Window
|
||||
var animeSelected *verniy.MediaList
|
||||
var episodeNumber = widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
||||
|
||||
func main() {
|
||||
startCurdInteg()
|
||||
fmt.Println(localAnime)
|
||||
a := app.New()
|
||||
//a.Settings().SetTheme(&myTheme{})
|
||||
var animeSelected verniy.MediaList
|
||||
|
||||
w := a.NewWindow("AnimeGui")
|
||||
w.Resize(fyne.NewSize(1000, 700))
|
||||
window = a.NewWindow("AnimeGui")
|
||||
window.Resize(fyne.NewSize(1000, 700))
|
||||
|
||||
debounced := debounce.New(400 * time.Millisecond)
|
||||
|
||||
@@ -48,8 +51,6 @@ func main() {
|
||||
o.(*widget.Label).Bind(i.(binding.String))
|
||||
})
|
||||
|
||||
dialogC := dialog.NewCustom("Select the correct anime", "Cancel", container.NewCenter(widget.NewLabel("Salut")), w)
|
||||
|
||||
hello := widget.NewLabel("Hello Fyne!")
|
||||
|
||||
input := widget.NewEntry()
|
||||
@@ -83,19 +84,10 @@ func main() {
|
||||
|
||||
go anilist.GetData(radiobox, user.Username)
|
||||
|
||||
// Load image from file
|
||||
/*imgFile, err := os.Open("asset/img.png")
|
||||
anilist.Fatal(err)
|
||||
defer imgFile.Close()
|
||||
|
||||
img, _, err := image.Decode(imgFile)
|
||||
anilist.Fatal(err)*/
|
||||
|
||||
imageEx := &canvas.Image{}
|
||||
|
||||
animeName := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{})
|
||||
|
||||
episodeNumber := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
||||
episodeMinus := widget.NewButton(" - ", func() {})
|
||||
episodePlus := widget.NewButton(" + ", func() {})
|
||||
|
||||
@@ -108,7 +100,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
OnPlayButtonClick(animeName.Text, animeSelected)
|
||||
dialogC.Show()
|
||||
})
|
||||
|
||||
button.IconPlacement = widget.ButtonIconTrailingText
|
||||
@@ -120,7 +111,7 @@ func main() {
|
||||
|
||||
listDisplay.OnSelected = func(id int) {
|
||||
listName, err := data.GetValue(id)
|
||||
animeSelected = animeList[id]
|
||||
animeSelected = &(*animeList)[id]
|
||||
if err == nil {
|
||||
animeName.SetText(listName)
|
||||
}
|
||||
@@ -143,9 +134,9 @@ func main() {
|
||||
imageContainer.Refresh()
|
||||
}
|
||||
|
||||
w.SetContent(container.NewBorder(nil, nil, nil, imageContainer, leftSide))
|
||||
window.SetContent(container.NewBorder(nil, nil, nil, imageContainer, leftSide))
|
||||
|
||||
w.ShowAndRun()
|
||||
window.ShowAndRun()
|
||||
}
|
||||
|
||||
func updateAnimeNames(data binding.ExternalStringList) (first bool) {
|
||||
@@ -154,7 +145,7 @@ func updateAnimeNames(data binding.ExternalStringList) (first bool) {
|
||||
return
|
||||
}
|
||||
tempName := make([]string, 0, 25)
|
||||
for _, anime := range animeList {
|
||||
for _, anime := range *animeList {
|
||||
if name := anilist.AnimeToName(anime); name != nil {
|
||||
tempName = append(tempName, *name)
|
||||
} else {
|
||||
@@ -203,6 +194,34 @@ func getAnimeImageFromImage(img image.Image) *canvas.Image {
|
||||
return imageEx
|
||||
}
|
||||
|
||||
func selectCorrectLinking(allAnimeList []AllAnimeIdData) {
|
||||
func selectCorrectLinking(allAnimeList []AllAnimeIdData, animeName string, animeProgress int) {
|
||||
linkingList := widget.NewList(func() int {
|
||||
return len(allAnimeList)
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("template")
|
||||
},
|
||||
func(i widget.ListItemID, o fyne.CanvasObject) {
|
||||
o.(*widget.Label).SetText(allAnimeList[i].Name)
|
||||
})
|
||||
|
||||
linkingContainer := container.NewBorder(nil, nil, nil, nil, linkingList)
|
||||
dialogC := dialog.NewCustom("Select the correct anime", "Cancel", linkingContainer, window)
|
||||
|
||||
linkingList.OnSelected = func(index widget.ListItemID) {
|
||||
fmt.Println("Selected:", allAnimeList[index])
|
||||
dialogC.Hide()
|
||||
err := curd.LocalUpdateAnime(databaseFile, animeSelected.Media.ID, allAnimeList[index].Id, animeProgress, 0, 0, animeName)
|
||||
if err != nil {
|
||||
log.Error("Can't update database file", err)
|
||||
return
|
||||
}
|
||||
localAnime = curd.LocalGetAllAnime(databaseFile)
|
||||
OnPlayButtonClick(animeName, animeSelected)
|
||||
}
|
||||
|
||||
dialogC.Resize(fyne.NewSize(600, 900))
|
||||
dialogC.Show()
|
||||
log.Info("Select the correct anime", allAnimeList)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user