1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Bug 621 - Metadata Editor: saved tags not displayed when importing MP2/MP3/FLAC/FFmpeg formats without metadata

This commit is contained in:
Leland Lucius 2021-02-12 08:06:59 -06:00
parent 0f58e8828d
commit 7392e8b619
3 changed files with 47 additions and 40 deletions

View File

@ -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));
}
}

View File

@ -443,8 +443,9 @@ ProgressResult FLACImportFileHandle::Import(WaveTrackFactory *trackFactory,
wxString comment;
wxString description;
tags->Clear();
size_t cnt = mFile->mComments.size();
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('='));
@ -472,6 +473,7 @@ ProgressResult FLACImportFileHandle::Import(WaveTrackFactory *trackFactory,
if (!comment.empty()) {
tags->SetTag(TAG_COMMENTS, comment);
}
}
return mUpdateResult;
}

View File

@ -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)