refactor: remove unused playback methods and source resolution
This commit is contained in:
@@ -562,57 +562,6 @@ func (c *allAnimeClient) Search(ctx context.Context, query string, mode string)
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEpisodes returns the list of available episode strings for a show and mode.
|
|
||||||
func (c *allAnimeClient) GetEpisodes(ctx context.Context, showID string, mode string) ([]string, error) {
|
|
||||||
graphqlQuery := `query($showId: String!) {
|
|
||||||
show(_id: $showId) {
|
|
||||||
availableEpisodesDetail
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
result, err := c.graphqlRequest(ctx, graphqlQuery, map[string]any{"showId": showID})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, ok := result["data"].(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("invalid episode response")
|
|
||||||
}
|
|
||||||
|
|
||||||
show, ok := data["show"].(map[string]any)
|
|
||||||
if !ok || show == nil {
|
|
||||||
return nil, fmt.Errorf("show not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
detail, ok := show["availableEpisodesDetail"].(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("invalid episodes detail")
|
|
||||||
}
|
|
||||||
|
|
||||||
rawList, ok := detail[mode].([]any)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("no episodes for mode %s", mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
episodes := make([]string, 0, len(rawList))
|
|
||||||
for _, item := range rawList {
|
|
||||||
episode, ok := item.(string)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
episode = strings.TrimSpace(episode)
|
|
||||||
if episode == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
episodes = append(episodes, episode)
|
|
||||||
}
|
|
||||||
|
|
||||||
return episodes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAvailableEpisodes returns the count of sub/dub/raw episodes available for a show.
|
// GetAvailableEpisodes returns the count of sub/dub/raw episodes available for a show.
|
||||||
func (c *allAnimeClient) GetAvailableEpisodes(ctx context.Context, showID string) (AvailableEpisodes, error) {
|
func (c *allAnimeClient) GetAvailableEpisodes(ctx context.Context, showID string) (AvailableEpisodes, error) {
|
||||||
graphqlQuery := `query($showId: String!) {
|
graphqlQuery := `query($showId: String!) {
|
||||||
@@ -668,42 +617,6 @@ func (c *allAnimeClient) GetAvailableEpisodes(ctx context.Context, showID string
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *allAnimeClient) GetEpisodeMetadata(ctx context.Context, showID string, episode string) (map[string]any, error) {
|
|
||||||
graphqlQuery := `query($showId: String!, $episodeString: String!, $translationType: VaildTranslationTypeEnumType!) {
|
|
||||||
episode(showId: $showId, episodeString: $episodeString, translationType: $translationType) {
|
|
||||||
notes
|
|
||||||
episodeInfo {
|
|
||||||
notes
|
|
||||||
thumbnails
|
|
||||||
vidinfors {
|
|
||||||
vidPath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
result, err := c.graphqlRequest(ctx, graphqlQuery, map[string]any{
|
|
||||||
"showId": showID,
|
|
||||||
"episodeString": episode,
|
|
||||||
"translationType": "sub",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, ok := result["data"].(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("invalid response")
|
|
||||||
}
|
|
||||||
|
|
||||||
ep, ok := data["episode"].(map[string]any)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("episode not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
return ep, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeSourceURL(encoded string) string {
|
func decodeSourceURL(encoded string) string {
|
||||||
if encoded == "" {
|
if encoded == "" {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -349,15 +349,6 @@ func clonePlaybackBaseData(data playbackBaseData) playbackBaseData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEpisodeMetadata fetches episode notes and thumbnails from AllAnime.
|
|
||||||
func (s *Service) GetEpisodeMetadata(ctx context.Context, malID int, episode string) (map[string]any, error) {
|
|
||||||
showID, _, err := s.resolveShowCached(ctx, malID, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return s.allAnimeClient.GetEpisodeMetadata(ctx, showID, episode)
|
|
||||||
}
|
|
||||||
|
|
||||||
func toQualities(sources []StreamSource) []string {
|
func toQualities(sources []StreamSource) []string {
|
||||||
seen := make(map[string]struct{})
|
seen := make(map[string]struct{})
|
||||||
var qualities []string
|
var qualities []string
|
||||||
|
|||||||
@@ -9,25 +9,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// resolveModeSource fetches sources for a given mode and selects the best one.
|
|
||||||
func (s *Service) resolveModeSource(ctx context.Context, showID string, episode string, mode string, quality string) (StreamSource, error) {
|
|
||||||
sources, err := s.allAnimeClient.GetEpisodeSources(ctx, showID, episode, mode)
|
|
||||||
if err != nil {
|
|
||||||
return StreamSource{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ranked, err := rankSources(sources, quality)
|
|
||||||
if err != nil {
|
|
||||||
return StreamSource{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
selected, _, err := s.choosePlaybackSource(ctx, ranked, s.probeDirectMedia)
|
|
||||||
if err != nil {
|
|
||||||
return StreamSource{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return selected, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// resolveModeSourceWithCache is like resolveModeSource but caches probe results.
|
// resolveModeSourceWithCache is like resolveModeSource but caches probe results.
|
||||||
func (s *Service) resolveModeSourceWithCache(
|
func (s *Service) resolveModeSourceWithCache(
|
||||||
|
|||||||
Reference in New Issue
Block a user