Skip to content

Commit

Permalink
Merge pull request #22 from tsirysndr/fix/unknown-station
Browse files Browse the repository at this point in the history
fix(ui): handle unknown station name and bitrate
  • Loading branch information
tsirysndr authored Jan 25, 2025
2 parents d0b756b + f9fe43e commit f1a947f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ fn render_frame(state: Arc<Mutex<State>>, frame: &mut Frame) {
);
render_line(
"Bitrate ",
&format!("{} kbps", &state.br),
&match state.br.is_empty() {
true => "Unknown".to_string(),
false => format!("{} kbps", &state.br),
},
Rect {
x: size.x,
y: match state.now_playing.is_empty() {
Expand Down
8 changes: 6 additions & 2 deletions src/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub async fn exec(name_or_id: &str, provider: &str) -> Result<(), Error> {
};

let mut app = App::new(&ui, &opts, frame_rx);
let station_name = station.name.clone();

thread::spawn(move || {
let client = reqwest::blocking::Client::new();
Expand All @@ -61,12 +62,15 @@ pub async fn exec(name_or_id: &str, provider: &str) -> Result<(), Error> {
let headers = response.headers();
cmd_tx
.send(State {
name: headers
name: match headers
.get("icy-name")
.unwrap_or(&HeaderValue::from_static("Unknown"))
.to_str()
.unwrap()
.to_string(),
{
"Unknown" => station_name,
name => name.to_string(),
},
now_playing,
genre: headers
.get("icy-genre")
Expand Down

0 comments on commit f1a947f

Please sign in to comment.