Commit e4dbb2953b

e4dbb2953bff35e2d0cb53007c48a3cb0cc542ac

parent: 4d9874c1c4

Unsigned

Vedant Deshmukh <73630434+Vedant9500@users.noreply.github.com> · 2025-05-30 15:58 UTC

performed gofmt -s

Layout: unified · split

internal/anime_list.go +13 −13
@@ -5,16 +5,16 @@ import (
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "net/http" 7 "net/http"
8 "net/url"
8 "os" 9 "os"
9 "path/filepath" 10 "path/filepath"
10 "net/url"
11 // "strings" 11 // "strings"
12) 12)
13 13
14type anime struct { 14type anime struct {
15 ID string `json:"_id"` 15 ID string `json:"_id"`
16 Name string `json:"name"` 16 Name string `json:"name"`
17 EnglishName string `json:"englishName"` 17 EnglishName string `json:"englishName"`
18 AvailableEpisodes interface{} `json:"availableEpisodes"` 18 AvailableEpisodes interface{} `json:"availableEpisodes"`
19} 19}
20 20
@@ -49,10 +49,10 @@ func SearchAnime(query, mode string) (map[string]string, error) {
49 logFile = filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "debug.log") 49 logFile = filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "debug.log")
50 } 50 }
51 const ( 51 const (
52 agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0" 52 agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0"
53 allanimeRef = "https://allanime.to" 53 allanimeRef = "https://allanime.to"
54 allanimeBase = "allanime.day" 54 allanimeBase = "allanime.day"
55 allanimeAPI = "https://api." + allanimeBase + "/api" 55 allanimeAPI = "https://api." + allanimeBase + "/api"
56 ) 56 )
57 57
58 // Prepare the anime list 58 // Prepare the anime list
@@ -73,12 +73,12 @@ func SearchAnime(query, mode string) (map[string]string, error) {
73 // Prepare the GraphQL variables 73 // Prepare the GraphQL variables
74 variables := map[string]interface{}{ 74 variables := map[string]interface{}{
75 "search": map[string]interface{}{ 75 "search": map[string]interface{}{
76 "allowAdult": false, 76 "allowAdult": false,
77 "allowUnknown": false, 77 "allowUnknown": false,
78 "query": query, 78 "query": query,
79 }, 79 },
80 "limit": 40, 80 "limit": 40,
81 "page": 1, 81 "page": 1,
82 "translationType": mode, 82 "translationType": mode,
83 "countryOrigin": "ALL", 83 "countryOrigin": "ALL",
84 } 84 }
internal/discord.go +10 −10
@@ -17,14 +17,14 @@ func DiscordPresence(anime Anime, IsPaused bool) error {
17 17
18 var state string 18 var state string
19 if IsPaused { 19 if IsPaused {
20 state = fmt.Sprintf("\nEpisode %d - %s (Paused)", 20 state = fmt.Sprintf("\nEpisode %d - %s (Paused)",
21 anime.Ep.Number, 21 anime.Ep.Number,
22 FormatTime(anime.Ep.Player.PlaybackTime), 22 FormatTime(anime.Ep.Player.PlaybackTime),
23 ) 23 )
24 } else { 24 } else {
25 state = fmt.Sprintf("\nEpisode %d - %s / %s", 25 state = fmt.Sprintf("\nEpisode %d - %s / %s",
26 anime.Ep.Number, 26 anime.Ep.Number,
27 FormatTime(anime.Ep.Player.PlaybackTime), 27 FormatTime(anime.Ep.Player.PlaybackTime),
28 FormatTime(anime.Ep.Duration), 28 FormatTime(anime.Ep.Duration),
29 ) 29 )
30 } 30 }
@@ -37,12 +37,12 @@ func DiscordPresence(anime Anime, IsPaused bool) error {
37 //SmallImage: anime.SmallCoverImage, // Image for the bottom left corner 37 //SmallImage: anime.SmallCoverImage, // Image for the bottom left corner
38 //SmallText: fmt.Sprintf("Episode: %s", anime.Ep.Title.English), // Text when hovering over the small image 38 //SmallText: fmt.Sprintf("Episode: %s", anime.Ep.Title.English), // Text when hovering over the small image
39 Buttons: []*client.Button{ 39 Buttons: []*client.Button{
40 &client.Button{ 40 {
41 Label: "View on AniList", // Button label 41 Label: "View on AniList", // Button label
42 Url: fmt.Sprintf("https://anilist.co/anime/%d", anime.AnilistId), // Button link 42 Url: fmt.Sprintf("https://anilist.co/anime/%d", anime.AnilistId), // Button link
43 }, 43 },
44 &client.Button{ 44 {
45 Label: "View on MAL", // Button label 45 Label: "View on MAL", // Button label
46 Url: fmt.Sprintf("https://myanimelist.net/anime/%d", anime.MalId), // Button link 46 Url: fmt.Sprintf("https://myanimelist.net/anime/%d", anime.MalId), // Button link
47 }, 47 },
48 }, 48 },
@@ -66,4 +66,4 @@ func FormatTime(seconds int) string {
66 66
67func ConvertSecondsToMinutes(seconds int) int { 67func ConvertSecondsToMinutes(seconds int) int {
68 return seconds / 60 68 return seconds / 60
69}\ No newline at end of file 69}
internal/episode_list.go +6 −6
@@ -12,7 +12,7 @@ import (
12type episodesResponse struct { 12type episodesResponse struct {
13 Data struct { 13 Data struct {
14 Show struct { 14 Show struct {
15 ID string `json:"_id"` 15 ID string `json:"_id"`
16 AvailableEpisodesDetail map[string]interface{} `json:"availableEpisodesDetail"` 16 AvailableEpisodesDetail map[string]interface{} `json:"availableEpisodesDetail"`
17 } `json:"show"` 17 } `json:"show"`
18 } `json:"data"` 18 } `json:"data"`
@@ -33,14 +33,14 @@ type episodesResponse struct {
33// episodesList performs the API call and fetches the episodes list 33// episodesList performs the API call and fetches the episodes list
34func EpisodesList(showID, mode string) ([]string, error) { 34func EpisodesList(showID, mode string) ([]string, error) {
35 const ( 35 const (
36 agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0" 36 agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/121.0"
37 allanimeRef = "https://allanime.to" 37 allanimeRef = "https://allanime.to"
38 allanimeBase = "allanime.day" 38 allanimeBase = "allanime.day"
39 allanimeAPI = "https://api." + allanimeBase + "/api" 39 allanimeAPI = "https://api." + allanimeBase + "/api"
40 ) 40 )
41 41
42 episodesListGql := `query ($showId: String!) { show( _id: $showId ) { _id availableEpisodesDetail }}` 42 episodesListGql := `query ($showId: String!) { show( _id: $showId ) { _id availableEpisodesDetail }}`
43 43
44 // Build the request URL 44 // Build the request URL
45 url := fmt.Sprintf("%s?variables={\"showId\":\"%s\"}&query=%s", allanimeAPI, showID, episodesListGql) 45 url := fmt.Sprintf("%s?variables={\"showId\":\"%s\"}&query=%s", allanimeAPI, showID, episodesListGql)
46 episodes := []string{} 46 episodes := []string{}
internal/episode_url.go −1
@@ -158,7 +158,6 @@ func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) {
158 return nil, err 158 return nil, err
159 } 159 }
160 160
161
162 // Pre-count valid URLs and create slice to preserve order 161 // Pre-count valid URLs and create slice to preserve order
163 validURLs := make([]string, 0) 162 validURLs := make([]string, 0)
164 highestPriority := -1 163 highestPriority := -1
internal/jikan.go +2 −2
@@ -3,8 +3,8 @@ package internal
3import ( 3import (
4 "encoding/json" 4 "encoding/json"
5 "fmt" 5 "fmt"
6 "net/http"
7 "io" 6 "io"
7 "net/http"
8) 8)
9 9
10// GetEpisodeData fetches episode data for a given anime ID and episode number 10// GetEpisodeData fetches episode data for a given anime ID and episode number
@@ -103,4 +103,4 @@ func makeGetRequest(url string, headers map[string]string) (map[string]interface
103 } 103 }
104 104
105 return responseData, nil 105 return responseData, nil
106}\ No newline at end of file 106}
internal/links.go −1
@@ -46,4 +46,3 @@ func PrioritizeLink(links []string) string {
46 46
47 return bestLink 47 return bestLink
48} 48}
49
internal/localTracking.go +4 −4
@@ -258,7 +258,7 @@ func WatchUntracked(userCurdConfig *CurdConfig) {
258 if userCurdConfig.RofiSelection { 258 if userCurdConfig.RofiSelection {
259 userInput, err := GetUserInputFromRofi("Enter the anime name") 259 userInput, err := GetUserInputFromRofi("Enter the anime name")
260 if err != nil { 260 if err != nil {
261 Log("Error getting user input: "+err.Error()) 261 Log("Error getting user input: " + err.Error())
262 ExitCurd(fmt.Errorf("Error getting user input: " + err.Error())) 262 ExitCurd(fmt.Errorf("Error getting user input: " + err.Error()))
263 } 263 }
264 query = userInput 264 query = userInput
@@ -297,7 +297,7 @@ func WatchUntracked(userCurdConfig *CurdConfig) {
297 if userCurdConfig.RofiSelection { 297 if userCurdConfig.RofiSelection {
298 userInput, err := GetUserInputFromRofi("Enter the episode number") 298 userInput, err := GetUserInputFromRofi("Enter the episode number")
299 if err != nil { 299 if err != nil {
300 Log("Error getting episode number: "+err.Error()) 300 Log("Error getting episode number: " + err.Error())
301 ExitCurd(fmt.Errorf("Error getting episode number: " + err.Error())) 301 ExitCurd(fmt.Errorf("Error getting episode number: " + err.Error()))
302 } 302 }
303 episodeNumber, err = strconv.Atoi(userInput) 303 episodeNumber, err = strconv.Atoi(userInput)
@@ -346,7 +346,7 @@ func WatchUntracked(userCurdConfig *CurdConfig) {
346 // Get video duration 346 // Get video duration
347 durationPos, err := MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "duration"}) 347 durationPos, err := MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "duration"})
348 if err != nil { 348 if err != nil {
349 Log("Error getting video duration: "+err.Error()) 349 Log("Error getting video duration: " + err.Error())
350 } else if durationPos != nil { 350 } else if durationPos != nil {
351 if duration, ok := durationPos.(float64); ok { 351 if duration, ok := durationPos.(float64); ok {
352 anime.Ep.Duration = int(duration + 0.5) // Round to nearest integer 352 anime.Ep.Duration = int(duration + 0.5) // Round to nearest integer
@@ -366,7 +366,7 @@ func WatchUntracked(userCurdConfig *CurdConfig) {
366 for { 366 for {
367 timePos, err := MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"}) 367 timePos, err := MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"})
368 if err != nil { 368 if err != nil {
369 Log("Error getting playback time: "+err.Error()) 369 Log("Error getting playback time: " + err.Error())
370 370
371 // Check if the error is due to invalid JSON 371 // Check if the error is due to invalid JSON
372 // User closed the video 372 // User closed the video
internal/rofi.go +6 −6
@@ -3,8 +3,8 @@ package internal
3import ( 3import (
4 "bytes" 4 "bytes"
5 "fmt" 5 "fmt"
6 "os/exec"
7 "os" 6 "os"
7 "os/exec"
8 "path/filepath" 8 "path/filepath"
9 "strings" 9 "strings"
10) 10)
@@ -43,19 +43,19 @@ func GetUserInputFromRofi(message string) (string, error) {
43 } 43 }
44 // Create the Rofi command 44 // Create the Rofi command
45 cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "userinput.rasi"), "-p", "Input", "-mesg", message) 45 cmd := exec.Command("rofi", "-dmenu", "-theme", filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "userinput.rasi"), "-p", "Input", "-mesg", message)
46 46
47 // Set up pipes for output 47 // Set up pipes for output
48 var out bytes.Buffer 48 var out bytes.Buffer
49 cmd.Stdout = &out 49 cmd.Stdout = &out
50 50
51 // Run the command 51 // Run the command
52 err := cmd.Run() 52 err := cmd.Run()
53 if err != nil { 53 if err != nil {
54 return "", fmt.Errorf("failed to run Rofi: %w", err) 54 return "", fmt.Errorf("failed to run Rofi: %w", err)
55 } 55 }
56 56
57 // Get the entered input 57 // Get the entered input
58 userInput := strings.TrimSpace(out.String()) 58 userInput := strings.TrimSpace(out.String())
59 59
60 return userInput, nil 60 return userInput, nil
61}\ No newline at end of file 61}
internal/unix_ipc.go +7 −7
@@ -4,13 +4,13 @@
4package internal 4package internal
5 5
6import ( 6import (
7 "net" 7 "net"
8) 8)
9 9
10func connectToPipe(ipcSocketPath string) (net.Conn, error) { 10func connectToPipe(ipcSocketPath string) (net.Conn, error) {
11 conn, err := net.Dial("unix", ipcSocketPath) 11 conn, err := net.Dial("unix", ipcSocketPath)
12 if err != nil { 12 if err != nil {
13 return nil, err 13 return nil, err
14 } 14 }
15 return conn, nil 15 return conn, nil
16}\ No newline at end of file 16}