diff --git a/Cargo.lock b/Cargo.lock index da2d1a2..d405a1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2118,7 +2118,7 @@ dependencies = [ [[package]] name = "tdl" -version = "0.2.4" +version = "0.2.5" dependencies = [ "anyhow", "base64 0.13.0", diff --git a/Cargo.toml b/Cargo.toml index b7d4a90..c9e7eee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tdl" description = "A command line tool for downloading files from the TIDAL API" -version = "0.2.4" +version = "0.2.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/api/mod.rs b/src/api/mod.rs index e9090c0..4d3c0a0 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -122,35 +122,37 @@ impl ApiClient { &self, url: &str, opts: Option>, - max: Option, + max: Option, ) -> Result, Error> where T: DeserializeOwned + 'a, { let mut limit = 50; let mut offset = 0; - let max = max.unwrap_or(u32::MAX); - let mut params = vec![ - ("limit".to_string(), limit.to_string()), - ("offset".to_string(), offset.to_string()), - ]; + let max = max.unwrap_or(usize::MAX); + let mut params = vec![("limit".to_string(), limit.to_string())]; if let Some(opt) = opts { params.extend(opt); - } + }; let mut result: Vec = Vec::new(); 'req: loop { + params.push(("offset".to_string(), offset.to_string())); let json = self.get::>(url, Some(¶ms)).await?; limit = json.limit; // the minimum between the items in the response, and the total number of items requested - let item_limit = u32::min(json.total_number_of_items, max); + let item_limit = usize::min(json.total_number_of_items, max); for item in json.items { - if result.len() as u32 >= item_limit { + if result.len() >= item_limit { break 'req; } result.push(item); } offset += limit; + params.pop(); + if offset >= json.total_number_of_items { + break 'req; + } } Ok(result) } diff --git a/src/api/models.rs b/src/api/models.rs index ce7140b..7de5da2 100644 --- a/src/api/models.rs +++ b/src/api/models.rs @@ -63,7 +63,7 @@ impl Default for DeviceAuthRequest { pub struct ItemResponse { pub limit: usize, pub offset: usize, - pub total_number_of_items: u32, + pub total_number_of_items: usize, pub items: Vec, } diff --git a/src/api/search.rs b/src/api/search.rs index 0a3e6db..ec45b2d 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -25,7 +25,7 @@ impl SearchClient { &self, url: &str, query: &str, - max: Option, + max: Option, ) -> Result where T: DeserializeOwned + 'a + Tabled, diff --git a/src/main.rs b/src/main.rs index fbb6376..4848450 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,7 +90,7 @@ async fn consume_channel(channel: ReceiveChannel, concurrency: usize) { async fn search(matches: &ArgMatches) { let client = login().await; if let Some(query) = matches.get_one::("query") { - let max = matches.get_one::("max").cloned(); + let max = matches.get_one::("max").cloned(); let result = match matches.get_one::("filter") { Some(filter) => match filter.as_str() { "artist" => {