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:
parent
0f58e8828d
commit
7392e8b619
@ -226,7 +226,7 @@ public:
|
|||||||
///\ tags - Audacity tags object
|
///\ tags - Audacity tags object
|
||||||
///\ tag - name of tag to set
|
///\ tag - name of tag to set
|
||||||
///\ name - name of metadata item to retrieve
|
///\ 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
|
///! Called by Import.cpp
|
||||||
///\return number of readable streams in the file
|
///\return number of readable streams in the file
|
||||||
@ -730,34 +730,39 @@ ProgressResult FFmpegImportFileHandle::WriteData(streamContext *sc)
|
|||||||
|
|
||||||
void FFmpegImportFileHandle::WriteMetadata(Tags *tags)
|
void FFmpegImportFileHandle::WriteMetadata(Tags *tags)
|
||||||
{
|
{
|
||||||
tags->Clear();
|
Tags temp;
|
||||||
|
|
||||||
GetMetadata(tags, TAG_TITLE, "title");
|
GetMetadata(temp, TAG_TITLE, "title");
|
||||||
GetMetadata(tags, TAG_COMMENTS, "comment");
|
GetMetadata(temp, TAG_COMMENTS, "comment");
|
||||||
GetMetadata(tags, TAG_ALBUM, "album");
|
GetMetadata(temp, TAG_ALBUM, "album");
|
||||||
GetMetadata(tags, TAG_TRACK, "track");
|
GetMetadata(temp, TAG_TRACK, "track");
|
||||||
GetMetadata(tags, TAG_GENRE, "genre");
|
GetMetadata(temp, TAG_GENRE, "genre");
|
||||||
|
|
||||||
if (wxString(mFormatContext->iformat->name).Contains("m4a"))
|
if (wxString(mFormatContext->iformat->name).Contains("m4a"))
|
||||||
{
|
{
|
||||||
GetMetadata(tags, TAG_ARTIST, "artist");
|
GetMetadata(temp, TAG_ARTIST, "artist");
|
||||||
GetMetadata(tags, TAG_YEAR, "date");
|
GetMetadata(temp, TAG_YEAR, "date");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetMetadata(tags, TAG_ARTIST, "author");
|
GetMetadata(temp, TAG_ARTIST, "author");
|
||||||
GetMetadata(tags, TAG_YEAR, "year");
|
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;
|
AVDictionaryEntry *meta;
|
||||||
|
|
||||||
meta = av_dict_get(mFormatContext->metadata, name, NULL, AV_DICT_IGNORE_SUFFIX);
|
meta = av_dict_get(mFormatContext->metadata, name, NULL, AV_DICT_IGNORE_SUFFIX);
|
||||||
if (meta)
|
if (meta)
|
||||||
{
|
{
|
||||||
tags->SetTag(tag, wxString::FromUTF8(meta->value));
|
tags.SetTag(tag, wxString::FromUTF8(meta->value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,34 +443,36 @@ ProgressResult FLACImportFileHandle::Import(WaveTrackFactory *trackFactory,
|
|||||||
wxString comment;
|
wxString comment;
|
||||||
wxString description;
|
wxString description;
|
||||||
|
|
||||||
tags->Clear();
|
|
||||||
size_t cnt = mFile->mComments.size();
|
size_t cnt = mFile->mComments.size();
|
||||||
for (size_t c = 0; c < cnt; c++) {
|
if (cnt > 0) {
|
||||||
wxString name = mFile->mComments[c].BeforeFirst(wxT('='));
|
tags->Clear();
|
||||||
wxString value = mFile->mComments[c].AfterFirst(wxT('='));
|
for (size_t c = 0; c < cnt; c++) {
|
||||||
wxString upper = name.Upper();
|
wxString name = mFile->mComments[c].BeforeFirst(wxT('='));
|
||||||
if (upper == wxT("DATE") && !tags->HasTag(TAG_YEAR)) {
|
wxString value = mFile->mComments[c].AfterFirst(wxT('='));
|
||||||
long val;
|
wxString upper = name.Upper();
|
||||||
if (value.length() == 4 && value.ToLong(&val)) {
|
if (upper == wxT("DATE") && !tags->HasTag(TAG_YEAR)) {
|
||||||
name = 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()) {
|
if (comment.empty()) {
|
||||||
comment = description;
|
comment = description;
|
||||||
}
|
}
|
||||||
if (!comment.empty()) {
|
if (!comment.empty()) {
|
||||||
tags->SetTag(TAG_COMMENTS, comment);
|
tags->SetTag(TAG_COMMENTS, comment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mUpdateResult;
|
return mUpdateResult;
|
||||||
|
@ -661,8 +661,6 @@ bool MP3ImportFileHandle::FillBuffer()
|
|||||||
void MP3ImportFileHandle::LoadID3(Tags *tags)
|
void MP3ImportFileHandle::LoadID3(Tags *tags)
|
||||||
{
|
{
|
||||||
#ifdef USE_LIBID3TAG
|
#ifdef USE_LIBID3TAG
|
||||||
tags->Clear();
|
|
||||||
|
|
||||||
struct id3_file *id3file = NULL;
|
struct id3_file *id3file = NULL;
|
||||||
auto cleanup = finally([&]
|
auto cleanup = finally([&]
|
||||||
{
|
{
|
||||||
@ -686,7 +684,7 @@ void MP3ImportFileHandle::LoadID3(Tags *tags)
|
|||||||
|
|
||||||
// Load the tags
|
// Load the tags
|
||||||
struct id3_tag *id3tags = id3_file_tag(id3file);
|
struct id3_tag *id3tags = id3_file_tag(id3file);
|
||||||
if (!id3tags)
|
if (!id3tags || id3tags->nframes == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -722,6 +720,8 @@ void MP3ImportFileHandle::LoadID3(Tags *tags)
|
|||||||
return wxString((char *) buf, converter);
|
return wxString((char *) buf, converter);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tags->Clear();
|
||||||
|
|
||||||
// Extract tags from ID3 frames and add to our tags
|
// Extract tags from ID3 frames and add to our tags
|
||||||
bool have_year = false;
|
bool have_year = false;
|
||||||
for (unsigned int i = 0; i < id3tags->nframes; ++i)
|
for (unsigned int i = 0; i < id3tags->nframes; ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user