From 7392e8b619b282d896b89ecb69526f178c8812f3 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Fri, 12 Feb 2021 08:06:59 -0600 Subject: [PATCH] Bug 621 - Metadata Editor: saved tags not displayed when importing MP2/MP3/FLAC/FFmpeg formats without metadata --- src/import/ImportFFmpeg.cpp | 31 +++++++++++++---------- src/import/ImportFLAC.cpp | 50 +++++++++++++++++++------------------ src/import/ImportMP3.cpp | 6 ++--- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/import/ImportFFmpeg.cpp b/src/import/ImportFFmpeg.cpp index 774ff1cf4..6239768da 100644 --- a/src/import/ImportFFmpeg.cpp +++ b/src/import/ImportFFmpeg.cpp @@ -226,7 +226,7 @@ public: ///\ tags - Audacity tags object ///\ tag - name of tag to set ///\ name - name of metadata item to retrieve - void GetMetadata(Tags *tags, const wxChar *tag, const char *name); + void GetMetadata(Tags &tags, const wxChar *tag, const char *name); ///! Called by Import.cpp ///\return number of readable streams in the file @@ -730,34 +730,39 @@ ProgressResult FFmpegImportFileHandle::WriteData(streamContext *sc) void FFmpegImportFileHandle::WriteMetadata(Tags *tags) { - tags->Clear(); + Tags temp; - GetMetadata(tags, TAG_TITLE, "title"); - GetMetadata(tags, TAG_COMMENTS, "comment"); - GetMetadata(tags, TAG_ALBUM, "album"); - GetMetadata(tags, TAG_TRACK, "track"); - GetMetadata(tags, TAG_GENRE, "genre"); + GetMetadata(temp, TAG_TITLE, "title"); + GetMetadata(temp, TAG_COMMENTS, "comment"); + GetMetadata(temp, TAG_ALBUM, "album"); + GetMetadata(temp, TAG_TRACK, "track"); + GetMetadata(temp, TAG_GENRE, "genre"); if (wxString(mFormatContext->iformat->name).Contains("m4a")) { - GetMetadata(tags, TAG_ARTIST, "artist"); - GetMetadata(tags, TAG_YEAR, "date"); + GetMetadata(temp, TAG_ARTIST, "artist"); + GetMetadata(temp, TAG_YEAR, "date"); } else { - GetMetadata(tags, TAG_ARTIST, "author"); - GetMetadata(tags, TAG_YEAR, "year"); + GetMetadata(temp, TAG_ARTIST, "author"); + GetMetadata(temp, TAG_YEAR, "year"); + } + + if (!temp.IsEmpty()) + { + *tags = temp; } } -void FFmpegImportFileHandle::GetMetadata(Tags *tags, const wxChar *tag, const char *name) +void FFmpegImportFileHandle::GetMetadata(Tags &tags, const wxChar *tag, const char *name) { AVDictionaryEntry *meta; meta = av_dict_get(mFormatContext->metadata, name, NULL, AV_DICT_IGNORE_SUFFIX); if (meta) { - tags->SetTag(tag, wxString::FromUTF8(meta->value)); + tags.SetTag(tag, wxString::FromUTF8(meta->value)); } } diff --git a/src/import/ImportFLAC.cpp b/src/import/ImportFLAC.cpp index 50835daa9..1970b7f91 100644 --- a/src/import/ImportFLAC.cpp +++ b/src/import/ImportFLAC.cpp @@ -443,34 +443,36 @@ ProgressResult FLACImportFileHandle::Import(WaveTrackFactory *trackFactory, wxString comment; wxString description; - tags->Clear(); size_t cnt = mFile->mComments.size(); - for (size_t c = 0; c < cnt; c++) { - wxString name = mFile->mComments[c].BeforeFirst(wxT('=')); - wxString value = mFile->mComments[c].AfterFirst(wxT('=')); - wxString upper = name.Upper(); - if (upper == wxT("DATE") && !tags->HasTag(TAG_YEAR)) { - long val; - if (value.length() == 4 && value.ToLong(&val)) { - name = TAG_YEAR; + if (cnt > 0) { + tags->Clear(); + for (size_t c = 0; c < cnt; c++) { + wxString name = mFile->mComments[c].BeforeFirst(wxT('=')); + wxString value = mFile->mComments[c].AfterFirst(wxT('=')); + wxString upper = name.Upper(); + if (upper == wxT("DATE") && !tags->HasTag(TAG_YEAR)) { + long val; + if (value.length() == 4 && value.ToLong(&val)) { + name = TAG_YEAR; + } } + else if (upper == wxT("COMMENT") || upper == wxT("COMMENTS")) { + comment = value; + continue; + } + else if (upper == wxT("DESCRIPTION")) { + description = value; + continue; + } + tags->SetTag(name, value); } - else if (upper == wxT("COMMENT") || upper == wxT("COMMENTS")) { - comment = value; - continue; - } - else if (upper == wxT("DESCRIPTION")) { - description = value; - continue; - } - tags->SetTag(name, value); - } - if (comment.empty()) { - comment = description; - } - if (!comment.empty()) { - tags->SetTag(TAG_COMMENTS, comment); + if (comment.empty()) { + comment = description; + } + if (!comment.empty()) { + tags->SetTag(TAG_COMMENTS, comment); + } } return mUpdateResult; diff --git a/src/import/ImportMP3.cpp b/src/import/ImportMP3.cpp index fdd95e1ce..8c2ca6b3c 100644 --- a/src/import/ImportMP3.cpp +++ b/src/import/ImportMP3.cpp @@ -661,8 +661,6 @@ bool MP3ImportFileHandle::FillBuffer() void MP3ImportFileHandle::LoadID3(Tags *tags) { #ifdef USE_LIBID3TAG - tags->Clear(); - struct id3_file *id3file = NULL; auto cleanup = finally([&] { @@ -686,7 +684,7 @@ void MP3ImportFileHandle::LoadID3(Tags *tags) // Load the tags struct id3_tag *id3tags = id3_file_tag(id3file); - if (!id3tags) + if (!id3tags || id3tags->nframes == 0) { return; } @@ -722,6 +720,8 @@ void MP3ImportFileHandle::LoadID3(Tags *tags) return wxString((char *) buf, converter); }; + tags->Clear(); + // Extract tags from ID3 frames and add to our tags bool have_year = false; for (unsigned int i = 0; i < id3tags->nframes; ++i)