complex_search/
complex_search.rs

1use std::env;
2
3use yt_api::{
4	search::{Error, ItemType, SearchList, VideoLocation},
5	ApiKey,
6};
7
8/// prints the first answer of a search query
9fn main() -> Result<(), Error> {
10	futures::executor::block_on(async {
11		// take api key from enviroment variable
12		let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14		// create the SearchList struct for the query "rust lang"
15		let result = SearchList::new(key)
16			.q("rust lang")
17			.max_results(1)
18			.item_type(ItemType::Video)
19			.location(VideoLocation::new(40.73061, -73.93524))
20			.location_radius("100km")
21			.video_embeddable()
22			.await?;
23
24		// outputs the video_id of the first search result
25		println!(
26			"Title: \"{}\"",
27			result.items[0].snippet.title.as_ref().unwrap()
28		);
29		println!(
30			"https://youtube.com/watch?v={}",
31			result.items[0].id.video_id.as_ref().unwrap()
32		);
33
34		Ok(())
35	})
36}