feat: Initial commit

This commit is contained in:
uttarayan21
2025-10-31 20:54:28 +05:30
commit 07027d6121
24 changed files with 68758 additions and 0 deletions

132
api/src/lib.rs Normal file
View File

@@ -0,0 +1,132 @@
use serde::{Deserialize, Serialize};
#[derive(thiserror::Error, Debug)]
pub enum JellyfinApiError {
#[error("Jellyfin API error: {0}")]
ReqwestError(#[from] reqwest::Error),
}
type Result<T, E = JellyfinApiError> = std::result::Result<T, E>;
#[derive(Debug, Clone)]
pub struct JellyfinClient {
client: reqwest::Client,
config: JellyfinConfig,
}
impl JellyfinClient {
pub fn new(config: JellyfinConfig) -> Self {
JellyfinClient {
client: reqwest::Client::new(),
config,
}
}
pub fn post(&self, uri: impl AsRef<str>) -> reqwest::RequestBuilder {
let url = format!("{}/{}", self.config.server_url.as_str(), uri.as_ref());
self.client.post(&url)
.header("X-Emby-Authorization", format!("MediaBrowser Client=\"Jello\", Device=\"Jello\", DeviceId=\"{}\", Version=\"1.0.0\"", self.config.device_id))
.header("Content-Type", "application/json")
}
// pub async fn authenticate(&mut self) -> Result<()> {
// self.post("Users/AuthenticateByName")
// .json(AuthenticateUserByName {
// username: self.config.username.clone(),
// pw: self.config.password.clone(),
// })
// .send()
// .await
// }
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct JellyfinConfig {
pub username: String,
pub password: String,
pub server_url: iref::IriBuf,
pub device_id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct AuthenticationResult {
user: UserDto,
session_info: Option<SessionInfoDto>,
access_token: Option<String>,
server_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct UserDto {}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct SerssionInfoDto {}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct AuthenticateUserByName {
username: String,
pw: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct QuickConnectDto {
secret: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
struct User {
id: String,
configuration: Configuration,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
struct Configuration {
audio_language_preference: Option<String>,
play_default_audio_track: bool,
subtitle_language_preference: String,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
struct Items {
items: Vec<MediaItem>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct MediaItem {
// #[serde(rename = "Id")]
pub id: String,
// #[serde(rename = "Name")]
pub name: String,
// #[serde(rename = "Type")]
pub type_: String,
// #[serde(rename = "Path")]
pub path: Option<String>,
// #[serde(rename = "CollectionType")]
pub collection_type: Option<String>,
// #[serde(rename = "ProductionYear")]
pub year: Option<i32>,
// #[serde(rename = "Overview")]
pub overview: Option<String>,
// #[serde(rename = "CommunityRating")]
pub imdb_rating: Option<f32>,
// #[serde(rename = "CriticRating")]
pub critic_rating: Option<i32>,
// #[serde(rename = "RunTimeTicks")]
pub runtime_ticks: Option<i64>,
// #[serde(rename = "SeriesId")]
pub series_id: Option<String>,
// #[serde(rename = "SeriesName")]
pub series_name: Option<String>,
// #[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i64>,
// #[serde(rename = "IndexNumber")]
pub index_number: Option<i64>,
}