|
| 1 | +# AllAnime Episode Navigation Enhancement |
| 2 | + |
| 3 | +This document describes the enhanced episode navigation features implemented for AllAnime sources, inspired by the ani-cli project. |
| 4 | + |
| 5 | +## Features Implemented |
| 6 | + |
| 7 | +### 1. AllAnime Navigator (`AllAnimeNavigator`) |
| 8 | +A dedicated navigator class that handles AllAnime-specific episode navigation: |
| 9 | + |
| 10 | +- **Next Episode Navigation**: Seamlessly moves to the next available episode |
| 11 | +- **Previous Episode Navigation**: Moves to the previous episode |
| 12 | +- **Episode Selection**: Direct episode selection by number |
| 13 | +- **Quality Management**: Change video quality (best, 1080p, 720p, 480p, 360p, worst) |
| 14 | +- **Mode Management**: Switch between subtitled (sub) and dubbed (dub) versions |
| 15 | +- **Episode Listing**: Get complete list of available episodes |
| 16 | + |
| 17 | +### 2. Enhanced Playback Controls |
| 18 | +Updated the playback interface to include AllAnime-specific options: |
| 19 | + |
| 20 | +#### Standard Options (All Sources) |
| 21 | +- Next episode (`n`) |
| 22 | +- Previous episode (`p`) |
| 23 | +- Replay current episode (`r`) |
| 24 | +- Select episode (`e`) |
| 25 | +- Change anime (`c`) |
| 26 | +- Quit (`quit`) |
| 27 | + |
| 28 | +#### AllAnime-Specific Options |
| 29 | +- Change quality (`q`) - Allows selection of video quality |
| 30 | +- Change mode (`m`) - Switch between sub/dub versions |
| 31 | + |
| 32 | +### 3. Intelligent Source Detection |
| 33 | +The system automatically detects AllAnime sources through multiple methods: |
| 34 | + |
| 35 | +1. **Source Field**: Checks `anime.Source == "AllAnime"` |
| 36 | +2. **Name Tags**: Detects `[AllAnime]` tags in anime names |
| 37 | +3. **URL Analysis**: Identifies AllAnime URLs containing "allanime" |
| 38 | +4. **ID Pattern**: Recognizes short alphanumeric AllAnime IDs |
| 39 | + |
| 40 | +### 4. Enhanced API Integration |
| 41 | +New API functions for AllAnime navigation: |
| 42 | + |
| 43 | +- `GetEpisodeStreamURLEnhanced()`: Enhanced episode URL fetching |
| 44 | +- `GetAllAnimeEpisodeWithNavigation()`: Navigation-aware episode retrieval |
| 45 | +- `GetAllAnimeEpisodeList()`: Formatted episode list retrieval |
| 46 | + |
| 47 | +## Implementation Details |
| 48 | + |
| 49 | +### Key Files Modified/Created |
| 50 | + |
| 51 | +1. **`internal/playback/allanime_navigation.go`** (NEW) |
| 52 | + - Contains the `AllAnimeNavigator` class |
| 53 | + - Implements episode navigation logic |
| 54 | + - Handles quality and mode management |
| 55 | + |
| 56 | +2. **`internal/playback/series.go`** (ENHANCED) |
| 57 | + - Updated `handleUserNavigation()` to support AllAnime |
| 58 | + - Added `handleUserNavigationEnhanced()` function |
| 59 | + - Integrated AllAnime-specific menu options |
| 60 | + |
| 61 | +3. **`internal/playback/input.go`** (ENHANCED) |
| 62 | + - Added `GetUserInputEnhanced()` function |
| 63 | + - Provides context-aware menu options |
| 64 | + - AllAnime sources get additional quality/mode options |
| 65 | + |
| 66 | +4. **`internal/api/allanime_enhanced.go`** (NEW) |
| 67 | + - Enhanced API functions for AllAnime |
| 68 | + - Navigation-aware episode URL fetching |
| 69 | + - Source detection and validation |
| 70 | + |
| 71 | +5. **`internal/player/scraper.go`** (ENHANCED) |
| 72 | + - Updated `GetVideoURLForEpisodeEnhanced()` function |
| 73 | + - Integrated AllAnime navigation support |
| 74 | + - Fallback mechanism for non-AllAnime sources |
| 75 | + |
| 76 | +### Navigation Flow |
| 77 | + |
| 78 | +``` |
| 79 | +User Input → GetUserInputEnhanced() → handleUserNavigationEnhanced() |
| 80 | + ↓ |
| 81 | +AllAnime Source? → YES → handleAllAnimeNavigation() |
| 82 | + ↓ ↓ |
| 83 | + NO AllAnimeNavigator |
| 84 | + ↓ ↓ |
| 85 | +Regular Navigation Enhanced Navigation |
| 86 | + ↓ ↓ |
| 87 | +Standard Episode Next/Previous with |
| 88 | +Selection AllAnime API |
| 89 | +``` |
| 90 | + |
| 91 | +## ani-cli Compatibility |
| 92 | + |
| 93 | +This implementation closely follows the ani-cli navigation model: |
| 94 | + |
| 95 | +### Similar Features |
| 96 | +- **Next/Previous**: Direct episode navigation like ani-cli's `next`/`previous` commands |
| 97 | +- **Quality Selection**: Multiple quality options similar to ani-cli's quality system |
| 98 | +- **Episode Selection**: Interactive episode picker |
| 99 | +- **Replay**: Ability to replay current episode |
| 100 | +- **Mode Switching**: Sub/dub switching (AllAnime specific) |
| 101 | + |
| 102 | +### Enhanced Features Beyond ani-cli |
| 103 | +- **Source-Aware Navigation**: Automatic detection and handling of different sources |
| 104 | +- **Quality Management**: Interactive quality selection menu |
| 105 | +- **Mode Management**: Interactive sub/dub switching |
| 106 | +- **Fallback Support**: Graceful fallback to regular navigation for non-AllAnime sources |
| 107 | + |
| 108 | +## Usage Examples |
| 109 | + |
| 110 | +### Basic Navigation |
| 111 | +```go |
| 112 | +// Next episode |
| 113 | +selectedEpisode, err := HandleAllAnimeEpisodeNavigation(anime, episodes, currentEpisode, "next") |
| 114 | + |
| 115 | +// Previous episode |
| 116 | +selectedEpisode, err := HandleAllAnimeEpisodeNavigation(anime, episodes, currentEpisode, "previous") |
| 117 | +``` |
| 118 | + |
| 119 | +### Navigator Usage |
| 120 | +```go |
| 121 | +navigator, err := NewAllAnimeNavigator(anime) |
| 122 | +if err != nil { |
| 123 | + // Handle error |
| 124 | +} |
| 125 | + |
| 126 | +// Get next episode |
| 127 | +nextEp, err := navigator.GetNextEpisode(currentEpisode) |
| 128 | + |
| 129 | +// Change quality |
| 130 | +navigator.SetQuality("720p") |
| 131 | + |
| 132 | +// Change mode |
| 133 | +err = navigator.SetMode("dub") |
| 134 | +``` |
| 135 | + |
| 136 | +### Enhanced API Usage |
| 137 | +```go |
| 138 | +// Get episode URL with navigation |
| 139 | +episode, streamURL, err := GetAllAnimeEpisodeWithNavigation(anime, "5", "next") |
| 140 | + |
| 141 | +// Get enhanced stream URL |
| 142 | +streamURL, err := GetEpisodeStreamURLEnhanced(episode, anime, "best") |
| 143 | +``` |
| 144 | + |
| 145 | +## Error Handling |
| 146 | + |
| 147 | +The implementation includes comprehensive error handling: |
| 148 | + |
| 149 | +- **Invalid Navigation**: Prevents navigation beyond first/last episodes |
| 150 | +- **Source Validation**: Ensures AllAnime functions only work with AllAnime sources |
| 151 | +- **API Failures**: Graceful fallback to regular navigation on API errors |
| 152 | +- **Quality/Mode Errors**: User-friendly error messages for invalid selections |
| 153 | + |
| 154 | +## Testing |
| 155 | + |
| 156 | +Unit tests are provided in `allanime_navigation_test.go`: |
| 157 | + |
| 158 | +- Source detection validation |
| 159 | +- ID extraction testing |
| 160 | +- Navigator creation testing |
| 161 | +- Navigation command testing |
| 162 | + |
| 163 | +## Future Enhancements |
| 164 | + |
| 165 | +Potential improvements based on ani-cli features: |
| 166 | + |
| 167 | +1. **Skip Intro/Outro**: Integration with AniSkip for automatic skipping |
| 168 | +2. **Playlist Support**: Batch episode management |
| 169 | +3. **Download Integration**: Enhanced download workflow for AllAnime |
| 170 | +4. **Subtitle Management**: Better subtitle handling |
| 171 | +5. **Search Integration**: Direct anime search from navigation |
| 172 | + |
| 173 | +## Compatibility Notes |
| 174 | + |
| 175 | +- **Backward Compatibility**: All existing functionality remains unchanged |
| 176 | +- **Source Agnostic**: Non-AllAnime sources continue to work normally |
| 177 | +- **Optional Features**: AllAnime-specific features only appear for AllAnime sources |
| 178 | +- **Graceful Degradation**: Falls back to regular navigation on errors |
| 179 | + |
| 180 | +This implementation provides a superior episode navigation experience for AllAnime sources while maintaining full compatibility with existing animefire.plus functionality. |
0 commit comments