internal/providers/anineko/substyle.go
40 lines · 913 bytes
1package anineko
2
3import (
4 "strings"
5
6 "github.com/wraient/curd/internal/providers/substyle"
7)
8
9func chooseSubStyle(groups map[string][]string, preference string) (string, error) {
10 hasSoft := len(groups["sub"]) > 0
11 hasHard := len(groups["hsub"]) > 0
12 return substyle.Choose(hasSoft, hasHard, preference)
13}
14
15func embedURLsForSubStyle(groups map[string][]string, style string) []string {
16 switch style {
17 case "soft":
18 return append([]string{}, groups["sub"]...)
19 case "hard":
20 return append([]string{}, groups["hsub"]...)
21 default:
22 return nil
23 }
24}
25
26func embedURLsForMode(groups map[string][]string, mode, subStyle string) ([]string, error) {
27 if strings.EqualFold(mode, "dub") {
28 return groups["dub"], nil
29 }
30
31 chosen, err := chooseSubStyle(groups, subStyle)
32 if err != nil {
33 return nil, err
34 }
35 return embedURLsForSubStyle(groups, chosen), nil
36}
37
38func resetSubStyleForTest() {
39 substyle.ResetForTest()
40}