diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:21:27 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-25 12:21:27 +0200 |
commit | a491792196c034efbd2f8998944af3f7958c0e52 (patch) | |
tree | a295342aef8cd38e32b05af273ff305b7f2a5cc5 /tool/src/import/tmdb.rs | |
parent | 5aa2a6fa5a6f8daf3ed4d86082658027a44f83c8 (diff) | |
parent | 8fc2d47f1f6cde93554ba096b959b3bef3652ac1 (diff) | |
download | jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar.bz2 jellything-a491792196c034efbd2f8998944af3f7958c0e52.tar.zst |
Merge branch 'master' of codeberg.org:metamuffin/jellything
Diffstat (limited to 'tool/src/import/tmdb.rs')
-rw-r--r-- | tool/src/import/tmdb.rs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tool/src/import/tmdb.rs b/tool/src/import/tmdb.rs new file mode 100644 index 0000000..5f21afd --- /dev/null +++ b/tool/src/import/tmdb.rs @@ -0,0 +1,95 @@ +/* + 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 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(()) +} |