Skip to content

Commit dc34230

Browse files
authored
Feature/host cli option (#95)
* Add --host cli option * Add host subcommand to print used host
1 parent 162b23a commit dc34230

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod stream;
1010
mod streamlink;
1111

1212
const VERSION: &str = env!("CARGO_PKG_VERSION");
13-
const HOST: &str = "http://freesports.ddns.net";
1413
const BANNER: &str = r#"
1514
| \ __ /\ \ / ___|__ __| _ \ ____| \ \ |
1615
| _ \ / \ /\___ \ | | | __| _ \ |\/ |
@@ -28,6 +27,7 @@ fn main() {
2827
OutputType::Record(opts) => crate::streamlink::run(opts),
2928
OutputType::Cast(opts) => crate::streamlink::run(opts),
3029
OutputType::Completions(opts) => crate::completions::run(opts),
30+
OutputType::Host(host) => println!("{}", host),
3131
}
3232
}
3333

src/opt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use isahc::http::Uri;
55
use std::{path::PathBuf, str::FromStr};
66
use structopt::{clap::AppSettings::DeriveDisplayOrder, StructOpt};
77

8+
const HOST: &str = "http://freesports.ddns.net";
9+
810
pub fn parse_opts() -> OutputType {
911
let opts = Opt::from_args();
1012

@@ -15,6 +17,7 @@ pub fn parse_opts() -> OutputType {
1517
Command::Record { .. } => OutputType::Record(opts),
1618
Command::Cast { .. } => OutputType::Cast(opts),
1719
Command::Completions { .. } => OutputType::Completions(opts),
20+
Command::Host { .. } => OutputType::Host(opts.host),
1821
}
1922
}
2023

@@ -44,6 +47,9 @@ pub struct Opt {
4447
#[structopt(long, global = true)]
4548
/// Disables unavailable stream retry for `play`, `record`, and `cast` commands. Program will exit instead.
4649
pub disable_retry: bool,
50+
#[structopt(long, global = true, default_value = HOST)]
51+
/// Specify a host
52+
pub host: String,
4753
}
4854

4955
#[derive(StructOpt, Debug, PartialEq, Clone)]
@@ -99,6 +105,9 @@ pub enum Command {
99105
/// Target directory to save completions
100106
target: PathBuf,
101107
},
108+
#[structopt(usage = "lazystream host [OPTIONS]")]
109+
/// Print the host used by 'lazystream'
110+
Host,
102111
}
103112

104113
#[derive(StructOpt, Debug, PartialEq, Clone)]
@@ -321,6 +330,7 @@ pub enum OutputType {
321330
Record(Opt),
322331
Cast(Opt),
323332
Completions(Opt),
333+
Host(String),
324334
}
325335

326336
fn parse_date(src: &str) -> Result<NaiveDate, ParseError> {

src/stream.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{
66
},
77
},
88
opt::{Cdn, FeedType, Opt, Quality, Sport},
9-
HOST,
109
};
1110
use chrono::{DateTime, NaiveDate, Utc};
1211
use failure::{bail, format_err, Error, ResultExt};
@@ -58,6 +57,7 @@ impl LazyStream {
5857

5958
let game = Game::new(
6059
opts.sport,
60+
opts.host.clone(),
6161
game_pk,
6262
game_date,
6363
date,
@@ -137,6 +137,7 @@ impl LazyStream {
137137
#[derive(Clone)]
138138
pub struct Game {
139139
sport: Sport,
140+
host: String,
140141
pub game_pk: u64,
141142
pub game_date: DateTime<Utc>,
142143
pub selected_date: NaiveDate,
@@ -149,6 +150,7 @@ pub struct Game {
149150
impl Game {
150151
fn new(
151152
sport: Sport,
153+
host: String,
152154
game_pk: u64,
153155
game_date: DateTime<Utc>,
154156
selected_date: NaiveDate,
@@ -157,6 +159,7 @@ impl Game {
157159
) -> Self {
158160
Game {
159161
sport,
162+
host,
160163
game_pk,
161164
game_date,
162165
selected_date,
@@ -190,6 +193,7 @@ impl Game {
190193

191194
let stream = Stream::new(
192195
id,
196+
self.host.clone(),
193197
self.sport,
194198
feed_type,
195199
self.game_date,
@@ -348,6 +352,7 @@ impl Game {
348352
#[allow(clippy::option_option)]
349353
pub struct Stream {
350354
id: String,
355+
host: String,
351356
sport: Sport,
352357
pub feed_type: FeedType,
353358
game_date: DateTime<Utc>,
@@ -360,13 +365,15 @@ pub struct Stream {
360365
impl Stream {
361366
fn new(
362367
id: String,
368+
host: String,
363369
sport: Sport,
364370
feed_type: FeedType,
365371
game_date: DateTime<Utc>,
366372
selected_date: NaiveDate,
367373
) -> Self {
368374
Stream {
369375
id,
376+
host,
370377
sport,
371378
feed_type,
372379
game_date,
@@ -380,7 +387,7 @@ impl Stream {
380387
pub fn host_link(&self, cdn: Cdn) -> String {
381388
format!(
382389
"{}/getM3U8.php?league={}&date={}&id={}&cdn={}",
383-
HOST,
390+
self.host,
384391
self.sport,
385392
self.selected_date.format("%Y-%m-%d"),
386393
self.id,

0 commit comments

Comments
 (0)