musikr: improve id3v2 tag mgmt

This commit is contained in:
Alexander Capehart 2025-02-19 12:08:12 -07:00
parent 313365d118
commit b60e3c5880
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 34 additions and 41 deletions

View file

@ -38,6 +38,9 @@ private object MetadataExtractorImpl : MetadataExtractor {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val fis = FileInputStream(fd.fileDescriptor) val fis = FileInputStream(fd.fileDescriptor)
val input = NativeInputStream(deviceFile, fis) val input = NativeInputStream(deviceFile, fis)
MetadataJNI.openFile(input).also { fis.close() } MetadataJNI.openFile(input).also {
Log.d("MetadataExtractor", "Metadata: ${it?.id3v2}")
fis.close()
}
} }
} }

View file

@ -59,41 +59,31 @@ impl<'local, 'file_ref> JMetadataBuilder<'local, 'file_ref> {
let mut first_pic = None; let mut first_pic = None;
let mut front_cover_pic = None; let mut front_cover_pic = None;
if let Some(frames) = tag.frames() { for mut frame in tag.frames().to_vec() {
for mut frame in frames.to_vec() { if let Some(user_text_frame) = frame.as_user_text_identification() {
if let Some(text_frame) = frame.as_text_identification() { let values = user_text_frame.values();
if let Some(field_list) = text_frame.field_list() { let mut values = values.to_vec();
let values: Vec<String> = field_list if !values.is_empty() {
.to_vec() let description = values.remove(0).to_string();
.into_iter() let remaining: Vec<String> = values.into_iter().map(|s| s.to_string()).collect();
.map(|s| s.to_string()) self.id3v2.add_combined_list(frame.id().to_string_lossy(), description, remaining);
.collect();
self.id3v2.add_id_list(frame.id().to_string_lossy(), values);
}
} else if let Some(user_text_frame) = frame.as_user_text_identification() {
if let Some(values) = user_text_frame.values() {
let mut values = values.to_vec();
if !values.is_empty() {
let description = values.remove(0);
for value in values {
self.id3v2.add_combined(
frame.id().to_string_lossy(),
description.clone(),
value.to_string(),
);
}
} }
} } else if let Some(text_frame) = frame.as_text_identification() {
let field_list = text_frame.field_list();
let values: Vec<String> = field_list
.to_vec()
.into_iter()
.map(|s| s.to_string())
.collect();
self.id3v2.add_id_list(frame.id().to_string_lossy(), values);
} else if let Some(picture_frame) = frame.as_attached_picture() { } else if let Some(picture_frame) = frame.as_attached_picture() {
if first_pic.is_none() { if first_pic.is_none() {
first_pic = picture_frame.picture().map(|p| p.to_vec()); first_pic = Some(picture_frame.picture().to_vec());
} }
// TODO: Check for front cover type when bindings are available
if let (Some(PictureType::FrontCover), None) = if let (Some(PictureType::FrontCover), None) =
(picture_frame.picture_type(), &front_cover_pic) (picture_frame.picture_type(), &front_cover_pic)
{ {
front_cover_pic = picture_frame.picture().map(|p| p.to_vec()); front_cover_pic = Some(picture_frame.picture().to_vec());
}
} }
} }
} }

View file

@ -16,10 +16,10 @@ impl<'file_ref> ID3v2Tag<'file_ref> {
Self { this } Self { this }
} }
pub fn frames(&self) -> Option<FrameList<'file_ref>> { pub fn frames(&self) -> FrameList<'file_ref> {
let frames = bridge::Tag_frameList(self.this.as_ref()); let frames = bridge::Tag_frameList(self.this.as_ref());
let this = OwnedThis::new(frames); let this = OwnedThis::new(frames).unwrap();
this.map(|this| FrameList::new(this)) FrameList::new(this)
} }
} }
@ -94,10 +94,10 @@ impl<'file_ref> TextIdentificationFrame<'file_ref> {
Self { this } Self { this }
} }
pub fn field_list(&self) -> Option<OwnedStringList<'file_ref>> { pub fn field_list(&self) -> OwnedStringList<'file_ref> {
let field_list = bridge::TextIdentificationFrame_fieldList(self.this.as_ref()); let field_list = bridge::TextIdentificationFrame_fieldList(self.this.as_ref());
let this = OwnedThis::new(field_list); let this = OwnedThis::new(field_list).unwrap();
this.map(|this| StringList::new(this)) StringList::new(this)
} }
} }
@ -110,10 +110,10 @@ impl<'file_ref> UserTextIdentificationFrame<'file_ref> {
Self { this } Self { this }
} }
pub fn values(&self) -> Option<OwnedStringList<'file_ref>> { pub fn values(&self) -> OwnedStringList<'file_ref> {
let values = bridge::UserTextIdentificationFrame_fieldList(self.this.as_ref()); let values = bridge::UserTextIdentificationFrame_fieldList(self.this.as_ref());
let this = OwnedThis::new(values); let this = OwnedThis::new(values).unwrap();
this.map(|this| StringList::new(this)) StringList::new(this)
} }
} }
@ -131,9 +131,9 @@ impl<'file_ref> AttachedPictureFrame<'file_ref> {
PictureType::from_u32(picture_type) PictureType::from_u32(picture_type)
} }
pub fn picture(&self) -> Option<OwnedByteVector<'file_ref>> { pub fn picture(&self) -> OwnedByteVector<'file_ref> {
let picture = bridge::AttachedPictureFrame_picture(self.this.as_ref()); let picture = bridge::AttachedPictureFrame_picture(self.this.as_ref());
let this = OwnedThis::new(picture); let this = OwnedThis::new(picture).unwrap();
this.map(|this| ByteVector::new(this)) ByteVector::new(this)
} }
} }