Skip to content

Commit

Permalink
Rofi Support
Browse files Browse the repository at this point in the history
Rofi Support Added (Beta)
  • Loading branch information
Wraient authored Oct 27, 2024
2 parents c3fa51f + 16834a0 commit e301087
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 100 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.3
0.0.4
90 changes: 48 additions & 42 deletions cmd/curd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ func main() {
var anime internal.Anime
var user internal.User

var homeDir string
if runtime.GOOS == "windows" {
homeDir = os.Getenv("USERPROFILE")
} else {
homeDir = os.Getenv("HOME")
}
var homeDir string
if runtime.GOOS == "windows" {
homeDir = os.Getenv("USERPROFILE")
} else {
homeDir = os.Getenv("HOME")
}

configFilePath := filepath.Join(homeDir, ".config", "curd", "curd.conf")
configFilePath := filepath.Join(homeDir, ".config", "curd", "curd.conf")

// load curd userCurdConfig
userCurdConfig, err := internal.LoadConfig(configFilePath)
if err != nil {
fmt.Println("Error loading config:", err)
return
}
internal.SetGlobalConfig(&userCurdConfig)

logFile := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "debug.log")
internal.ClearLogFile(logFile)
Expand All @@ -59,11 +60,12 @@ func main() {
flag.BoolVar(&userCurdConfig.DiscordPresence, "discord-presence", userCurdConfig.DiscordPresence, "Enable Discord presence (true/false)")
continueLast := flag.Bool("c", false, "Continue last episode")
addNewAnime := flag.Bool("new", false, "Add new anime")
rofiSelection := flag.Bool("rofi", false, "Open selection in rofi")
updateScript := flag.Bool("u", false, "Update the script")
editConfig := flag.Bool("e", false, "Edit config")
subFlag := flag.Bool("sub", false, "Watch sub version")
dubFlag := flag.Bool("dub", false, "Watch dub version")

// Custom help/usage function
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Curd is a CLI tool to manage anime playback with advanced features like skipping intro, outro, filler, recap, tracking progress, and integrating with Discord.\n")
Expand All @@ -72,34 +74,38 @@ func main() {
}

flag.Parse()

anime.Ep.ContinueLast = *continueLast

if *updateScript{
if *updateScript {
repo := "wraient/curd"
fileName := "curd"

if err := internal.UpdateCurd(repo, fileName); err != nil {
fmt.Printf("Error updating executable: %v\n", err)
internal.CurdOut(fmt.Sprintf("Error updating executable: %v\n", err))
internal.ExitCurd(err)
} else {
fmt.Println("Program Updated!")
internal.CurdOut("Program Updated!")
internal.ExitCurd(nil)
}
}

if *rofiSelection {
userCurdConfig.RofiSelection = true
}

if *editConfig {
internal.EditConfig(configFilePath)
return
}

// Set SubOrDub based on the flags
if *subFlag {
userCurdConfig.SubOrDub = "sub"
} else if *dubFlag {
userCurdConfig.SubOrDub = "dub"
}
} else if *dubFlag {
userCurdConfig.SubOrDub = "dub"
}

// Get the token from the token file
user.Token, err = internal.GetTokenFromFile(filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token"))
if err != nil {
Expand All @@ -110,29 +116,29 @@ func main() {
fmt.Scanln(&user.Token)
internal.WriteTokenToFile(user.Token, filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token"))
}

// Load animes in database
databaseFile := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_history.txt")
databaseAnimes := internal.LocalGetAllAnime(databaseFile)

if *addNewAnime {
internal.AddNewAnime(&userCurdConfig, &anime, &user, &databaseAnimes, logFile)
internal.ExitCurd(fmt.Errorf("Added new anime!"))
}

internal.SetupCurd(&userCurdConfig, &anime, &user, &databaseAnimes, logFile)

temp_anime, err := internal.FindAnimeByAnilistID(user.AnimeList, strconv.Itoa(anime.AnilistId))
if err != nil {
internal.Log("Error finding anime by Anilist ID: "+err.Error(), logFile)
}

if anime.TotalEpisodes == temp_anime.Progress {
internal.Log(temp_anime.Progress, logFile)
internal.Log(anime.TotalEpisodes, logFile)
internal.Log(user.AnimeList, logFile)
internal.Log("Rewatching anime: "+internal.GetAnimeName(anime), logFile)
anime.Rewatching = true
anime.Rewatching = true
}

anime.Ep.Player.Speed = 1.0
Expand Down Expand Up @@ -168,7 +174,7 @@ func main() {
internal.Log(fmt.Sprint("Playback starting time: ", anime.Ep.Player.PlaybackTime), logFile)
internal.Log(anime.Ep.Player.SocketPath, logFile)
} else {
fmt.Println("Filler episode, skipping: ", anime.Ep.Number)
internal.CurdOut(fmt.Sprint("Filler episode, skipping: ", anime.Ep.Number))
}

wg.Add(1)
Expand All @@ -184,12 +190,12 @@ func main() {
// if filler episode or recap episode and skip is enabled
if (userCurdConfig.SkipFiller || userCurdConfig.SkipRecap) && (anime.Ep.IsFiller || anime.Ep.IsRecap) {
if anime.Ep.IsFiller && userCurdConfig.SkipFiller {
fmt.Println("Filler Episode, starting next episode: ", anime.Ep.Number+1)
internal.CurdOut(fmt.Sprint("Filler Episode, starting next episode: ", anime.Ep.Number+1))
internal.Log("Filler episode detected", logFile)
} else if anime.Ep.IsRecap && userCurdConfig.SkipRecap {
fmt.Println("Recap Episode, starting next episode: ", anime.Ep.Number+1)
internal.CurdOut(fmt.Sprint("Recap Episode, starting next episode: ", anime.Ep.Number+1))
internal.Log("Recap episode detected", logFile)
}
}
anime.Ep.Number++
anime.Ep.Started = false
anime.Ep.IsCompleted = true
Expand All @@ -202,7 +208,7 @@ func main() {
}
// Exit the skip loop
close(skipLoopDone)
}
}
}
}()

Expand Down Expand Up @@ -244,15 +250,15 @@ func main() {
durationPos, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "duration"})
if err != nil {
internal.Log("Error getting video duration: "+err.Error(), logFile)
} else if durationPos != nil {
if duration, ok := durationPos.(float64); ok {
anime.Ep.Duration = int(duration + 0.5) // Round to nearest integer
internal.Log(fmt.Sprintf("Video duration: %d seconds", anime.Ep.Duration), logFile)
} else {
} else if durationPos != nil {
if duration, ok := durationPos.(float64); ok {
anime.Ep.Duration = int(duration + 0.5) // Round to nearest integer
internal.Log(fmt.Sprintf("Video duration: %d seconds", anime.Ep.Duration), logFile)
} else {
internal.Log("Error: duration is not a float64", logFile)
}
}
break
break
}
}
time.Sleep(1 * time.Second)
Expand Down Expand Up @@ -375,19 +381,19 @@ func main() {
wg = sync.WaitGroup{}

if anime.Ep.IsCompleted && !anime.Rewatching {
go func(){
go func() {
err = internal.UpdateAnimeProgress(user.Token, anime.AnilistId, anime.Ep.Number-1)
if err != nil {
internal.Log("Error updating Anilist progress: "+err.Error(), logFile)
}
}()

anime.Ep.IsCompleted = false
// fmt.Println(anime.Ep.Number, anime.TotalEpisodes)
// internal.CurdOut(anime.Ep.Number, anime.TotalEpisodes, &userCurdConfig)
if anime.Ep.Number-1 == anime.TotalEpisodes && userCurdConfig.ScoreOnCompletion {
anime.Ep.Number = anime.Ep.Number - 1
var userScore float64
fmt.Println("Completed anime.")
internal.CurdOut("Completed anime.")
fmt.Println("Rate this anime: ")
fmt.Scanln(&userScore)
internal.RateAnime(user.Token, anime.AnilistId, userScore)
Expand All @@ -397,7 +403,7 @@ func main() {
}
if anime.Rewatching && anime.Ep.IsCompleted && anime.Ep.Number-1 == anime.TotalEpisodes {
anime.Ep.Number = anime.Ep.Number - 1
fmt.Println("Completed anime. (Rewatching so no scoring)")
internal.CurdOut("Completed anime. (Rewatching so no scoring)")
internal.LocalDeleteAnime(databaseFile, anime.AnilistId, anime.AllanimeId)
internal.ExitCurd(nil)
}
Expand All @@ -411,9 +417,9 @@ func main() {
internal.ExitCurd(nil)
}
}
fmt.Println("Starting next episode: "+fmt.Sprint(anime.Ep.Number))
anime.Ep.Started = false

internal.CurdOut(fmt.Sprint("Starting next episode: ", anime.Ep.Number))
anime.Ep.Started = false

}
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23.2
require (
github.com/Microsoft/go-winio v0.6.2
github.com/charmbracelet/bubbletea v1.1.1
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
github.com/hugolgst/rich-go v0.0.0-20240715122152-74618cc1ace2
)

Expand All @@ -14,14 +15,18 @@ require (
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4h
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/hugolgst/rich-go v0.0.0-20240715122152-74618cc1ace2 h1:9qOViOQGFIP5ar+2NorfAIsfuADEKXtklySC0zNnYf4=
github.com/hugolgst/rich-go v0.0.0-20240715122152-74618cc1ace2/go.mod h1:nGaW7CGfNZnhtiFxMpc4OZdqIexGXjUlBnlmpZmjEKA=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand All @@ -28,9 +34,13 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
8 changes: 4 additions & 4 deletions internal/anilist.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func AddAnimeToWatchingList(animeID int, token string) error {
return fmt.Errorf("failed to add anime: %w", err)
}

fmt.Printf("Anime with ID %d has been added to your watching list.\n", animeID)
CurdOut(fmt.Sprintf("Anime with ID %d has been added to your watching list.", animeID))
return nil
}

Expand Down Expand Up @@ -344,7 +344,7 @@ func UpdateAnimeProgress(token string, mediaID, progress int) error {
return err
}

fmt.Println("Anime progress updated! Latest watched episode:", progress)
CurdOut(fmt.Sprint("Anime progress updated! Latest watched episode: ", progress))
return nil
}

Expand Down Expand Up @@ -375,7 +375,7 @@ func RateAnime(token string, mediaID int, score float64) error {
return err
}

fmt.Printf("Successfully rated anime (mediaId: %d) with score: %.2f\n", mediaID, score)
CurdOut(fmt.Sprintf("Successfully rated anime (mediaId: %d) with score: %.2f", mediaID, score))
return nil
}

Expand Down Expand Up @@ -456,7 +456,7 @@ func ParseAnimeList(input map[string]interface{}) AnimeList {
// Access the list entries in the input map
if input["data"] == nil {
Log("Anilist request failed", logFile)
fmt.Println("Anilist request failed")
CurdOut("Anilist request failed")
ExitCurd(fmt.Errorf("Anilist request failed"))
return animeList
}
Expand Down
Loading

0 comments on commit e301087

Please sign in to comment.