1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
use std::io::Write;
use log::info;
use serde::Deserialize;
#[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: String,
pub genre_ids: Vec<u64>,
pub id: u64,
pub original_language: String,
pub original_title: String,
pub overview: String,
pub popularity: f64,
pub poster_path: String,
pub release_date: String,
pub title: String,
pub video: bool,
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: String,
pub original_title: String,
pub overview: String,
pub popularity: f64,
pub poster_path: Option<String>,
pub release_date: String,
pub title: String,
pub video: bool,
pub vote_average: f64,
pub vote_count: usize,
pub budget: usize,
pub homepage: String,
pub imdb_id: String,
pub production_companies: Vec<TmdbProductionCompany>,
pub revenue: usize,
pub tagline: 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(query: &str, key: &str) -> anyhow::Result<TmdbQuery> {
info!("searching tmdb: {query:?}");
Ok(reqwest::blocking::get(&format!(
"https://api.themoviedb.org/3/search/movie?query={}&api_key={key}",
query.replace(" ", "+")
))?
.json::<TmdbQuery>()?)
}
pub fn tmdb_details(id: u64, key: &str) -> anyhow::Result<TmdbDetails> {
info!("fetching details: {id:?}");
Ok(reqwest::blocking::get(&format!(
"https://api.themoviedb.org/3/movie/{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(())
}
|