diff options
| author | Yuval Adam <_@yuv.al> | 2024-05-31 12:21:36 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2024-05-31 12:21:36 +0200 |
| commit | 083aa3410d8be297470051e39fb3b62960797bb0 (patch) | |
| tree | 201f3f78af2d159255cc3aeed420fbbadbf41bec /src | |
| parent | 56af6d299b02b07fbce1d650ae27c049dc152fa2 (diff) | |
Basic somafm channels json parse
Diffstat (limited to 'src')
| -rw-r--r-- | src/channels.rs | 19 | ||||
| -rw-r--r-- | src/main.rs | 6 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/channels.rs b/src/channels.rs new file mode 100644 index 0000000..257fa02 --- /dev/null +++ b/src/channels.rs @@ -0,0 +1,19 @@ +use serde::Deserialize; + +#[derive(Deserialize)] +#[allow(dead_code)] +struct Channel { + id: String, + title: String, + description: String, + image: String, +} + +mod tests { + #[test] + fn test_channel_parse() { + let chan_str = r#"{"id":"7soul","title":"Seven Inch Soul","description":"Vintage soul tracks from the original 45 RPM vinyl.","dj":"Dion Watts Garcia","djmail":"dion@somafm.com","genre":"oldies","image":"https://api.somafm.com/img/7soul120.png","largeimage":"https://api.somafm.com/logos/256/7soul256.png","xlimage":"https://api.somafm.com/logos/512/7soul512.png","twitter":"","updated":"1396144686","playlists":[{"url":"https://api.somafm.com/7soul.pls","format":"mp3","quality":"highest"},{"url":"https://api.somafm.com/7soul130.pls","format":"aac","quality":"highest"},{"url":"https://api.somafm.com/7soul64.pls","format":"aacp","quality":"high"},{"url":"https://api.somafm.com/7soul32.pls","format":"aacp","quality":"low"}],"preroll":[],"listeners":"80","lastPlaying":"Durand Jones & The Indications - Is It Any Wonder"}"#; + let chan: super::Channel = serde_json::from_str(chan_str).unwrap(); + assert_eq!(chan.id, "7soul"); + } +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..152a2ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +mod channels; + fn main() { - println!("Hello, world!"); + let url = "https://api.somafm.com/channels.json"; + let res = reqwest::blocking::get(url).unwrap().text().unwrap(); + println!("{res}"); } |
