From 1c271a9d345dfa1763e5f7d5b5aa19d01d8de459 Mon Sep 17 00:00:00 2001 From: Malloc Voidstar <1284317+AlyoshaVasilieva@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:16:11 -0700 Subject: [PATCH] Add page-size option --- Cargo.toml | 2 +- src/main.rs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 347265d..04a8eb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cbc-sl" -version = "0.6.0" +version = "0.6.1" edition = "2021" authors = ["Malloc Voidstar <1284317+AlyoshaVasilieva@users.noreply.github.com>"] license = "Apache-2.0" diff --git a/src/main.rs b/src/main.rs index b47fc3e..91da5c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,12 +37,16 @@ struct Args { /// User-Agent or it will reject your request #[clap(short = 'n', long = "no-run", conflicts_with_all(&["list", "replays"]))] no_run: bool, - /// List available Olympics streams + /// List available Olympics streams (at most page-size are shown) #[clap(short = 'l', long = "list", conflicts_with_all(&["url", "replays"]))] list: bool, - /// List available Olympics replays (at most 24 are shown) + /// List available Olympics replays (at most page-size are shown) #[clap(short = 'a', long = "replays", conflicts_with_all(&["url", "list"]))] replays: bool, + /// Size of a "page" of streams to load. Since this tool only loads one page, this means + /// how many streams/replays to show for --list and --replays + #[clap(long = "page-size", default_value = "24")] + page_size: u8, /// Streamlink log level #[clap(long = "loglevel", value_parser(["none", "error", "warning", "info", "debug", "trace"]), default_value = "info")] loglevel: String, @@ -64,7 +68,7 @@ struct Args { url: Option, } -fn get_live_and_upcoming(agent: &Agent) -> Result { +fn get_live_and_upcoming(agent: &Agent, page_size: u8) -> Result { const LIVE_QUERY: &str = "query contentItemsByItemsQueryFilters($itemsQueryFilters:ItemsQueryFilters\ ,$page:Int,$pageSize:Int,$minPubDate:String,$maxPubDate:String,$lineupOnly:Boolean,$offset:Int)\ @@ -87,7 +91,7 @@ fn get_live_and_upcoming(agent: &Agent) -> Result { "variables": { "lineupOnly": false, "page": 1, - "pageSize": 15, + "pageSize": page_size, "maxPubDate": "now+35d", "minPubDate": "now-14h", "itemsQueryFilters": { @@ -106,7 +110,7 @@ fn get_live_and_upcoming(agent: &Agent) -> Result { Ok(agent.post("https://www.cbc.ca/graphql").send_json(query)?.into_json()?) } -fn get_replays(agent: &Agent) -> Result { +fn get_replays(agent: &Agent, page_size: u8) -> Result { const VOD_QUERY: &str = "query contentItemsByItemsQueryFilters($itemsQueryFilters:\ ItemsQueryFilters,$page:Int,$pageSize:Int,$minPubDate:String,$maxPubDate:String,\ $lineupOnly:Boolean,$offset:Int){allContentItems(itemsQueryFilters:$itemsQueryFilters,\ @@ -129,7 +133,7 @@ fn get_replays(agent: &Agent) -> Result { "variables": { "lineupOnly": false, "page": 1, - "pageSize": 16, + "pageSize": page_size, "itemsQueryFilters": { "types": [ "video" @@ -153,14 +157,15 @@ fn main() -> Result<()> { ab = ab.proxy(Proxy::new(proxy_url_ureq(proxy))?); } let agent = ab.build(); + let psz = args.page_size; if args.list { - for item in get_live_and_upcoming(&agent)?.data.all_content_items.nodes { + for item in get_live_and_upcoming(&agent, psz)?.data.all_content_items.nodes { println!("{}", item.to_human(args.full_urls)?); } return Ok(()); } if args.replays { - for item in get_replays(&agent)?.data.all_content_items.nodes { + for item in get_replays(&agent, psz)?.data.all_content_items.nodes { println!("{}", item.to_human(args.full_urls)?); } return Ok(());