aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 0eab6821c02a71d6927a67bea77da9ee50df7c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
extern crate clap;
extern crate regex;
extern crate reqwest;
extern crate rss;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

mod actions;
mod structs;
mod utils;

use actions::*;
use clap::{Arg, App, SubCommand};
use structs::*;

fn main() {
    let mut state = State::new();

    let matches = App::new("podcast")
        .version("1.0")
        .author("Nathan J. <njaremko@gmail.com>")
        .about("Does awesome things")
        .subcommand(
            SubCommand::with_name("download")
                .about("download episodes of podcast")
                .arg(
                    Arg::with_name("PODCAST")
                        .help("Regex for subscribed podcast")
                        .required(true)
                        .index(1),
                )
                .arg(Arg::with_name("EPISODE").help("Episode index").index(2)),
        )
        .subcommand(
            SubCommand::with_name("list")
                .about("list episodes of podcast")
                .arg(
                    Arg::with_name("PODCAST")
                        .help("Regex for subscribed podcast")
                        .index(1),
                ),
        )
        .subcommand(
            SubCommand::with_name("play")
                .about("list episodes of podcast")
                .arg(
                    Arg::with_name("PODCAST")
                        .help("Regex for subscribed podcast")
                        .required(true)
                        .index(1),
                )
                .arg(
                    Arg::with_name("EPISODE")
                        .help("Episode index")
                        .required(true)
                        .index(2),
                ),
        )
        .subcommand(
            SubCommand::with_name("search")
                .about("searches for podcasts")
                .arg(
                    Arg::with_name("debug")
                        .short("d")
                        .help("print debug information verbosely"),
                ),
        )
        .subcommand(
            SubCommand::with_name("subscribe")
                .about("subscribes to a podcast RSS feed")
                .arg(
                    Arg::with_name("URL")
                        .help("URL to RSS feed")
                        .required(true)
                        .index(1),
                ),
        )
        .subcommand(
            SubCommand::with_name("update").about("update subscribed podcasts"),
        )
        .get_matches();

    match matches.subcommand_name() {
        Some("download") => {
            let download_matches = matches.subcommand_matches("download").unwrap();
            let podcast = download_matches.value_of("PODCAST").unwrap();
            match download_matches.value_of("EPISODE") {
                Some(ep) => download_episode(&state, podcast, ep),
                None => download_all(&state, podcast),
            }
        }
        Some("list") => {
            let list_matches = matches.subcommand_matches("list").unwrap();
            match list_matches.value_of("PODCAST") {
                Some(regex) => list_episodes(&state, regex),
                None => list_subscriptions(&state),
            }
        }
        Some("play") => {
            let play_matches = matches.subcommand_matches("play").unwrap();
            let podcast = play_matches.value_of("PODCAST").unwrap();
            let episode = play_matches.value_of("EPISODE").unwrap();
            play_episode(&state, podcast, episode);
        }
        Some("subscribe") => {
            state.subscribe(
                matches
                    .subcommand_matches("subscribe")
                    .unwrap()
                    .value_of("URL")
                    .unwrap(),
            )
        }
        Some("search") => (),
        Some("update") => update_rss(&state),
        _ => (),
    }
}