feat: add timezone query option

This commit is contained in:
ThetaDev 2025-01-18 07:03:36 +01:00
parent ccb1178b95
commit 3a2370b97c
No known key found for this signature in database
GPG key ID: E319D3C5148D65B6
14 changed files with 132 additions and 25 deletions

View file

@ -12,6 +12,7 @@ description = "CLI for RustyPipe - download videos and extract data from YouTube
[features]
default = ["native-tls"]
timezone = ["dep:time", "dep:time-tz"]
# Reqwest TLS options
native-tls = [
@ -49,6 +50,8 @@ futures-util.workspace = true
serde.workspace = true
serde_json.workspace = true
quick-xml.workspace = true
time = { workspace = true, optional = true }
time-tz = { workspace = true, optional = true }
indicatif.workspace = true
anyhow.workspace = true

View file

@ -55,6 +55,10 @@ struct Cli {
/// YouTube content country
#[clap(long, global = true)]
country: Option<String>,
/// UTC offset in minutes
#[cfg(feature = "timezone")]
#[clap(long, global = true)]
timezone: Option<String>,
/// Use authentication
#[clap(long, global = true)]
auth: bool,
@ -913,6 +917,20 @@ async fn run() -> anyhow::Result<()> {
if let Some(botguard_bin) = cli.botguard_bin {
rp = rp.botguard_bin(botguard_bin);
}
#[cfg(feature = "timezone")]
if let Some(timezone) = cli.timezone {
use time::OffsetDateTime;
use time_tz::{Offset, TimeZone};
let tz = time_tz::timezones::get_by_name(&timezone).expect("invalid timezone");
let offset = tz
.get_offset_utc(&OffsetDateTime::now_utc())
.to_utc()
.whole_minutes();
rp = rp.timezone(tz.name(), offset);
}
if cli.no_botguard {
rp = rp.no_botguard();
}