2012-02-11 16:29:49 +01:00
|
|
|
/*
|
2018-10-31 17:54:59 +01:00
|
|
|
* Copyright 2003-2018 The Music Player Daemon Project
|
2012-02-11 16:29:49 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-01-26 00:37:04 +01:00
|
|
|
/* necessary because libavutil/common.h uses UINT64_C */
|
|
|
|
#define __STDC_CONSTANT_MACROS
|
|
|
|
|
|
|
|
#include "FfmpegMetaData.hxx"
|
2017-02-08 08:26:58 +01:00
|
|
|
#include "tag/Table.hxx"
|
|
|
|
#include "tag/Handler.hxx"
|
2017-07-20 01:43:17 +02:00
|
|
|
#include "tag/Id3MusicBrainz.hxx"
|
2019-06-06 12:02:55 +02:00
|
|
|
#include "util/StringView.hxx"
|
2012-02-11 16:29:49 +01:00
|
|
|
|
2014-12-10 13:40:53 +01:00
|
|
|
extern "C" {
|
|
|
|
#include <libavutil/dict.h>
|
|
|
|
}
|
|
|
|
|
2014-12-09 21:56:22 +01:00
|
|
|
static constexpr struct tag_table ffmpeg_tags[] = {
|
2012-02-13 19:15:18 +01:00
|
|
|
{ "year", TAG_DATE },
|
2012-02-11 16:39:03 +01:00
|
|
|
{ "author-sort", TAG_ARTIST_SORT },
|
|
|
|
{ "album_artist", TAG_ALBUM_ARTIST },
|
|
|
|
{ "album_artist-sort", TAG_ALBUM_ARTIST_SORT },
|
2012-02-11 16:29:49 +01:00
|
|
|
|
|
|
|
/* sentinel */
|
2013-10-28 23:58:17 +01:00
|
|
|
{ nullptr, TAG_NUM_OF_ITEM_TYPES }
|
2012-02-11 16:29:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2014-12-10 13:05:28 +01:00
|
|
|
FfmpegScanTag(TagType type,
|
|
|
|
AVDictionary *m, const char *name,
|
2018-07-05 19:07:05 +02:00
|
|
|
TagHandler &handler) noexcept
|
2012-02-11 16:29:49 +01:00
|
|
|
{
|
2013-10-28 23:58:17 +01:00
|
|
|
AVDictionaryEntry *mt = nullptr;
|
2012-02-11 16:29:49 +01:00
|
|
|
|
2013-10-28 23:58:17 +01:00
|
|
|
while ((mt = av_dict_get(m, name, mt, 0)) != nullptr)
|
2018-07-05 19:07:05 +02:00
|
|
|
handler.OnTag(type, mt->value);
|
2012-02-11 16:29:49 +01:00
|
|
|
}
|
|
|
|
|
2012-02-11 19:24:51 +01:00
|
|
|
static void
|
2018-07-05 19:07:05 +02:00
|
|
|
FfmpegScanPairs(AVDictionary *dict, TagHandler &handler) noexcept
|
2012-02-11 19:24:51 +01:00
|
|
|
{
|
2013-10-28 23:58:17 +01:00
|
|
|
AVDictionaryEntry *i = nullptr;
|
2012-02-11 19:24:51 +01:00
|
|
|
|
2013-10-28 23:58:17 +01:00
|
|
|
while ((i = av_dict_get(dict, "", i, AV_DICT_IGNORE_SUFFIX)) != nullptr)
|
2018-07-05 19:07:05 +02:00
|
|
|
handler.OnPair(i->key, i->value);
|
2012-02-11 19:24:51 +01:00
|
|
|
}
|
|
|
|
|
2012-02-11 16:29:49 +01:00
|
|
|
void
|
2018-07-05 19:07:05 +02:00
|
|
|
FfmpegScanDictionary(AVDictionary *dict, TagHandler &handler) noexcept
|
2012-02-11 16:29:49 +01:00
|
|
|
{
|
2018-07-05 19:07:05 +02:00
|
|
|
if (handler.WantTag()) {
|
2014-12-10 09:35:28 +01:00
|
|
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
2014-12-10 13:05:28 +01:00
|
|
|
FfmpegScanTag(TagType(i), dict, tag_item_names[i],
|
2018-07-05 19:07:05 +02:00
|
|
|
handler);
|
2012-02-11 16:29:49 +01:00
|
|
|
|
2014-12-10 09:35:28 +01:00
|
|
|
for (const struct tag_table *i = ffmpeg_tags;
|
|
|
|
i->name != nullptr; ++i)
|
2014-12-10 13:05:28 +01:00
|
|
|
FfmpegScanTag(i->type, dict, i->name,
|
2018-07-05 19:07:05 +02:00
|
|
|
handler);
|
2017-07-20 01:43:17 +02:00
|
|
|
|
|
|
|
for (const struct tag_table *i = musicbrainz_txxx_tags;
|
|
|
|
i->name != nullptr; ++i)
|
|
|
|
FfmpegScanTag(i->type, dict, i->name,
|
2018-07-05 19:07:05 +02:00
|
|
|
handler);
|
2014-12-10 09:35:28 +01:00
|
|
|
}
|
2012-02-11 19:24:51 +01:00
|
|
|
|
2018-07-05 19:07:05 +02:00
|
|
|
if (handler.WantPair())
|
|
|
|
FfmpegScanPairs(dict, handler);
|
2012-02-11 16:29:49 +01:00
|
|
|
}
|