2024-11-24 23:09:31 -06:00
//! Contains tons of structs used by the library
2024-11-27 21:49:15 -06:00
2024-11-29 15:49:33 -06:00
use std ::collections ::HashMap ;
2024-11-28 23:09:32 -06:00
use rocket ::FromForm ;
2024-11-24 23:09:31 -06:00
pub ( crate ) type AuthFunc = fn ( String ) -> Result < bool , String > ;
// TODO: Figure out what the arguments should be for a search function and what it should return
2024-11-23 18:39:48 -06:00
pub ( crate ) type SearchFunc = fn ( String , Vec < String > ) -> Result < String , String > ;
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// The maximum and defaults for the `limit` parameter in queries
/// `max` is the maximum number of results the program can return
/// `default` is the default number of results the program will return
2024-11-21 13:19:57 -06:00
pub struct Limits {
/*
2024-11-27 21:49:15 -06:00
I don ' t know why this would possibly need to be a u32 , I can ' t imagine you ' ll be returning 4 billion results or whatever
2024-11-21 13:19:57 -06:00
In fact , I * really * hope you aren ' t - if you are , you ' re doing something extremely wrong
But hey , it ' s an option
* /
2024-11-26 23:36:06 -06:00
/// The maximum number of entries that can be listed in a search query
2024-11-27 21:49:15 -06:00
pub max : u32 ,
2024-11-26 23:36:06 -06:00
/// The default number of entries to be listed in a search query
2024-11-27 21:49:15 -06:00
pub default : u32 ,
2024-11-21 13:19:57 -06:00
}
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// A struct holding the info for a type of search
2024-11-21 13:19:57 -06:00
pub struct SearchInfo {
2024-11-26 23:36:06 -06:00
/// What type of search this is - must be `search`, `tv-search`, `movie-search`, `audio-search`, or `book-search`
2024-11-21 13:19:57 -06:00
pub search_type : String ,
2024-11-26 23:36:06 -06:00
/// Whether this search type is available
2024-11-21 13:19:57 -06:00
pub available : bool ,
2024-11-26 23:36:06 -06:00
/// The supported parameters for this search type
2024-11-30 01:12:37 -06:00
///
/// Highly recommended: `q` (free text query)
2024-11-21 13:19:57 -06:00
pub supported_params : Vec < String > ,
}
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// Contains subcategories, for use in `Category`
2024-11-21 13:19:57 -06:00
pub struct Subcategory {
2024-11-26 23:36:06 -06:00
/// The numeric ID of a subcategory
///
/// The (de facto?) standard is `xxyy`, xx being the first two digits of the category, and the last two digits specifying the subcategory; see also: Category
2024-11-27 21:49:15 -06:00
pub id : u32 ,
2024-11-26 23:36:06 -06:00
/// The name of the subcategory, e.g. "Anime" under the "TV" cateogyr
2024-11-21 13:19:57 -06:00
pub name : String ,
}
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// Contains a category, for use in `Caps` and searches as a query parameter
2024-11-21 13:19:57 -06:00
pub struct Category {
2024-11-26 23:36:06 -06:00
/// The numeric ID of a category
///
/// The (de facto?) standard is `xxyy`, xx being the first two digits of the category, and the last two digits specifying the subcategory; see also: Subcategory
2024-11-27 21:49:15 -06:00
pub id : u32 ,
2024-11-26 23:36:06 -06:00
/// The name of the category, e.g. "Movies"
2024-11-21 13:19:57 -06:00
pub name : String ,
2024-11-26 23:36:06 -06:00
/// A vector of all the subcategory in this category
2024-11-21 13:19:57 -06:00
pub subcategories : Vec < Subcategory > ,
}
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// Contains a genre, for use in `Caps` and searches as a query parameter
2024-11-21 13:19:57 -06:00
pub struct Genre {
2024-11-26 23:36:06 -06:00
/// The numeric ID of a genre
///
2024-11-27 21:49:15 -06:00
/// I'm not aware of any standard for numbering this; the specification for Torznab shows an example with an ID of 1.
pub id : u32 ,
2024-11-26 23:36:06 -06:00
/// The numeric ID of the category this genre is for.
2024-11-27 21:49:15 -06:00
pub category_id : u32 ,
2024-11-26 23:36:06 -06:00
/// The name of the genre
2024-11-21 13:19:57 -06:00
pub name : String ,
}
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// Contains a tag, for use in `Caps` and searches as a query parameter
2024-11-21 13:19:57 -06:00
pub struct Tag {
2024-11-26 23:36:06 -06:00
/// The name of a tag for a torrent
2024-11-21 13:19:57 -06:00
pub name : String ,
2024-11-26 23:36:06 -06:00
/// The description of the tag
pub description : String ,
2024-11-21 13:19:57 -06:00
}
2024-11-23 18:39:48 -06:00
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
2024-11-27 21:49:15 -06:00
/// Holds the configuration for the capabilities of the Torznab server (used in `/api?t=caps`)
2024-11-24 23:09:31 -06:00
///
2024-11-29 15:49:33 -06:00
/// <div class="warning">Note that this library might not support all the capabilities listed in yet, so check the README before listing capabilities, or just accept that unsupported capabilities will return error 501.
2024-11-24 23:09:31 -06:00
///
2024-11-27 21:49:15 -06:00
/// It's recommended to add any capabilities you want, and set `available` to `false` in the [`Caps`] struct for any currently unsupported search types.</div>
2024-11-24 23:09:31 -06:00
///
/// TODO: Add a way to partially(?) generate automatically from the Config
2024-11-23 18:39:48 -06:00
pub struct Caps {
2024-11-29 15:49:33 -06:00
/// The server info, like title - optional
2024-11-30 01:12:37 -06:00
///
/// Examples: `version`, `title`, `email`, `url`, `image`
pub server_info : Option < HashMap < String , String > > ,
2024-11-29 15:49:33 -06:00
/// The max and default number of items to be returned by queries - see [`Limits`]
2024-11-23 18:39:48 -06:00
pub limits : Limits ,
2024-11-29 15:49:33 -06:00
/// Info about each type of search
2024-11-23 18:39:48 -06:00
pub searching : Vec < SearchInfo > ,
2024-11-29 15:49:33 -06:00
/// What categories the server has - see [`Category`]
2024-11-23 18:39:48 -06:00
pub categories : Vec < Category > ,
2024-11-29 15:49:33 -06:00
/// What genres the server has - see [`Genre`] (optional)
2024-11-23 18:39:48 -06:00
pub genres : Option < Vec < Genre > > ,
2024-11-29 15:49:33 -06:00
/// What torrents can be tagged with - see [`Tag`] (optional)
2024-11-23 18:39:48 -06:00
pub tags : Option < Vec < Tag > > ,
}
2024-11-24 23:09:31 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// A struct that holds configuration for torznab-toolkit
2024-11-27 21:49:15 -06:00
/// The search function (`/api?t=search`) and capabilities (`/api?t=caps` - struct [`Caps`]) are required
2024-11-24 23:09:31 -06:00
/// Everything else is optional
2024-11-23 18:39:48 -06:00
pub struct Config {
2024-11-29 15:49:33 -06:00
/// The function to use for a free text search
2024-11-26 23:36:06 -06:00
pub search : SearchFunc ,
2024-11-29 15:49:33 -06:00
/// The auth function - if not specified, then no authorization is needed.
2024-11-23 18:39:48 -06:00
pub auth : Option < AuthFunc > ,
2024-11-29 15:49:33 -06:00
/// The capabilities of the indexer - see [`Caps`]
2024-11-23 18:39:48 -06:00
pub caps : Caps ,
2024-11-29 15:49:33 -06:00
/// The function to use for a tv search
2024-11-23 18:39:48 -06:00
pub tvsearch : Option < SearchFunc > ,
2024-11-29 15:49:33 -06:00
/// The function to use for a movie search
2024-11-23 18:39:48 -06:00
pub movie : Option < SearchFunc > ,
2024-11-29 15:49:33 -06:00
/// The function to use for a music search
2024-11-23 18:39:48 -06:00
pub music : Option < SearchFunc > ,
2024-11-29 15:49:33 -06:00
/// The function to use for a book search
2024-11-23 18:39:48 -06:00
pub book : Option < SearchFunc > ,
}
2024-11-27 21:49:15 -06:00
#[ derive(Debug, Clone, PartialEq, Eq, FromForm) ]
2024-11-28 23:09:32 -06:00
pub ( crate ) struct SearchParameters {
2024-11-27 21:49:15 -06:00
/// The text query for the search
pub ( crate ) q : Option < String > ,
/// The apikey, for authentication
pub ( crate ) apikey : Option < String > ,
2024-11-28 23:09:32 -06:00
/// A [`Vec`] containing the numeric category IDs to be included in the search results
pub ( crate ) categories : Option < Vec < u32 > > ,
/// A [`Vec`] containing the extended attribute names to be included in the search results
pub ( crate ) attributes : Option < Vec < String > > ,
/// Whether *all* extended attributes should be included in the search results; overrules `attributes`
pub ( crate ) extended_attrs : Option < bool > ,
2024-11-27 21:49:15 -06:00
/// How many items to skip/offset by in the results.
pub ( crate ) offset : Option < u32 > ,
/// The maximum number of items to return - also limited to whatever `limits` is in [`Caps`]
2024-11-28 23:09:32 -06:00
pub ( crate ) limit : u32 ,
2024-11-27 21:49:15 -06:00
}
2024-11-29 15:49:33 -06:00
#[ derive(Debug, Clone, PartialEq, Eq) ]
/// Holds the info for a torrent
pub struct Torrent {
title : String ,
description : Option < String > ,
size : u64 ,
categories : Vec < Category > ,
seeders : Option < u32 > ,
leechers : Option < u32 > ,
peers : Option < u32 > ,
infohash : Option < String > ,
link : Option < String > ,
torrent_file_url : Option < String > ,
magnet_uri : Option < String > ,
other_attributes : Option < HashMap < String , String > > ,
}