Skip to content

Commit

Permalink
feat: add --live and --wait to poll for new videos automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopolak committed Nov 15, 2022
1 parent 84b9602 commit a4a44d6
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 132 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -15,12 +15,14 @@ Options:
-i, --client-id <CLIENT_ID> The Twitch client ID to use in the request headers
-f, --format <FORMAT> Used with --output or --stdout [default: csv] [possible values: json, csv]
-l, --limit <LIMIT> Downloads the first n videos from each channel
-e, --live If specified, polls for new videos every `poll` seconds
-o, --output <OUTPUT> If specified, pipes data to the file
-p, --postgres [<POSTGRES>] The PostgreSQL connection string [default: DATABASE_URL env]
-q, --quiet Whether to print download progress
-s, --stdout If specified, pipes data to stdout
-t, --threads <THREADS> The number of threads to use [default: 10]
-v, --video <VIDEO> The video ids to download the chat for
-w, --wait <WAIT> The number of minutes to wait between polls (`live` only) [default: 30]
-h, --help Print help information
-V, --version Print version information
```
Expand Down
19 changes: 18 additions & 1 deletion cli/src/cli.rs
Expand Up @@ -19,6 +19,15 @@ impl From<Format> for tcd::gql::prelude::Format {
}
}

impl From<&Format> for tcd::gql::prelude::Format {
fn from(format: &Format) -> Self {
match format {
Format::Json => tcd::gql::prelude::Format::Json,
Format::Csv => tcd::gql::prelude::Format::Csv,
}
}
}

impl std::fmt::Display for Format {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down Expand Up @@ -59,6 +68,10 @@ pub struct Args {
#[clap(short = 'l', long)]
pub limit: Option<usize>,

/// If specified, polls for new videos every `poll` seconds
#[clap(short = 'e', long, default_value_t = false)]
pub live: bool,

/// If specified, pipes data to the file
#[clap(alias = "out", short = 'o', long, value_hint = ValueHint::FilePath)]
pub output: Option<PathBuf>,
Expand All @@ -80,6 +93,10 @@ pub struct Args {
pub threads: usize,

/// The video ids to download the chat for
#[clap(alias = "vid", short = 'v', long)]
#[clap(short = 'v', long)]
pub video: Vec<i64>,

/// The number of minutes to wait between polls (`live` only)
#[clap(short = 'w', long, default_value_t = 30.)]
pub wait: f64,
}

0 comments on commit a4a44d6

Please sign in to comment.