Commit c324653056

c3246530568f8d0509d2dc4506567905faeb779d

parent: 49488fa4ff

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-27 11:38 UTC

Rate anime with rofi

Layout: unified · split

cmd/curd/main.go +1 −4
@@ -400,11 +400,8 @@ func main() {
400400 // internal.CurdOut(anime.Ep.Number, anime.TotalEpisodes, &userCurdConfig)
401401 if anime.Ep.Number-1 == anime.TotalEpisodes && userCurdConfig.ScoreOnCompletion {
402402 anime.Ep.Number = anime.Ep.Number - 1
403 var userScore float64
404403 internal.CurdOut("Completed anime.")
405 fmt.Println("Rate this anime: ")
406 fmt.Scanln(&userScore)
407 internal.RateAnime(user.Token, anime.AnilistId, userScore)
404 internal.RateAnime(user.Token, anime.AnilistId)
408405 internal.LocalDeleteAnime(databaseFile, anime.AnilistId, anime.AllanimeId)
409406 internal.ExitCurd(nil)
410407 }
internal/anilist.go +19 −2
@@ -349,7 +349,24 @@ func UpdateAnimeProgress(token string, mediaID, progress int) error {
349349}
350350
351351// Function to rate an anime on AniList
352func RateAnime(token string, mediaID int, score float64) error {
352func RateAnime(token string, mediaID int) error {
353 var score float64
354 var err error
355
356 if GetGlobalConfig().RofiSelection {
357 userInput, err := GetUserInputFromRofi("Enter a score for the anime (0-10):")
358 if err != nil {
359 return err
360 }
361 score, err = strconv.ParseFloat(userInput, 64)
362 if err != nil {
363 return err
364 }
365 } else {
366 fmt.Println("Rate this anime: ")
367 fmt.Scanln(&score)
368 }
369
353370 url := "https://graphql.anilist.co"
354371 query := `
355372 mutation($mediaId: Int, $score: Float) {
@@ -370,7 +387,7 @@ func RateAnime(token string, mediaID int, score float64) error {
370387 "Content-Type": "application/json",
371388 }
372389
373 _, err := makePostRequest(url, query, variables, headers)
390 _, err = makePostRequest(url, query, variables, headers)
374391 if err != nil {
375392 return err
376393 }
internal/rofi.go +24
@@ -1,7 +1,10 @@
11package internal
22
33import (
4 "bytes"
5 "fmt"
46 "os/exec"
7 "strings"
58)
69
710func GetTokenFromRofi() (string, error) {
@@ -29,3 +32,24 @@ func GetTokenFromRofi() (string, error) {
2932
3033 return token, nil
3134}
35
36// GetUserInputFromRofi prompts the user for input using Rofi with a custom message
37func GetUserInputFromRofi(message string) (string, error) {
38 // Create the Rofi command
39 cmd := exec.Command("rofi", "-dmenu", "-p", "Input", "-mesg", message)
40
41 // Set up pipes for output
42 var out bytes.Buffer
43 cmd.Stdout = &out
44
45 // Run the command
46 err := cmd.Run()
47 if err != nil {
48 return "", fmt.Errorf("failed to run Rofi: %w", err)
49 }
50
51 // Get the entered input
52 userInput := strings.TrimSpace(out.String())
53
54 return userInput, nil
55}
\ No newline at end of file