diff options
author | metamuffin <metamuffin@disroot.org> | 2023-12-21 23:57:42 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-12-21 23:57:42 +0100 |
commit | 3a29113e965a94bdef06655f1583cc6e86edd606 (patch) | |
tree | a0910fa9687a9935ba1ca85a9cb5def1a0bc9069 /tool/src/import/tmdb.rs | |
parent | a8b2480e898e269e7e0d41dbd46d9a18c7d1e4ba (diff) | |
download | jellything-3a29113e965a94bdef06655f1583cc6e86edd606.tar jellything-3a29113e965a94bdef06655f1583cc6e86edd606.tar.bz2 jellything-3a29113e965a94bdef06655f1583cc6e86edd606.tar.zst |
rework import system pt. 1
Diffstat (limited to 'tool/src/import/tmdb.rs')
-rw-r--r-- | tool/src/import/tmdb.rs | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/tool/src/import/tmdb.rs b/tool/src/import/tmdb.rs deleted file mode 100644 index c38d50e..0000000 --- a/tool/src/import/tmdb.rs +++ /dev/null @@ -1,116 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2023 metamuffin <metamuffin.org> -*/ -use anyhow::Context; -use jellycommon::chrono::{format::Parsed, DateTime, Utc}; -use log::info; -use serde::Deserialize; -use std::io::Write; - -#[derive(Debug, Clone, Deserialize)] -pub struct TmdbQuery { - pub page: usize, - pub results: Vec<TmdbQueryResult>, - pub total_pages: usize, - pub total_results: usize, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct TmdbQueryResult { - pub adult: bool, - pub backdrop_path: Option<String>, - pub genre_ids: Vec<u64>, - pub id: u64, - pub original_language: Option<String>, - pub original_title: Option<String>, - pub overview: String, - pub popularity: f64, - pub poster_path: Option<String>, - pub release_date: Option<String>, - pub title: Option<String>, - pub name: Option<String>, - pub vote_average: f64, - pub vote_count: usize, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct TmdbDetails { - pub adult: bool, - pub backdrop_path: Option<String>, - pub genres: Vec<TmdbGenre>, - pub id: u64, - pub original_language: Option<String>, - pub original_title: Option<String>, - pub overview: String, - pub popularity: f64, - pub poster_path: Option<String>, - pub release_date: Option<String>, - pub title: Option<String>, - pub name: Option<String>, - pub vote_average: f64, - pub vote_count: usize, - pub budget: Option<usize>, - pub homepage: Option<String>, - pub imdb_id: Option<String>, - pub production_companies: Vec<TmdbProductionCompany>, - pub revenue: Option<usize>, - pub tagline: Option<String>, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct TmdbGenre { - pub id: u64, - pub name: String, -} - -#[derive(Debug, Clone, Deserialize)] -pub struct TmdbProductionCompany { - pub id: u64, - pub name: String, - pub logo_path: Option<String>, -} - -pub fn tmdb_search(kind: &str, query: &str, key: &str) -> anyhow::Result<TmdbQuery> { - info!("searching tmdb: {query:?}"); - Ok(reqwest::blocking::get(&format!( - "https://api.themoviedb.org/3/search/{kind}?query={}&api_key={key}", - query.replace(" ", "+") - ))? - .json::<TmdbQuery>()?) -} - -pub fn tmdb_details(kind: &str, id: u64, key: &str) -> anyhow::Result<TmdbDetails> { - info!("fetching details: {id:?}"); - Ok(reqwest::blocking::get(&format!( - "https://api.themoviedb.org/3/{kind}/{id}?api_key={key}" - ))? - .json()?) -} - -pub fn tmdb_image(path: &str, out: &mut impl Write) -> anyhow::Result<()> { - info!("downloading image {path:?}"); - let mut res = reqwest::blocking::get(&format!("https://image.tmdb.org/t/p/original{path}"))?; - res.copy_to(out)?; - Ok(()) -} - -pub fn parse_release_date(d: &str) -> anyhow::Result<DateTime<Utc>> { - let (year, month, day) = (&d[0..4], &d[5..7], &d[8..10]); - let (year, month, day) = ( - year.parse().context("parsing year")?, - month.parse().context("parsing month")?, - day.parse().context("parsing day")?, - ); - - let mut p = Parsed::new(); - p.year = Some(year); - p.month = Some(month); - p.day = Some(day); - p.hour_div_12 = Some(0); - p.hour_mod_12 = Some(0); - p.minute = Some(0); - p.second = Some(0); - Ok(p.to_datetime_with_timezone(&Utc)?) -} |