aboutsummaryrefslogtreecommitdiff
path: root/utils/api
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-02-24 15:02:38 +0530
committerBobby <[email protected]>2026-02-24 15:02:38 +0530
commitc6ff27b989047cf0af8d6cf2aa86c8e80547cf10 (patch)
tree55206173780ba073611d72fca135fedfd0322cb4 /utils/api
parent17b77153a862ad1eb3babe1e34e748363ac9916c (diff)
downloadmetachan-c6ff27b989047cf0af8d6cf2aa86c8e80547cf10.tar.xz
metachan-c6ff27b989047cf0af8d6cf2aa86c8e80547cf10.zip
Add GetAnimeEpisodes endpoint and implement episode retrieval logic
Diffstat (limited to 'utils/api')
-rw-r--r--utils/api/streaming/streaming.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/utils/api/streaming/streaming.go b/utils/api/streaming/streaming.go
index f08a2d3..4e06515 100644
--- a/utils/api/streaming/streaming.go
+++ b/utils/api/streaming/streaming.go
@@ -514,6 +514,56 @@ func GetStreamingSources(title string, episodeNumber int) (*types.StreamAnimeStr
return streaming, nil
}
+func FetchAllEpisodeSources(title string, episodeNumbers []int) (map[int]*types.StreamAnimeStreaming, error) {
+ searchResults, err := SearchAnime(title)
+ if err != nil || len(searchResults) == 0 {
+ return nil, errors.New("no streaming sources found")
+ }
+
+ bestMatch := searchResults[0]
+
+ subSet := make(map[string]bool)
+ dubSet := make(map[string]bool)
+
+ if bestMatch.SubEpisodes > 0 {
+ if eps, err := GetEpisodesList(bestMatch.ID, "sub"); err == nil {
+ for _, e := range eps {
+ subSet[e] = true
+ }
+ }
+ }
+ if bestMatch.DubEpisodes > 0 {
+ if eps, err := GetEpisodesList(bestMatch.ID, "dub"); err == nil {
+ for _, e := range eps {
+ dubSet[e] = true
+ }
+ }
+ }
+
+ result := make(map[int]*types.StreamAnimeStreaming)
+ for _, epNum := range episodeNumbers {
+ epStr := fmt.Sprintf("%d", epNum)
+ s := &types.StreamAnimeStreaming{
+ Sub: []types.StreamAnimeStreamingSource{},
+ Dub: []types.StreamAnimeStreamingSource{},
+ }
+ if subSet[epStr] {
+ if sources, err := GetEpisodeLinks(bestMatch.ID, epStr, "sub"); err == nil {
+ s.Sub = sources
+ }
+ }
+ if dubSet[epStr] {
+ if sources, err := GetEpisodeLinks(bestMatch.ID, epStr, "dub"); err == nil {
+ s.Dub = sources
+ }
+ }
+ if len(s.Sub) > 0 || len(s.Dub) > 0 {
+ result[epNum] = s
+ }
+ }
+ return result, nil
+}
+
func GetStreamingCounts(title string) (int, int, error) {
searchResults, err := SearchAnime(title)
if err != nil {