audio tagging utilities

cover_bytes rather than cover_size

Stella 150b2527 f2103cc8

+22 -13
+22 -13
src/main.rs
··· 44 44 title: String, 45 45 artist: String, 46 46 album: Option<String>, 47 - cover_present: bool, 47 + cover_bytes: Option<u64>, 48 48 } 49 49 50 50 impl AudioFileEntry { ··· 52 52 let title = self.tags.title().unwrap_or("Unknown").to_string(); 53 53 let artist = self.tags.artist().unwrap_or("Unknown").to_string(); 54 54 55 - let (album, cover_present) = match self.tags.album() { 56 - Some(a) => (Some(a.title.to_string()), a.cover.is_some()), 57 - None => (None, false), 55 + let (album, cover_size) = match self.tags.album() { 56 + Some(a) => { 57 + let size = a.cover.as_ref().map(|c| c.data.len() as u64); 58 + (Some(a.title.to_string()), size) 59 + } 60 + None => (None, None), 58 61 }; 59 62 60 63 AudioFileSummary { ··· 62 65 title, 63 66 artist, 64 67 album, 65 - cover_present, 68 + cover_bytes: cover_size, 66 69 } 67 70 } 68 71 } ··· 74 77 75 78 impl std::fmt::Debug for AudioFileEntry { 76 79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 77 - let cover_present = match self.tags.album() { 78 - Some(album) => album.cover.is_some(), 79 - None => false, 80 + let cover_size = match self.tags.album() { 81 + Some(album) => album.cover.as_ref().map(|c| c.data.len() as u64), 82 + None => None, 80 83 }; 81 84 82 85 let album_info = self.tags.album().as_ref().map(|a| format!("{} by {}", a.title, a.artist.as_deref().unwrap_or("Unknown Artist"))); ··· 86 89 .field("title", &self.tags.title().unwrap_or("Unknown")) 87 90 .field("artist", &self.tags.artist().unwrap_or("Unknown")) 88 91 .field("album", &album_info) 89 - .field("cover_present", &cover_present) 92 + .field("cover_size", &cover_size) 90 93 .finish() 91 94 } 92 95 } ··· 95 98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 96 99 let title = self.tags.title().unwrap_or("Unknown"); 97 100 let artist = self.tags.artist().unwrap_or("Unknown"); 98 - let (album_info, cover_present) = match self.tags.album() { 101 + let (album_info, cover_size) = match self.tags.album() { 99 102 Some(album) => { 100 103 let artist = album.artist.as_ref().map(|s| &**s).unwrap_or("Unknown Artist"); 101 104 let info = format!("{} by {}", album.title, artist); 102 - (info, album.cover.is_some()) 105 + let size = album.cover.as_ref().map(|c| c.data.len() as u64); 106 + (info, size) 103 107 } 104 - None => ("No album".to_string(), false), 108 + None => ("No album".to_string(), None), 105 109 }; 106 110 107 - write!(f, "{} | {} | {} | {} | cover_present: {}", self.path.display(), title, artist, album_info, cover_present) 111 + let cover_display = match cover_size { 112 + Some(n) => n.to_string(), 113 + None => "none".to_string(), 114 + }; 115 + 116 + write!(f, "{} | {} | {} | {} | cover_size: {}", self.path.display(), title, artist, album_info, cover_display) 108 117 } 109 118 } 110 119