Small refactor

This commit is contained in:
johannesd3 2021-02-09 09:15:55 +01:00
parent d3495cfed4
commit 2f660f74ec

View file

@ -652,15 +652,23 @@ impl PlayerTrackLoader {
], ],
}; };
let (format, file_id) = formats let entry = formats.iter().find_map(|format| {
.iter() if let Some(&file_id) = audio.files.get(format) {
.find_map(|format| Some((format, *audio.files.get(&format)?))) Some((*format, file_id))
.or_else(|| { } else {
warn!("<{}> is not available in any supported format", audio.name);
None None
})?; }
});
let bytes_per_second = self.stream_data_rate(*format); let (format, file_id) = match entry {
Some(t) => t,
None => {
warn!("<{}> is not available in any supported format", audio.name);
return None;
}
};
let bytes_per_second = self.stream_data_rate(format);
let play_from_beginning = position_ms == 0; let play_from_beginning = position_ms == 0;
let key = self.session.audio_key().request(spotify_id, file_id); let key = self.session.audio_key().request(spotify_id, file_id);