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