sounds_of_earth.rs (1147B)
1 use crate::config::*; 2 use crate::radio::*; 3 use serde_json; 4 use ureq; 5 fn retrieve_channels() -> Result<Vec<Radio>, ureq::Error> { 6 let uri = "https://soundsofearth.eco/regions.json"; 7 let resp: ureq::Response = ureq::get(uri).call()?; 8 let mut body: serde_json::Value = resp.into_json()?; 9 let mut sounds: Vec<Radio> = serde_json::from_value(body["results"].take()).unwrap(); 10 for s in &mut sounds { 11 s.mpc_load_option = Some(MpcLoadOptions::ADD); 12 } 13 Ok(sounds) 14 } 15 pub fn new() -> Radio { 16 match retrieve_channels() { 17 Ok(radios) => { 18 assert!(radios 19 .iter() 20 .all(|r| r.description.is_some() || r.website.is_some())); 21 assert!(radios.iter().all(|r| r.url.is_some())); 22 return Radio { 23 name: "Sounds of Earth".to_string(), 24 website: Some("https://www.soundsofearth.eco/".to_string()), 25 radios: Some(radios), 26 mpc_load_option: None, 27 url: None, 28 description: None, 29 }; 30 } 31 Err(e) => panic!("error getting channels: {}", e), 32 } 33 }