Skip to content

Commit

Permalink
Export cover art metadata comment value as description value in IDSMR…
Browse files Browse the repository at this point in the history
…esourceBag
  • Loading branch information
clsid2 authored and Nevcairiel committed Oct 5, 2018
1 parent 9cc3856 commit 0a413a9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions demuxer/Demuxers/LAVFDemuxer.cpp
Expand Up @@ -695,22 +695,29 @@ STDMETHODIMP CLAVFDemuxer::InitAVFormat(LPCOLESTR pszFileName, BOOL bForce)

const AVDictionaryEntry* attachFilename = av_dict_get(st->metadata, "filename", nullptr, 0);
const AVDictionaryEntry* attachMimeType = av_dict_get(st->metadata, "mimetype", nullptr, 0);
const AVDictionaryEntry* attachDescription = av_dict_get(st->metadata, "comment", nullptr, 0);

if (attachFilename && attachMimeType) {
LPWSTR chFilename = CoTaskGetWideCharFromMultiByte(CP_UTF8, MB_ERR_INVALID_CHARS, attachFilename->value, -1);
LPWSTR chMimetype = CoTaskGetWideCharFromMultiByte(CP_UTF8, MB_ERR_INVALID_CHARS, attachMimeType->value, -1);
LPWSTR chDescription = nullptr;

if (attachDescription)
chDescription = CoTaskGetWideCharFromMultiByte(CP_UTF8, MB_ERR_INVALID_CHARS, attachDescription->value, -1);

if (chFilename && chMimetype)
ResAppend(chFilename, nullptr, chMimetype, st->codecpar->extradata, (DWORD)st->codecpar->extradata_size);
ResAppend(chFilename, chDescription, chMimetype, st->codecpar->extradata, (DWORD)st->codecpar->extradata_size);

SAFE_CO_FREE(chFilename);
SAFE_CO_FREE(chMimetype);
SAFE_CO_FREE(chDescription);
} else {
DbgLog((LOG_TRACE, 10, L" -> Unknown attachment, missing filename or mimetype"));
}
} else if (st->disposition & AV_DISPOSITION_ATTACHED_PIC && st->attached_pic.data && st->attached_pic.size > 0) {
LPWSTR chFilename = nullptr;
LPWSTR chMimeType = nullptr;
LPWSTR chDescription = nullptr;

// gather a filename
const AVDictionaryEntry* attachFilename = av_dict_get(st->metadata, "filename", nullptr, 0);
Expand All @@ -722,6 +729,11 @@ STDMETHODIMP CLAVFDemuxer::InitAVFormat(LPCOLESTR pszFileName, BOOL bForce)
if (attachMimeType)
chMimeType = CoTaskGetWideCharFromMultiByte(CP_UTF8, MB_ERR_INVALID_CHARS, attachMimeType->value, -1);

// gather description
const AVDictionaryEntry* attachDescription = av_dict_get(st->metadata, "comment", nullptr, 0);
if (attachDescription)
chDescription = CoTaskGetWideCharFromMultiByte(CP_UTF8, MB_ERR_INVALID_CHARS, attachDescription->value, -1);

for (int c = 0; c < countof(CoverMimeTypes); c++)
{
if (CoverMimeTypes[c].codec == st->codecpar->codec_id) {
Expand All @@ -742,7 +754,7 @@ STDMETHODIMP CLAVFDemuxer::InitAVFormat(LPCOLESTR pszFileName, BOOL bForce)

// Export embedded cover-art through IDSMResourceBag interface
if (chFilename && chMimeType) {
ResAppend(chFilename, nullptr, chMimeType, st->attached_pic.data, (DWORD)st->attached_pic.size);
ResAppend(chFilename, chDescription, chMimeType, st->attached_pic.data, (DWORD)st->attached_pic.size);
} else {
DbgLog((LOG_TRACE, 10, L" -> Unknown attachment, missing filename or mimetype"));
}
Expand Down

0 comments on commit 0a413a9

Please sign in to comment.