### Install GoAnime Library Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md Use 'go get' to install the GoAnime library. This command fetches and installs the specified package. ```bash go get github.com/alvarorichard/Goanime ``` -------------------------------- ### Complete Goanime Example: Search, List Episodes, Get Stream Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md This example demonstrates the full workflow: searching for an anime, fetching its episodes, and retrieving the stream URL for the first episode. It includes error handling and outputting results to the console. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { client := goanime.NewClient() // 1. Search for anime fmt.Println("Searching for anime...") results, err := client.SearchAnime("Jujutsu Kaisen", nil) if err != nil { log.Fatal(err) } if len(results) == 0 { log.Fatal("No anime found") } // Display search results fmt.Printf("\nFound %d results:\n", len(results)) for i, anime := range results { fmt.Printf("%d. %s [%s]\n", i+1, anime.Name, anime.Source) } // Select first result selectedAnime := results[0] fmt.Printf("\nSelected: %s\n", selectedAnime.Name) // 2. Get episodes source, err := types.ParseSource(selectedAnime.Source) if err != nil { log.Fatal(err) } fmt.Println("\nFetching episodes...") episodes, err := client.GetAnimeEpisodes(selectedAnime.URL, source) if err != nil { log.Fatal(err) } fmt.Printf("Found %d episodes\n", len(episodes)) // Display first 5 episodes displayCount := 5 if len(episodes) < displayCount { displayCount = len(episodes) } fmt.Printf("\nFirst %d episodes:\n", displayCount) for i := 0; i < displayCount; i++ { ep := episodes[i] title := "N/A" if ep.Title != nil && ep.Title.English != "" { title = ep.Title.English } else if ep.Title != nil && ep.Title.Romaji != "" { title = ep.Title.Romaji } fmt.Printf(" Episode %s: %s\n", ep.Number, title) } // 3. Get stream URL for first episode if len(episodes) > 0 { fmt.Println("\nGetting stream URL for episode 1...") streamURL, metadata, err := client.GetEpisodeStreamURL(selectedAnime, episodes[0], &goanime.StreamOptions{ Quality: "best", Mode: "sub", }) if err != nil { log.Printf("Error getting stream URL: %v\n", err) } else { fmt.Printf("Stream URL: %s\n", streamURL) if len(metadata) > 0 { fmt.Println("Metadata:") for key, value := range metadata { fmt.Printf(" %s: %s\n", key, value) } } } } fmt.Println("\nDone!") } ``` -------------------------------- ### Complete Example: Search, List Episodes, and Get Stream Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md A comprehensive example demonstrating the workflow of searching for anime, retrieving its episodes, and getting a stream URL for an episode. ```APIDOC ## Complete Example: Search, List Episodes, and Get Stream ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { client := goanime.NewClient() // 1. Search for anime fmt.Println("Searching for anime...") results, err := client.SearchAnime("Jujutsu Kaisen", nil) if err != nil { log.Fatal(err) } if len(results) == 0 { log.Fatal("No anime found") } // Display search results fmt.Printf("\nFound %d results:\n", len(results)) for i, anime := range results { fmt.Printf("%d. %s [%s]\n", i+1, anime.Name, anime.Source) } // Select first result selectedAnime := results[0] fmt.Printf("\nSelected: %s\n", selectedAnime.Name) // 2. Get episodes source, err := types.ParseSource(selectedAnime.Source) if err != nil { log.Fatal(err) } fmt.Println("\nFetching episodes...") episodes, err := client.GetAnimeEpisodes(selectedAnime.URL, source) if err != nil { log.Fatal(err) } fmt.Printf("Found %d episodes\n", len(episodes)) // Display first 5 episodes displayCount := 5 if len(episodes) < displayCount { displayCount = len(episodes) } fmt.Printf("\nFirst %d episodes:\n", displayCount) for i := 0; i < displayCount; i++ { ep := episodes[i] title := "N/A" if ep.Title != nil && ep.Title.English != "" { title = ep.Title.English } else if ep.Title != nil && ep.Title.Romaji != "" { title = ep.Title.Romaji } fmt.Printf(" Episode %s: %s\n", ep.Number, title) } // 3. Get stream URL for first episode if len(episodes) > 0 { fmt.Println("\nGetting stream URL for episode 1...") streamURL, metadata, err := client.GetEpisodeStreamURL(selectedAnime, episodes[0], &goanime.StreamOptions{ Quality: "best", Mode: "sub", }) if err != nil { log.Printf("Error getting stream URL: %v\n", err) } else { fmt.Printf("Stream URL: %s\n", streamURL) if len(metadata) > 0 { fmt.Println("Metadata:") for key, value := range metadata { fmt.Printf(" %s: %s\n", key, value) } } } } fmt.Println("\nDone!") } ``` ``` -------------------------------- ### Run Example: Search Anime Source: https://github.com/alvarorichard/goanime/blob/main/pkg/README.md Command to run the basic anime search example located in the pkg/goanime/examples/search directory. ```bash go run ./pkg/goanime/examples/search/main.go ``` -------------------------------- ### Install GoAnime CLI and Library Source: https://context7.com/alvarorichard/goanime/llms.txt Install the GoAnime CLI application or add it as a library to your Go project using the go toolchain. ```bash # Install the CLI application go install github.com/alvarorichard/Goanime/cmd/goanime@latest # Or install as a library for your Go project go get github.com/alvarorichard/Goanime ``` -------------------------------- ### Install GoAnime on Debian/Ubuntu Source: https://github.com/alvarorichard/goanime/blob/main/README.md Update package lists, install mpv, download the GoAnime binary, make it executable, and move it to /usr/local/bin. ```bash sudo apt update sudo apt install mpv -y curl -LO https://github.com/alvarorichard/Goanime/releases/latest/download/goanime-linux-amd64.tar.gz tar -xzf goanime-linux-amd64.tar.gz chmod +x goanime-linux-amd64 sudo mv goanime-linux-amd64 /usr/local/bin/goanime ``` -------------------------------- ### Install GoAnime via Go Source: https://github.com/alvarorichard/goanime/blob/main/README.md Use this command to install GoAnime if you have Go installed on your system. Ensure you are using the latest version. ```bash go install github.com/alvarorichard/Goanime/cmd/goanime@latest ``` -------------------------------- ### Install GoAnime on Fedora Source: https://github.com/alvarorichard/goanime/blob/main/README.md Update system packages, install mpv, download the GoAnime binary, make it executable, and move it to /usr/local/bin. ```bash sudo dnf update sudo dnf install mpv curl -LO https://github.com/alvarorichard/Goanime/releases/latest/download/goanime-linux-amd64.tar.gz tar -xzf goanime-linux-amd64.tar.gz chmod +x goanime-linux-amd64 sudo mv goanime-linux-amd64 /usr/local/bin/goanime ``` -------------------------------- ### Clone Repository and Set Up Environment Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Clone the GoAnime repository, navigate into the directory, and install dependencies using Nix or `go mod tidy`. ```bash git clone https://github.com/alvarorichard/GoAnime.git cd GoAnime git checkout dev nix-shell go mod tidy ``` -------------------------------- ### Example Go Code Structure and Documentation Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Illustrates standard Go package organization, constructor patterns, and documentation for exported types and functions. ```go // Package player provides video playback functionality for GoAnime. package player import ( "context" "fmt" "log" ) // Player represents a video player instance. type Player struct { config Config state State } // NewPlayer creates a new player instance with the given configuration. func NewPlayer(config Config) (*Player, error) { if err := config.Validate(); err != nil { return nil, fmt.Errorf("invalid config: %w", err) } return &Player{ config: config, state: StateIdle, }, nil } ``` -------------------------------- ### GoAnime CLI Usage Examples Source: https://context7.com/alvarorichard/goanime/llms.txt Examples of using the GoAnime command-line interface for interactive search, direct search, updates, and help. ```bash # Basic usage - interactive search goanime # Direct search by anime name goanime "Naruto" # Update the application to latest version goanime --update # Show version information goanime --version # Show help goanime -h ``` -------------------------------- ### Install GoAnime on macOS Source: https://github.com/alvarorichard/goanime/blob/main/README.md Install mpv using Homebrew, then download and make the GoAnime binary executable. This method places the binary in /usr/local/bin. ```bash brew install mpv curl -Lo goanime https://github.com/alvarorichard/GoAnime/releases/latest/download/goanime-apple-darwin chmod +x goanime sudo mv goanime /usr/local/bin/ sudo xattr -d com.apple.quarantine /usr/local/bin/goanime ``` -------------------------------- ### GoAnime Basic Usage Examples Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md Demonstrates fundamental GoAnime commands for searching, downloading, and specifying sources or quality. ```bash # Search all sources goanime "naruto" ``` ```bash # Download with specific source goanime -d --source allanime "one piece" 1 ``` ```bash # Download with quality preference goanime -d --quality 720p "attack on titan" 5 ``` ```bash # Download range with specific source and quality goanime -d -r --source animefire --quality best "demon slayer" 1-12 ``` -------------------------------- ### Install GoAnime on Arch Linux/Manjaro Source: https://github.com/alvarorichard/goanime/blob/main/README.md Install GoAnime from the Arch User Repository (AUR) using yay. ```bash yay -S goanime ``` -------------------------------- ### Install SQLite Development Libraries (Fedora) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Installs the necessary SQLite development libraries for building GoAnime with SQLite support on Fedora systems. ```bash sudo dnf install sqlite-devel ``` -------------------------------- ### Quick Start: Search Anime Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md Initialize a new client and search for anime across all sources. Handles basic search functionality and error checking. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { // Create a new client client := goanime.NewClient() // Search for anime across all sources results, err := client.SearchAnime("One Piece", nil) if err != nil { log.Fatal(err) } fmt.Printf("Found %d results\n", len(results)) for i, anime := range results { fmt.Printf("%d. %s [%s]\n", i+1, anime.Name, anime.Source) } } ``` -------------------------------- ### Install SQLite Development Libraries (Ubuntu/Debian) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Installs the necessary SQLite development libraries for building GoAnime with SQLite support on Ubuntu/Debian-based systems. ```bash sudo apt-get install libsqlite3-dev ``` -------------------------------- ### Install SQLite Development Libraries (Arch Linux) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Installs the necessary SQLite development libraries for building GoAnime with SQLite support on Arch Linux systems. ```bash sudo pacman -S sqlite ``` -------------------------------- ### Install SQLite Development Libraries (macOS) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Installs the necessary SQLite development libraries for building GoAnime with SQLite support on macOS using Homebrew. ```bash brew install sqlite3 ``` -------------------------------- ### Quick Start: Search Anime with Goanime Source: https://github.com/alvarorichard/goanime/blob/main/pkg/README.md Initialize the Goanime client and search for anime. Handles potential errors during the search process. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" ) func main() { // Create a new client client := goanime.NewClient() // Search for anime results, err := client.SearchAnime("One Piece", nil) if err != nil { log.Fatal(err) } // Display results for _, anime := range results { fmt.Printf("%s [%s]\n", anime.Name, anime.Source) } } ``` -------------------------------- ### Example Table-Driven Test Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Demonstrates a table-driven test structure for the `Play` function in Go. This pattern is recommended for testing multiple scenarios efficiently. ```go func TestPlayer_Play(t *testing.T) { tests := []struct { name string input string wantErr bool }{ { name: "valid video file", input: "test.mp4", wantErr: false, }, { name: "invalid file", input: "", wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := NewPlayer(DefaultConfig()) err := p.Play(tt.input) if (err != nil) != tt.wantErr { t.Errorf("Play() error = %v, wantErr %v", err, tt.wantErr) } }) } } ``` -------------------------------- ### Interactive Update Menu Example Source: https://github.com/alvarorichard/goanime/blob/main/docs/AUTO_UPDATE.md This is an example of the interactive menu presented when a GoAnime update is available. It shows current and latest versions, along with options to update, skip, or view release notes. ```text ┃ Update Available! ┃ A new version of GoAnime is available. ┃ ┃ Current: v1.0.0 ┃ Latest: v1.1.0 (4.0 MB) ┃ ┃ Would you like to update now? ┃ > Yes, update now ┃ No, maybe later ┃ Show release notes ``` -------------------------------- ### GoAnime Advanced Usage Examples Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md Illustrates advanced GoAnime commands for targeting specific sources, qualities, and automatic selection. ```bash # Use AllAnime for high-quality content goanime -d --source allanime --quality 1080p "jujutsu kaisen" 10 ``` ```bash # Use AnimeFire for Portuguese content goanime -d --source animefire "naruto" 25 ``` ```bash # Let the system choose the best source automatically goanime -d --quality best "bleach" 100 ``` -------------------------------- ### GoAnime Debug Mode Example Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md Run GoAnime with the --debug flag to enable verbose logging for troubleshooting, specifying source and download options. ```bash goanime --debug -d --source allanime "your anime" 1 ``` -------------------------------- ### Error Handling Example Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md Demonstrates how to handle errors returned by Goanime client methods. ```APIDOC ## Error Handling All methods return errors that should be properly handled: ```go results, err := client.SearchAnime("One Piece", nil) if err != nil { // Handle error appropriately log.Printf("Search failed: %v", err) return } ``` ``` -------------------------------- ### Goanime Error Handling Examples Source: https://context7.com/alvarorichard/goanime/llms.txt Illustrates how to handle various errors when using the Goanime library, including unavailable sources, no search results, and failed stream URL extraction. Shows how to use errors.Is for specific error types. ```go package main import ( "errors" "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { client := goanime.NewClient() // Handle search errors results, err := client.SearchAnime("NonexistentAnime123456", nil) if err != nil { // Check for specific error types if errors.Is(err, goanime.ErrSourceUnavailable) { log.Printf("Source is temporarily unavailable: %v", err) // Retry with a different source or wait } else { log.Printf("Search failed: %v", err) } return } // Handle empty results if len(results) == 0 { fmt.Println("No anime found with that name. Try a different search term.") return } // Handle episode fetch errors anime := results[0] source, err := types.ParseSource(anime.Source) if err != nil { log.Printf("Unknown source '%s': %v", anime.Source, err) return } episodes, err := client.GetAnimeEpisodes(anime.URL, source) if err != nil { log.Printf("Failed to fetch episodes: %v", err) return } if len(episodes) == 0 { fmt.Println("No episodes available for this anime.") return } // Handle stream URL errors streamURL, metadata, err := client.GetEpisodeStreamURL(anime, episodes[0], &goanime.StreamOptions{ Quality: "1080p", Mode: "sub", }) if err != nil { // Stream URL extraction can fail due to various reasons log.Printf("Failed to get stream URL: %v", err) // Try with different quality streamURL, metadata, err = client.GetEpisodeStreamURL(anime, episodes[0], &goanime.StreamOptions{ Quality: "720p", Mode: "sub", }) if err != nil { log.Printf("Fallback also failed: %v", err) return } } fmt.Printf("Stream URL: %s\n", streamURL) fmt.Printf("Metadata: %v\n", metadata) } ``` -------------------------------- ### Discord Rich Presence for Media Playback Source: https://context7.com/alvarorichard/goanime/llms.txt Integrates with Discord to display real-time media playback status, including title, episode, progress, and pause state. Requires media data, player control functions, and Discord RPC client setup. ```go package main import ( "sync" "time" "github.com/alvarorichard/Goanime/internal/discord" "github.com/alvarorichard/Goanime/internal/models" "github.com/alvarorichard/Goanime/internal/player" ) func main() { // Create anime data anime := &models.Media{ Name: "Demon Slayer", AnilistID: 101922, MalID: 38000, ImageURL: "https://example.com/cover.jpg", Episodes: []models.Episode{ {Number: "1", Num: 1}, }, } // Setup Discord RPC isPaused := false animeMutex := &sync.Mutex{} socketPath := "/tmp/mpv_socket" // From player.StartVideo() // Create Rich Presence updater updater := discord.NewRichPresenceUpdater( anime, &isPaused, animeMutex, 15*time.Second, // Update frequency 24*time.Minute, // Episode duration socketPath, player.MpvSendCommand, // MPV IPC function ) // Start updating Discord presence updater.Start() defer updater.Stop() // The updater will show: // - Anime title and episode number // - Progress bar with elapsed/remaining time // - Pause state // - Links to AniList/MAL // To login/logout manually: if err := discord.LoginClient(); err != nil { // Handle error } defer discord.LogoutClient() } ``` -------------------------------- ### Create and Commit a New Feature Branch Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Start a new feature branch from the latest `dev` branch, make changes, commit them with a descriptive message, and push to your feature branch. ```bash git checkout dev git pull origin dev git checkout -b feature/your-feature-name # Make your changes... # Commit your changes git add . git commit -m "feat: add your feature description" # Push to your feature branch git push origin feature/your-feature-name ``` -------------------------------- ### GoAnime Troubleshooting: Enable Debug Mode Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md Enable debug mode to get verbose logging output, which is helpful for diagnosing download failures or other issues. ```bash # Enable debug mode goanime --debug -d "your anime" 1 ``` -------------------------------- ### Run the Application Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Execute the compiled Go application. Assumes the application has been built and the executable is in the 'bin' directory. ```bash # Run the application ./bin/goanime ``` -------------------------------- ### Build Application for Current Platform Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Compile the Go application for the current operating system and architecture. The output executable is placed in the 'bin' directory. ```bash # Build for current platform go build -o bin/goanime cmd/goanime/main.go ``` -------------------------------- ### NewClient - Initialize GoAnime Client Source: https://context7.com/alvarorichard/goanime/llms.txt Demonstrates how to create a new GoAnime client instance, which initializes all available scrapers for searching anime across multiple sources. ```APIDOC ## NewClient ### Description Creates a new GoAnime client with all available scrapers initialized for searching anime across multiple sources. ### Method `goanime.NewClient()` ### Endpoint N/A (Library Function) ### Parameters None ### Request Example ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" ) func main() { // Create a new client instance client := goanime.NewClient() // Check available sources sources := client.GetAvailableSources() fmt.Println("Available sources:") for _, source := range sources { fmt.Printf("- %s\n", source.String()) } } ``` ### Response #### Success Response (Client Object) - **client** (*goanime.Client) - An initialized client object ready for use. #### Response Example ```go // Output from GetAvailableSources within the example: // Available sources: // - AllAnime // - AnimeFire ``` ``` -------------------------------- ### Commit Changes Source: https://github.com/alvarorichard/goanime/blob/main/README.md Commit your changes using a conventional commit message format, starting with 'feat:' for new features. ```bash git commit -m "feat: add foo" ``` -------------------------------- ### Initialize GoAnime Client Source: https://context7.com/alvarorichard/goanime/llms.txt Create a new GoAnime client instance to access its functionalities. This initializes all available scrapers for searching anime. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" ) func main() { // Create a new client instance client := goanime.NewClient() // Check available sources sources := client.GetAvailableSources() fmt.Println("Available sources:") for _, source := range sources { fmt.Printf("- %s\n", source.String()) } // Output: // Available sources: // - AllAnime // - AnimeFire } ``` -------------------------------- ### Run Basic Tests Source: https://github.com/alvarorichard/goanime/blob/main/internal/updater/TEST_DOCUMENTATION.md Execute the test suite for the updater module. Use the -v flag for verbose output. ```bash cd /path/to/GoAnime go test ./internal/updater -v ``` -------------------------------- ### Display help message Source: https://github.com/alvarorichard/goanime/blob/main/README.md View all available commands, flags, and options for GoAnime by using the help flag. ```bash goanime -h ``` -------------------------------- ### Get Episodes for an Anime Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md Retrieve a list of episodes for a given anime by its URL and source. Requires parsing the source string into a types.Source enum. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { client := goanime.NewClient() // First, search for anime results, err := client.SearchAnime("Demon Slayer", nil) if err != nil { log.Fatal(err) } if len(results) == 0 { log.Fatal("No anime found") } // Get episodes for the first result anime := results[0] // Parse the source to use the correct scraper source, err := types.ParseSource(anime.Source) if err != nil { log.Fatal(err) } episodes, err := client.GetAnimeEpisodes(anime.URL, source) if err != nil { log.Fatal(err) } fmt.Printf("Found %d episodes\n", len(episodes)) for _, ep := range episodes { fmt.Printf("Episode %s: %s\n", ep.Number, ep.URL) if ep.Title != nil { fmt.Printf(" Title: %s\n", ep.Title.English) } } } ``` -------------------------------- ### Build GoAnime with SQLite Support (Linux) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Compiles GoAnime with full anime progress tracking features using SQLite. Requires SQLite development libraries on Linux. ```bash cd build ./buildlinux-with-sqlite.sh ``` -------------------------------- ### Implement UnifiedScraper Interface in Go Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md This template shows the basic structure for a new anime source client, including the NewSourceClient struct and the SearchAnime method signature. Ensure your implementation adheres to the UnifiedScraper interface. ```go type NewSourceClient struct { client *http.Client baseURL string } func (c *NewSourceClient) SearchAnime(query string, options ...interface{}) ([]*models.Anime, error) { // Implementation here } ``` -------------------------------- ### Get Episode Stream URL Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md Fetch the direct stream URL for an episode, with options for quality and mode (sub/dub). This is the recommended method for obtaining streamable content. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { client := goanime.NewClient() // Search for anime results, err := client.SearchAnime("Attack on Titan", nil) if err != nil { log.Fatal(err) } if len(results) == 0 { log.Fatal("No anime found") } anime := results[0] source, _ := types.ParseSource(anime.Source) // Get episodes episodes, err := client.GetAnimeEpisodes(anime.URL, source) if err != nil { log.Fatal(err) } if len(episodes) == 0 { log.Fatal("No episodes found") } // Get stream URL for first episode using the recommended method // This properly handles AllAnime and AnimeFire sources streamURL, metadata, err := client.GetEpisodeStreamURL(anime, episodes[0], &goanime.StreamOptions{ Quality: "best", // Options: "best", "worst", "1080p", "720p", "480p", "360p" Mode: "sub", // Options: "sub" (subtitled), "dub" (dubbed) }) if err != nil { log.Fatal(err) } fmt.Printf("Stream URL: %s\n", streamURL) fmt.Println("Metadata:") for key, value := range metadata { fmt.Printf(" %s: %s\n", key, value) } // Play with mpv fmt.Printf("\nPlay with: mpv \"%s\"\n", streamURL) } ``` -------------------------------- ### Successful GoAnime Update Log Source: https://github.com/alvarorichard/goanime/blob/main/docs/AUTO_UPDATE.md This log demonstrates a successful GoAnime update process, from checking for updates to confirmation of the new version installation. It includes informational messages about the download and update status. ```bash $ goanime --update INFO GoAnime : Checking for updates... INFO GoAnime : Update available: v1.0.0 → v1.1.0 # Interactive menu appears INFO GoAnime : Downloading GoAnime v1.1.0... INFO GoAnime : Downloading update... INFO GoAnime : Successfully updated to GoAnime v1.1.0! INFO GoAnime : The update has been installed. Please restart GoAnime to use the new version. ``` -------------------------------- ### Goanime Library Types Reference Source: https://context7.com/alvarorichard/goanime/llms.txt Demonstrates the usage of Goanime library types like Source constants and the Anime struct. Shows how to initialize sources and parse them from strings. ```go package main import ( "fmt" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { // Source constants for specifying which scraper to use allAnimeSource := types.SourceAllAnime // AllAnime scraper animeFireSource := types.SourceAnimeFire // AnimeFire scraper (Portuguese) fmt.Printf("Sources: %s, %s\n", allAnimeSource.String(), animeFireSource.String()) // Parse source from string (useful when working with search results) source, err := types.ParseSource("AllAnime") if err != nil { fmt.Printf("Error: %v\n", err) } fmt.Printf("Parsed source: %s\n", source.String()) // Anime struct fields: // - Name: string - Title of the anime // - URL: string - Source-specific URL // - ImageURL: string - Cover/poster image URL // - Episodes: []*Episode - Available episodes (populated by GetAnimeEpisodes) // - AnilistID: int - AniList database ID (if available) // - MalID: int - MyAnimeList database ID (if available) // - Source: string - Source identifier (e.g., "AllAnime", "AnimeFire") // - Details: *AniListDetails - Extended metadata from AniList // Episode struct fields: // - Number: string - Episode number (e.g., "1", "1.5", "OVA") // - Num: int - Episode number as integer // - URL: string - Source-specific URL for the episode // - Title: *TitleDetails - Episode title in multiple languages // - Aired: string - Air date // - Duration: int - Duration in seconds // - IsFiller: bool - Whether this is a filler episode // - IsRecap: bool - Whether this is a recap episode // - Synopsis: string - Episode description // - SkipTimes: *SkipTimes - Timestamps for skipping intro/outro // StreamOptions fields: // - Quality: string - Video quality ("best", "worst", "1080p", "720p", "480p", "360p") // - Mode: string - Audio mode ("sub" for subtitled, "dub" for dubbed) } ``` -------------------------------- ### Get Episode Stream URL with Options Source: https://context7.com/alvarorichard/goanime/llms.txt Retrieves the streaming URL for a specific episode, allowing customization of quality and subtitle mode. Ensure the Goanime client is initialized and anime/episode data is available. ```go package main import ( "fmt" "log" "github.com/alvarorichard/Goanime/pkg/goanime" "github.com/alvarorichard/Goanime/pkg/goanime/types" ) func main() { client := goanime.NewClient() // Search for anime results, err := client.SearchAnime("Attack on Titan", nil) if err != nil { log.Fatal(err) } if len(results) == 0 { log.Fatal("No anime found") } anime := results[0] source, _ := types.ParseSource(anime.Source) // Get episodes episodes, err := client.GetAnimeEpisodes(anime.URL, source) if err != nil { log.Fatal(err) } if len(episodes) == 0 { log.Fatal("No episodes found") } // Get stream URL with options // Quality options: "best", "worst", "1080p", "720p", "480p", "360p" // Mode options: "sub" (subtitled), "dub" (dubbed) streamURL, metadata, err := client.GetEpisodeStreamURL(anime, episodes[0], &goanime.StreamOptions{ Quality: "best", Mode: "sub", }) if err != nil { log.Fatal(err) } fmt.Printf("Stream URL: %s\n", streamURL) // Metadata may contain additional info like actual quality, source server, etc. if len(metadata) > 0 { fmt.Println("Metadata:") for key, value := range metadata { fmt.Printf(" %s: %s\n", key, value) } } // Play with mpv fmt.Printf("\nTo play: mpv \"%s\"\n", streamURL) } ``` -------------------------------- ### GoAnime Troubleshooting: Try Different Sources Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md When no results are found, try explicitly specifying a different source like 'animefire' to broaden the search. ```bash # Try different sources goanime -d --source animefire "your anime" 1 ``` -------------------------------- ### GoAnime CLI Usage Source: https://context7.com/alvarorichard/goanime/llms.txt Demonstrates how to use the GoAnime command-line interface for searching, updating, and displaying version/help information. ```APIDOC ## GoAnime CLI Usage ### Description The main command-line interface for searching, playing, and downloading media content. ### Method CLI Commands ### Endpoint N/A (CLI Application) ### Parameters #### Query Parameters - **"Anime Name"** (string) - Optional - The name of the anime to search for. - **--update** (flag) - Optional - Updates the application to the latest version. - **--version** (flag) - Optional - Shows the application version information. - **-h** (flag) - Optional - Shows the help information. ### Request Example ```bash # Basic usage - interactive search goanime # Direct search by anime name goanime "Naruto" # Update the application to latest version goanime --update # Show version information goanime --version # Show help goanime -h ``` ### Response N/A (CLI Output varies based on command and search results) ``` -------------------------------- ### Control MPV Video Player via IPC Source: https://context7.com/alvarorichard/goanime/llms.txt Use this Go code to interact with an mpv player instance through its IPC socket. It allows starting videos, retrieving playback statistics, controlling playback speed, toggling subtitles, cycling audio/subtitle tracks, and sending custom MPV commands. Ensure mpv is running and its IPC socket is accessible. ```go package main import ( "fmt" "log" "time" "github.com/alvarorichard/Goanime/internal/player" ) func main() { // Start video and get socket path videoURL := "https://example.com/episode.mp4" socketPath, err := player.StartVideo(videoURL, []string{ "--hwdec=auto", // Hardware decoding "--cache=yes", // Enable caching "--demuxer-max-bytes=50M", // Buffer size }) if err != nil { log.Fatal(err) } fmt.Printf("MPV socket: %s\n", socketPath) // Wait for video to load time.Sleep(2 * time.Second) // Get playback statistics stats, err := player.GetPlaybackStats(socketPath) if err != nil { log.Printf("Failed to get stats: %v", err) } else { fmt.Printf("Position: %v seconds\n", stats["time-pos"]) fmt.Printf("Duration: %v seconds\n", stats["duration"]) fmt.Printf("Paused: %v\n", stats["pause"]) fmt.Printf("Volume: %v\n", stats["volume"]) } // Control playback player.SetPlaybackSpeed(socketPath, 1.5) // 1.5x speed player.ToggleSubtitle(socketPath) // Toggle subtitles player.CycleAudioTrack(socketPath) // Next audio track player.CycleSubtitleTrack(socketPath) // Next subtitle track player.SetAudioTrack(socketPath, 2) // Set specific audio track player.SetSubtitleTrack(socketPath, 1) // Set specific subtitle track // Get available tracks audioTracks, _ := player.GetAudioTracks(socketPath) subTracks, _ := player.GetSubtitleTracks(socketPath) fmt.Printf("Audio tracks: %d\n", len(audioTracks)) fmt.Printf("Subtitle tracks: %d\n", len(subTracks)) // Send custom MPV commands result, err := player.MpvSendCommand(socketPath, []any{"get_property", "filename"}) if err == nil { fmt.Printf("Filename: %v\n", result) } } ``` -------------------------------- ### Run Static Analysis Tools Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Execute all mandatory static analysis tools before submitting contributions. Ensure all reported issues are resolved or justified. ```bash # Static analysis (built-in) go vet ./... # Advanced static analysis staticcheck ./... # Security scanner — flags insecure code patterns gosec ./... # Vulnerability check on dependencies govulncheck ./... ``` -------------------------------- ### Stream Anime with MPV Player Source: https://github.com/alvarorichard/goanime/blob/main/pkg/README.md Obtains the stream URL and necessary headers, then constructs and executes an MPV player command. ```go streamURL, headers, _ := client.GetStreamURL(episode.URL, source) // Build MPV command with headers args := []string{streamURL} for key, value := range headers { args = append(args, fmt.Sprintf("--http-header-fields=%s: %s", key, value)) } cmd := exec.Command("mpv", args...) cmd.Run() ``` -------------------------------- ### Build Standard GoAnime (Windows) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Compiles the standard GoAnime build without CGO or SQLite support. This is for Windows systems. ```bash cd build ./buildwindows.sh ``` -------------------------------- ### Format Go Code with `go fmt` Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Ensure consistent Go code style by running `go fmt` on all files or specific files before committing. ```bash # Format all Go files in the project go fmt ./... # Or format specific files go fmt internal/player/player.go ``` -------------------------------- ### GoAnime Help Command Source: https://github.com/alvarorichard/goanime/blob/main/docs/AUTO_UPDATE.md Display GoAnime's help information, which includes details about available flags such as the --update flag for managing software updates. ```bash goanime --help ``` -------------------------------- ### Format Code with Go fmt Source: https://github.com/alvarorichard/goanime/blob/main/README.md Use `go fmt` to ensure code adheres to Go's standard formatting conventions before committing changes. ```bash go fmt ``` -------------------------------- ### Pre-commit Checks Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Run these commands before committing to ensure code quality and correctness. Includes formatting, static analysis, security scanning, linting, and tests. ```bash # Format code go fmt ./... # Built-in static analysis go vet ./... # Advanced static analysis staticcheck ./... # Security scanner gosec ./... # Vulnerability check govulncheck ./... # Run linter golangci-lint run # Run tests go test ./... ``` -------------------------------- ### GoAnime Troubleshooting: Try Different Quality Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md If a stream URL is not found, attempting to use the 'worst' quality setting might resolve the issue. ```bash # Try different quality goanime -d --quality worst "your anime" 1 ``` -------------------------------- ### GoAnime Environment Variables for Configuration Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md Configure GoAnime's default behavior by setting environment variables for quality, source, and download directory. ```bash # Set default quality export GOANIME_DEFAULT_QUALITY=720p ``` ```bash # Set default source export GOANIME_DEFAULT_SOURCE=allanime ``` ```bash # Set download directory export GOANIME_DOWNLOAD_DIR=/path/to/downloads ``` -------------------------------- ### Run All Tests Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Execute all tests in the project. This is a fundamental step in ensuring code quality and functionality. ```bash # Run all tests go test ./... ``` -------------------------------- ### Cross-Platform Build Scripts Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Scripts to build the Go application for different operating systems. These scripts handle cross-compilation, including specific builds for Linux with SQLite support. ```bash # Linux build ./build/buildlinux.sh # Linux with SQLite ./build/buildlinux-with-sqlite.sh # macOS build ./build/buildmacos.sh # Windows build ./build/buildwindows.sh ``` -------------------------------- ### Build Standard GoAnime (Linux) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Compiles the standard GoAnime build without CGO or SQLite support. This is for Linux systems. ```bash cd build ./buildlinux.sh ``` -------------------------------- ### Build Standard GoAnime (macOS) Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Compiles the standard GoAnime build without CGO or SQLite support. This is for macOS systems. ```bash cd build ./buildmacos.sh ``` -------------------------------- ### Run Quick Tests Source: https://github.com/alvarorichard/goanime/blob/main/internal/updater/TEST_DOCUMENTATION.md Execute tests for the updater module, skipping long-running tests. Use the -short flag to enable this behavior. ```bash go test ./internal/updater -v -short ``` -------------------------------- ### Generate Coverage Report Source: https://github.com/alvarorichard/goanime/blob/main/internal/updater/TEST_DOCUMENTATION.md Analyze test coverage by generating a coverage profile and opening it in a web browser. ```bash go test ./internal/updater -cover ``` ```bash go test ./internal/updater -coverprofile=coverage.out ``` ```bash go tool cover -html=coverage.out ``` -------------------------------- ### Search Anime by Name or Source Source: https://github.com/alvarorichard/goanime/blob/main/pkg/README.md Demonstrates searching for anime using the Goanime client. You can search across all sources or specify a particular source. ```go client := goanime.NewClient() // Search all sources results, _ := client.SearchAnime("Naruto", nil) // Search specific source source := types.SourceAllAnime results, _ := client.SearchAnime("Naruto", &source) ``` -------------------------------- ### Check GoAnime Build Version Source: https://github.com/alvarorichard/goanime/blob/main/docs/BUILD_OPTIONS.md Executes the GoAnime binary with the --version flag to check if it was compiled with SQLite tracking support. ```bash ./goanime --version ``` -------------------------------- ### GoAnime Command Equivalents to ani-cli Source: https://github.com/alvarorichard/goanime/blob/main/docs/SCRAPING_INTEGRATION.md Maps common ani-cli commands to their GoAnime equivalents for users migrating from ani-cli. ```bash # ani-cli -d "anime name" episode goanime -d "anime name" episode ``` ```bash # ani-cli -d -r "anime name" 1-5 goanime -d -r "anime name" 1-5 ``` ```bash # ani-cli -q 720p "anime name" goanime -d --quality 720p "anime name" 1 ``` -------------------------------- ### GoAnime Client Methods Source: https://github.com/alvarorichard/goanime/blob/main/pkg/README.md Reference for the main client methods available in the GoAnime library. ```APIDOC ## Client Methods ### `NewClient()` - **Description**: Creates a new instance of the GoAnime client. - **Method**: N/A (Constructor) - **Endpoint**: N/A ### `SearchAnime(query string, source *types.Source) ([]*types.Anime, error)` - **Description**: Searches for anime based on a query string. Optionally filters by a specific source. - **Method**: N/A (Function Call) - **Endpoint**: N/A - **Parameters**: - **query** (string) - Required - The search term for the anime. - **source** (*types.Source) - Optional - A pointer to a specific source to search within. - **Returns**: A slice of `types.Anime` structs and an error if any occurred. ### `GetAnimeEpisodes(animeURL string, source types.Source) ([]*types.Episode, error)` - **Description**: Retrieves a list of episodes for a given anime URL and source. - **Method**: N/A (Function Call) - **Endpoint**: N/A - **Parameters**: - **animeURL** (string) - Required - The URL of the anime. - **source** (types.Source) - Required - The source from which to retrieve episodes. - **Returns**: A slice of `types.Episode` structs and an error if any occurred. ### `GetStreamURL(episodeURL string, source types.Source, options ...interface{}) (string, map[string]string, error)` - **Description**: Extracts the streaming URL and necessary headers for a given episode URL and source. - **Method**: N/A (Function Call) - **Endpoint**: N/A - **Parameters**: - **episodeURL** (string) - Required - The URL of the episode. - **source** (types.Source) - Required - The source from which to retrieve the stream URL. - **options** (...interface{}) - Optional - Additional options for stream URL retrieval. - **Returns**: The stream URL (string), a map of headers (map[string]string), and an error if any occurred. ### `GetAvailableSources() []types.Source` - **Description**: Returns a list of all available anime sources supported by the library. - **Method**: N/A (Function Call) - **Endpoint**: N/A - **Returns**: A slice of `types.Source` representing available sources. ``` -------------------------------- ### Stream Anime with Custom HTTP Client Source: https://github.com/alvarorichard/goanime/blob/main/pkg/README.md Fetches the stream URL and headers, then uses a custom HTTP client to make the request and process the response. ```go streamURL, headers, _ := client.GetStreamURL(episode.URL, source) req, _ := http.NewRequest("GET", streamURL, nil) for key, value := range headers { req.Header.Set(key, value) } resp, _ := http.DefaultClient.Do(req) deferr resp.Body.Close() // Process video stream... ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/alvarorichard/goanime/blob/main/docs/Development.md Execute all tests and generate a code coverage report. Helps identify areas of the codebase not adequately tested. ```bash # Run tests with coverage go test -cover ./... ``` -------------------------------- ### List Available Sources Source: https://github.com/alvarorichard/goanime/blob/main/pkg/goanime/README.md Retrieve and display a list of all anime sources supported by the GoAnime library. Useful for understanding which sources can be queried. ```go package main import ( "fmt" "github.com/alvarorichard/Goanime/pkg/goanime" ) func main() { client := goanime.NewClient() sources := client.GetAvailableSources() fmt.Println("Available sources:") for _, source := range sources { fmt.Printf("- %s\n", source.String()) } } ```