feat(yarr): Added download option

This commit is contained in:
uttarayan21
2025-10-13 20:35:49 +05:30
parent 92d69f13f0
commit f04de80e14
7 changed files with 9733 additions and 12 deletions

View File

@@ -12,6 +12,8 @@ A Rust client library for the Sonarr API.
- **Type-safe API** - All API responses are strongly typed with `serde`
- **Error handling** - Comprehensive error types with detailed error information
- **Easy to use** - Simple client interface with intuitive method names
- **Download after search** - Search for releases and automatically download the best quality
- **Release management** - Full support for searching, filtering, and downloading releases
- **Well documented** - Extensive documentation and examples
## Installation
@@ -48,6 +50,12 @@ async fn main() -> Result<()> {
let queue = client.get_queue().await?;
println!("Items in queue: {}", queue.records.len());
// Search and download the best release for a series
let downloaded = client.search_and_download_best(Some(1), None, None).await?;
if let Some(release) = downloaded {
println!("Downloaded: {}", release.title.unwrap_or_default());
}
Ok(())
}
```
@@ -73,6 +81,12 @@ async fn main() -> Result<()> {
- ✅ Get download queue
- ✅ Get download history
### Releases
- ✅ Search for releases by series/episode/season
- ✅ Download specific releases
- ✅ Automatic best quality selection
- ✅ Advanced filtering and sorting
## Examples
See the `examples/` directory for more comprehensive usage examples:
@@ -81,11 +95,39 @@ See the `examples/` directory for more comprehensive usage examples:
# Run the basic usage example
cargo run --example basic_usage
# Run the download after search example
cargo run --example download_after_search
# Make sure to set your Sonarr URL and API key first:
export SONARR_URL="http://localhost:8989"
export SONARR_API_KEY="your-api-key-here"
```
### Download After Search
The library provides powerful functionality for searching and automatically downloading releases:
```rust
use yarr_api::SonarrClient;
let client = SonarrClient::new(url, api_key);
// Search and download the first available release
let success = client.search_and_download(Some(series_id), None, None).await?;
// Search and download the best quality release
let best_release = client.search_and_download_best(Some(series_id), None, Some(season)).await?;
// Manual search with custom filtering
let releases = client.search_releases(Some(series_id), Some(episode_id), None).await?;
for release in releases {
if release.download_allowed.unwrap_or(false) && !release.rejected.unwrap_or(true) {
client.download_release(&release).await?;
break;
}
}
```
## Error Handling
The library uses a custom `ApiError` type that provides detailed error information:
@@ -121,6 +163,9 @@ All Sonarr API responses are represented as strongly-typed Rust structs:
- `QueueItem` - Download queue items
- `HistoryItem` - Download history
- `HealthResource` - Health check results
- `ReleaseResource` - Release/torrent information with download metadata
- `QualityModel` - Quality information and settings
- `CustomFormatResource` - Custom format definitions
## Contributing