radio-rs

Place a description here.
git clone git://git.alex.balgavy.eu/reponame.git
Log | Files | Refs

main.rs (1914B)


      1 mod config;
      2 mod radio;
      3 mod radios;
      4 mod screen;
      5 use crate::config::*;
      6 use radio::*;
      7 use radios::*;
      8 use std::process::exit;
      9 /* TODO:
     10  * - optionally allow playing video
     11  * - implement additional radios from Ruby scripts
     12  */
     13 fn choose_radio(radios: &Vec<Radio>) -> &Radio {
     14     loop {
     15         let choices: Vec<String> = radios
     16             .iter()
     17             .map(|x| match &x.website {
     18                 Some(w) => format!("{} ({})", x.name, w),
     19                 None => format!("{} ({})", x.name, x.description.as_ref().unwrap()),
     20             })
     21             .collect();
     22 
     23         let (choice_i, _) = match screen::list_menu(&*choices) {
     24             Some((i, s)) => (i, s),
     25             None => continue,
     26         };
     27         let chosen_radio = match radios[choice_i].url {
     28             Some(_) => &radios[choice_i],
     29             None => {
     30                 let subradios = radios[choice_i].radios.as_ref().unwrap();
     31                 let choices: Vec<String> = subradios
     32                     .iter()
     33                     .map(|x| match &x.website {
     34                         Some(w) => format!("{} ({})", x.name, w),
     35                         None => format!("{} ({})", x.name, x.description.as_ref().unwrap()),
     36                     })
     37                     .collect();
     38                 let (choice_i, _) = match screen::list_menu(&*choices) {
     39                     Some((i, s)) => (i, s),
     40                     None => continue,
     41                 };
     42                 &subradios[choice_i]
     43             }
     44         };
     45         return chosen_radio;
     46     }
     47 }
     48 fn main() {
     49     let mut data = config::read_config();
     50 
     51     let top_radios = &mut data.config.radios;
     52     top_radios.push(sounds_of_earth::new()); // this new should be async, it calls API
     53     let chosen_radio = choose_radio(top_radios);
     54     let opts = RadioOptions {
     55         method: data.config.player,
     56         load_options: chosen_radio.mpc_load_option,
     57     };
     58     chosen_radio.play(&opts);
     59 }