Commit 58a2350eaf

58a2350eaf343bb03d03c6495209cbef152c4705

parent: 986e998085

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-22 14:20 UTC

Add: Links selected on priority

Layout: unified · split

internal/curd.go +1 −1
@@ -199,7 +199,7 @@ func StartCurd(userCurdConfig *CurdConfig, anime *Anime, logFile string) string
199 } 199 }
200 200
201 Log(anime, logFile) 201 Log(anime, logFile)
202 mpvSocketPath, err := StartVideo(anime.Ep.Links[len(anime.Ep.Links)-1], []string{}) 202 mpvSocketPath, err := StartVideo(PrioritizeLink(anime.Ep.Links), []string{})
203 203
204 if err != nil { 204 if err != nil {
205 Log("Failed to start mpv", logFile) 205 Log("Failed to start mpv", logFile)
internal/links.go added +49
@@ -0,0 +1,49 @@
1package internal
2
3import "strings"
4
5// LinkPriorities defines the order of priority for link domains
6var LinkPriorities = []string{
7 "sharepoint.com",
8 "wixmp.com",
9 "dropbox.com",
10 "wetransfer.com",
11 "gogoanime.com",
12 // Add more domains in order of priority
13}
14
15// PrioritizeLink takes an array of links and returns a single link based on priority
16func PrioritizeLink(links []string) string {
17 if len(links) == 0 {
18 return ""
19 }
20
21 // Create a map for quick lookup of priorities
22 priorityMap := make(map[string]int)
23 for i, p := range LinkPriorities {
24 priorityMap[p] = len(LinkPriorities) - i // Higher index means higher priority
25 }
26
27 highestPriority := -1
28 var bestLink string
29
30 for _, link := range links {
31 for domain, priority := range priorityMap {
32 if strings.Contains(link, domain) {
33 if priority > highestPriority {
34 highestPriority = priority
35 bestLink = link
36 }
37 break
38 }
39 }
40 }
41
42 // If no priority link found, return the first link
43 if bestLink == "" {
44 return links[0]
45 }
46
47 return bestLink
48}
49