Commit b698507701

b698507701d64ef5df5d6e403ce0370ba171f0b8

parent: e74117eec9

Unsigned

Wraient <wraient.911@gmail.com> · 2025-02-05 15:54 UTC

Feat: Fetch next episode link for faster playback

Layout: unified · split

internal/curd.go +27
@@ -979,6 +979,10 @@ func WriteTokenToFile(token string, filePath string) error {
979979
980980func StartCurd(userCurdConfig *CurdConfig, anime *Anime, logFile string) string {
981981
982 if anime.Ep.NextEpisode.Number == anime.Ep.Number {
983 anime.Ep.Links = anime.Ep.NextEpisode.Links
984 fmt.Println("using prefetched next episode link")
985 } else {
982986 // Get episode link
983987 link, err := GetEpisodeURL(*userCurdConfig, anime.AllanimeId, anime.Ep.Number)
984988 if err != nil {
@@ -1008,6 +1012,7 @@ func StartCurd(userCurdConfig *CurdConfig, anime *Anime, logFile string) string
10081012 // anime.Ep.Links = link
10091013 }
10101014 anime.Ep.Links = link
1015 }
10111016
10121017 if len(anime.Ep.Links) == 0 {
10131018 CurdOut("No episode links found")
@@ -1016,6 +1021,28 @@ func StartCurd(userCurdConfig *CurdConfig, anime *Anime, logFile string) string
10161021
10171022 Log(anime, logFile)
10181023
1024 // Modify the goroutine in main.go where next episode links are fetched
1025 // Get next episode link in parallel
1026 go func() {
1027 nextEpNum := anime.Ep.Number + 1
1028 if nextEpNum <= anime.TotalEpisodes {
1029 // Get next canon episode number if filler skip is enabled
1030 if userCurdConfig.SkipFiller && IsEpisodeFiller(anime.FillerEpisodes, anime.Ep.Number) {
1031 nextEpNum = GetNextCanonEpisode(anime.FillerEpisodes, nextEpNum)
1032 }
1033 nextLinks, err := GetEpisodeURL(*userCurdConfig, anime.AllanimeId, nextEpNum)
1034 if err != nil {
1035 Log("Error getting next episode link: "+err.Error(), logFile)
1036 } else {
1037 anime.Ep.NextEpisode = NextEpisode{
1038 Number: nextEpNum,
1039 Links: nextLinks,
1040 }
1041 Log(fmt.Sprintf("Next episode link fetched for ep %d", nextEpNum), logFile)
1042 }
1043 }
1044 }()
1045
10191046 // Write anime.AnilistId to curd_id in the storage path
10201047 idFilePath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_id")
10211048 Log(fmt.Sprintf("idFilePath: %v", idFilePath), logFile)
internal/structs.go +6
@@ -37,6 +37,7 @@ type Episode struct {
3737 Started bool `json:"started"`
3838 Duration int `json:"duration"`
3939 Links []string `json:"links"`
40 NextEpisode NextEpisode `json:"next_episode"`
4041 IsFiller bool `json:"filler"`
4142 IsRecap bool `json:"recap"`
4243 Aired string `json:"aired"`
@@ -46,6 +47,11 @@ type Episode struct {
4647 IsCompleted bool
4748}
4849
50type NextEpisode struct {
51 Number int
52 Links []string
53}
54
4955type playingVideo struct {
5056 Url string
5157 Speed float64 `json:"speed"`