Commit d8af251280
Unsigned
Layout: unified · split
PKGBUILD +11 −55
| @@ -1,67 +1,23 @@ | ||
| 1 | 1 | # Maintainer: Wraient <rushikeshwastaken@gmail.com> |
| 2 | 2 | pkgname='curd' |
| 3 | pkgver=r92.d2c2c15 | |
| 4 | pkgrel=5 | |
| 5 | pkgdesc="Watch anime in cli with Anilist Tracking, Discord RPC, Intro Outro Skipping, etc." | |
| 3 | pkgver=0.0.1 | |
| 4 | pkgrel=6 | |
| 5 | pkgdesc="Watch anime in CLI with AniList Tracking, Discord RPC, Intro/Outro/Filler/Recap Skipping, etc." | |
| 6 | 6 | arch=("x86_64") |
| 7 | 7 | url="https://github.com/Wraient/curd" |
| 8 | 8 | license=('GPL') |
| 9 | depends=('python' 'mpv' 'socat') | |
| 10 | makedepends=('git' 'python-pip') | |
| 11 | source=("git+$url.git") | |
| 9 | depends=('mpv') | |
| 10 | source=("curd::https://github.com/Wraient/curd/releases/download/${pkgver}/curd") | |
| 12 | 11 | sha256sums=('SKIP') |
| 13 | 12 | |
| 14 | 13 | pkgver() { |
| 15 | cd "$srcdir/$pkgname" | |
| 16 | # Use the number of commits and the short hash as the version number | |
| 17 | printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" | |
| 18 | } | |
| 19 | ||
| 20 | build() { | |
| 21 | # No compilation needed for a Python script | |
| 22 | return 0 | |
| 14 | # Fetch the latest release tag from GitHub and set it as pkgver | |
| 15 | local latest_release | |
| 16 | latest_release=$(curl -s https://api.github.com/repos/Wraient/curd/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') | |
| 17 | echo "$latest_release" | |
| 23 | 18 | } |
| 24 | 19 | |
| 25 | 20 | package() { |
| 26 | # Create the directory for the virtual environment and script | |
| 27 | install -dm755 "$pkgdir/usr/share/$pkgname" | |
| 28 | ||
| 29 | # Check if the virtual environment already exists, if not, create it | |
| 30 | if [ ! -d "$pkgdir/usr/share/$pkgname/venv" ]; then | |
| 31 | python -m venv "$pkgdir/usr/share/$pkgname/venv" | |
| 32 | fi | |
| 33 | ||
| 34 | # Install or update packages in the virtual environment | |
| 35 | "$pkgdir/usr/share/$pkgname/venv/bin/pip" install --upgrade pypresence requests | |
| 36 | ||
| 37 | # Install the Python script | |
| 38 | install -Dm755 "$srcdir/$pkgname/curd.py" "$pkgdir/usr/share/$pkgname/curd.py" | |
| 39 | ||
| 40 | install -Dm755 /dev/null "$pkgdir/usr/bin/curd" | |
| 41 | # Create the run script | |
| 42 | cat << 'EOF' > "$pkgdir/usr/bin/curd" | |
| 43 | #!/bin/bash | |
| 44 | ||
| 45 | # Path to the virtual environment | |
| 46 | VENV_DIR="/usr/share/curd/venv" | |
| 47 | ||
| 48 | # Check if the virtual environment exists, create if not | |
| 49 | if [ ! -d "$VENV_DIR" ]; then | |
| 50 | python -m venv "$VENV_DIR" | |
| 51 | "$VENV_DIR/bin/pip" install pypresence requests | |
| 52 | fi | |
| 53 | ||
| 54 | # Activate the virtual environment | |
| 55 | source "$VENV_DIR/bin/activate" | |
| 56 | ||
| 57 | # Run the Python script | |
| 58 | python /usr/share/curd/curd.py "$@" | |
| 59 | ||
| 60 | # Deactivate the virtual environment after running | |
| 61 | deactivate | |
| 62 | EOF | |
| 63 | ||
| 64 | # Make the run script executable | |
| 65 | chmod +x "$pkgdir/usr/bin/curd" | |
| 21 | # Install the precompiled binary into /usr/bin | |
| 22 | install -Dm755 "$srcdir/curd" "$pkgdir/usr/bin/curd" | |
| 66 | 23 | } |
| 67 | ||
README.md +1
| @@ -119,6 +119,7 @@ yay -R curd | ||
| 119 | 119 | |
| 120 | 120 | |Description | Command | |
| 121 | 121 | ------------------------|------------------ |
| 122 | |*Watching new anime* | `curd -new` | | |
| 122 | 123 | |*Watch dub* | `curd -dub` | |
| 123 | 124 | |*Watch sub* | `curd -sub` | |
| 124 | 125 | |*Update the script* | `curd -u` | |
cmd/curd/main.go +41 −34
| @@ -50,9 +50,9 @@ func main() { | ||
| 50 | 50 | flag.BoolVar(&userCurdConfig.SaveMpvSpeed, "save-mpv-speed", userCurdConfig.SaveMpvSpeed, "Save MPV speed setting (true/false)") |
| 51 | 51 | flag.BoolVar(&userCurdConfig.DiscordPresence, "discord-presence", userCurdConfig.DiscordPresence, "Enable Discord presence (true/false)") |
| 52 | 52 | continueLast := flag.Bool("c", false, "Continue last episode") |
| 53 | addNewAnime := flag.Bool("new", false, "Add new anime") | |
| 53 | 54 | updateScript := flag.Bool("u", false, "Update the script") |
| 54 | 55 | editConfig := flag.Bool("e", false, "Edit config") |
| 55 | ||
| 56 | 56 | subFlag := flag.Bool("sub", false, "Watch sub version") |
| 57 | 57 | dubFlag := flag.Bool("dub", false, "Watch dub version") |
| 58 | 58 | |
| @@ -67,53 +67,60 @@ func main() { | ||
| 67 | 67 | |
| 68 | 68 | anime.Ep.ContinueLast = *continueLast |
| 69 | 69 | |
| 70 | ||
| 71 | ||
| 70 | 72 | if *updateScript{ |
| 71 | 73 | repo := "wraient/curd" |
| 72 | 74 | fileName := "curd" |
| 73 | ||
| 75 | ||
| 74 | 76 | if err := internal.UpdateCurd(repo, fileName); err != nil { |
| 75 | 77 | fmt.Printf("Error updating executable: %v\n", err) |
| 76 | 78 | os.Exit(1) |
| 77 | } else { | |
| 78 | fmt.Println("Program Updated!") | |
| 79 | internal.ExitCurd() | |
| 79 | } else { | |
| 80 | fmt.Println("Program Updated!") | |
| 81 | internal.ExitCurd() | |
| 82 | } | |
| 80 | 83 | } |
| 81 | } | |
| 82 | ||
| 83 | if *editConfig { | |
| 84 | internal.EditConfig(configFilePath) | |
| 85 | return | |
| 86 | } | |
| 87 | ||
| 84 | ||
| 85 | if *editConfig { | |
| 86 | internal.EditConfig(configFilePath) | |
| 87 | return | |
| 88 | } | |
| 89 | ||
| 88 | 90 | // Set SubOrDub based on the flags |
| 89 | 91 | if *subFlag { |
| 90 | 92 | userCurdConfig.SubOrDub = "sub" |
| 91 | } else if *dubFlag { | |
| 92 | userCurdConfig.SubOrDub = "dub" | |
| 93 | } | |
| 94 | ||
| 95 | // Get the token from the token file | |
| 96 | user.Token, err = internal.GetTokenFromFile(filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token")) | |
| 97 | if err != nil { | |
| 98 | internal.Log("Error reading token", logFile) | |
| 99 | } | |
| 100 | if user.Token == "" { | |
| 101 | fmt.Println("No token found, please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token") | |
| 102 | fmt.Scanln(&user.Token) | |
| 103 | internal.WriteTokenToFile(user.Token, filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token")) | |
| 104 | } | |
| 105 | ||
| 106 | // Load animes in database | |
| 107 | databaseFile := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_history.txt") | |
| 108 | databaseAnimes := internal.LocalGetAllAnime(databaseFile) | |
| 109 | ||
| 110 | internal.SetupCurd(&userCurdConfig, &anime, &user, &databaseAnimes, logFile) | |
| 93 | } else if *dubFlag { | |
| 94 | userCurdConfig.SubOrDub = "dub" | |
| 95 | } | |
| 96 | ||
| 97 | // Get the token from the token file | |
| 98 | user.Token, err = internal.GetTokenFromFile(filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token")) | |
| 99 | if err != nil { | |
| 100 | internal.Log("Error reading token", logFile) | |
| 101 | } | |
| 102 | if user.Token == "" { | |
| 103 | fmt.Println("No token found, please generate a token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token") | |
| 104 | fmt.Scanln(&user.Token) | |
| 105 | internal.WriteTokenToFile(user.Token, filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "token")) | |
| 106 | } | |
| 107 | ||
| 108 | // Load animes in database | |
| 109 | databaseFile := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_history.txt") | |
| 110 | databaseAnimes := internal.LocalGetAllAnime(databaseFile) | |
| 111 | ||
| 112 | if *addNewAnime { | |
| 113 | internal.AddNewAnime(&userCurdConfig, &anime, &user, &databaseAnimes, logFile) | |
| 114 | internal.ExitCurd() | |
| 115 | } | |
| 111 | 116 | |
| 112 | temp_anime, err := internal.FindAnimeByAnilistID(user.AnimeList, strconv.Itoa(anime.AnilistId)) | |
| 117 | internal.SetupCurd(&userCurdConfig, &anime, &user, &databaseAnimes, logFile) | |
| 118 | ||
| 119 | temp_anime, err := internal.FindAnimeByAnilistID(user.AnimeList, strconv.Itoa(anime.AnilistId)) | |
| 113 | 120 | if err != nil { |
| 114 | 121 | internal.Log("Error finding anime by Anilist ID: "+err.Error(), logFile) |
| 115 | 122 | } |
| 116 | ||
| 123 | ||
| 117 | 124 | if anime.TotalEpisodes == temp_anime.Progress { |
| 118 | 125 | internal.Log(temp_anime.Progress, logFile) |
| 119 | 126 | internal.Log(anime.TotalEpisodes, logFile) |
internal/curd.go +33 −29
| @@ -170,6 +170,38 @@ func UpdateCurd(repo, fileName string) error { | ||
| 170 | 170 | return nil |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | func AddNewAnime(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime, logFile string) { | |
| 174 | fmt.Println("Enter the anime name:") | |
| 175 | var query string | |
| 176 | fmt.Scanln(&query) | |
| 177 | animeMap, err := SearchAnimeAnilist(query, user.Token) | |
| 178 | if err != nil { | |
| 179 | Log(fmt.Sprintf("Failed to search anime: %v", err), logFile) | |
| 180 | ExitCurd() | |
| 181 | } | |
| 182 | anilistSelectedOption, err := DynamicSelect(animeMap) | |
| 183 | if err != nil { | |
| 184 | Log(fmt.Sprintf("No anime available: %v", err), logFile) | |
| 185 | ExitCurd() | |
| 186 | } | |
| 187 | animeID, err := strconv.Atoi(anilistSelectedOption.Key) | |
| 188 | if err != nil { | |
| 189 | Log(fmt.Sprintf("Failed to convert anime ID to integer: %v", err), logFile) | |
| 190 | ExitCurd() | |
| 191 | } | |
| 192 | err = AddAnimeToWatchingList(animeID, user.Token) | |
| 193 | if err != nil { | |
| 194 | Log(fmt.Sprintf("Failed to add anime to watching list: %v", err), logFile) | |
| 195 | ExitCurd() | |
| 196 | } | |
| 197 | anilistUserData, err := GetUserData(user.Token, user.Id) | |
| 198 | if err != nil { | |
| 199 | Log(fmt.Sprintf("Failed to get user data: %v", err), logFile) | |
| 200 | ExitCurd() | |
| 201 | } | |
| 202 | user.AnimeList = ParseAnimeList(anilistUserData) | |
| 203 | } | |
| 204 | ||
| 173 | 205 | func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAnimes *[]Anime, logFile string) { |
| 174 | 206 | var err error |
| 175 | 207 | |
| @@ -213,35 +245,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | ||
| 213 | 245 | } |
| 214 | 246 | |
| 215 | 247 | if anilistSelectedOption.Label == "add_new" { |
| 216 | fmt.Println("Enter the anime name:") | |
| 217 | var query string | |
| 218 | fmt.Scanln(&query) | |
| 219 | animeMap, err := SearchAnimeAnilist(query, user.Token) | |
| 220 | if err != nil { | |
| 221 | Log(fmt.Sprintf("Failed to search anime: %v", err), logFile) | |
| 222 | ExitCurd() | |
| 223 | } | |
| 224 | anilistSelectedOption, err = DynamicSelect(animeMap) | |
| 225 | if err != nil { | |
| 226 | Log(fmt.Sprintf("No anime available: %v", err), logFile) | |
| 227 | ExitCurd() | |
| 228 | } | |
| 229 | animeID, err := strconv.Atoi(anilistSelectedOption.Key) | |
| 230 | if err != nil { | |
| 231 | Log(fmt.Sprintf("Failed to convert anime ID to integer: %v", err), logFile) | |
| 232 | ExitCurd() | |
| 233 | } | |
| 234 | err = AddAnimeToWatchingList(animeID, user.Token) | |
| 235 | if err != nil { | |
| 236 | Log(fmt.Sprintf("Failed to add anime to watching list: %v", err), logFile) | |
| 237 | ExitCurd() | |
| 238 | } | |
| 239 | anilistUserData, err := GetUserData(user.Token, user.Id) | |
| 240 | if err != nil { | |
| 241 | Log(fmt.Sprintf("Failed to get user data: %v", err), logFile) | |
| 242 | ExitCurd() | |
| 243 | } | |
| 244 | user.AnimeList = ParseAnimeList(anilistUserData) | |
| 248 | AddNewAnime(userCurdConfig, anime, user, databaseAnimes, logFile) | |
| 245 | 249 | } |
| 246 | 250 | |
| 247 | 251 | userQuery = anilistSelectedOption.Label |