2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2012-04-23 22:30:06 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
2016-02-19 19:06:06 +01:00
|
|
|
#include "tag/Id3Load.hxx"
|
2017-02-08 08:26:58 +01:00
|
|
|
#include "tag/Rva2.hxx"
|
2021-12-06 09:24:12 +01:00
|
|
|
#include "tag/ReplayGainInfo.hxx"
|
2016-02-23 10:30:06 +01:00
|
|
|
#include "thread/Mutex.hxx"
|
2013-10-26 15:14:54 +02:00
|
|
|
#include "fs/Path.hxx"
|
2023-12-22 18:05:37 +01:00
|
|
|
#include "fs/NarrowPath.hxx"
|
2016-02-23 10:30:06 +01:00
|
|
|
#include "input/InputStream.hxx"
|
|
|
|
#include "input/LocalOpen.hxx"
|
2018-07-17 21:56:43 +02:00
|
|
|
#include "util/PrintException.hxx"
|
2012-04-23 22:30:06 +02:00
|
|
|
|
|
|
|
#include <id3tag.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2014-01-07 23:57:39 +01:00
|
|
|
#include <stdio.h>
|
2012-04-23 22:30:06 +02:00
|
|
|
|
2016-11-24 17:17:08 +01:00
|
|
|
static void
|
|
|
|
DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple)
|
|
|
|
{
|
|
|
|
if (tuple.IsDefined())
|
|
|
|
fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n",
|
2020-09-22 20:24:23 +02:00
|
|
|
name, (double)tuple.gain, (double)tuple.peak);
|
2016-11-24 17:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DumpReplayGainInfo(const ReplayGainInfo &info)
|
|
|
|
{
|
2016-11-24 16:45:56 +01:00
|
|
|
DumpReplayGainTuple("album", info.album);
|
|
|
|
DumpReplayGainTuple("track", info.track);
|
2016-11-24 17:17:08 +01:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:30:06 +02:00
|
|
|
int main(int argc, char **argv)
|
2016-09-09 15:37:06 +02:00
|
|
|
try {
|
2012-04-23 22:30:06 +02:00
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
/* initialize locale */
|
|
|
|
setlocale(LC_CTYPE,"");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (argc != 2) {
|
2013-12-24 14:44:08 +01:00
|
|
|
fprintf(stderr, "Usage: read_rva2 FILE\n");
|
|
|
|
return EXIT_FAILURE;
|
2012-04-23 22:30:06 +02:00
|
|
|
}
|
|
|
|
|
2023-12-22 18:05:37 +01:00
|
|
|
const FromNarrowPath path = argv[1];
|
2016-02-23 10:30:06 +01:00
|
|
|
|
|
|
|
Mutex mutex;
|
2012-04-23 22:30:06 +02:00
|
|
|
|
2018-06-22 19:37:18 +02:00
|
|
|
auto is = OpenLocalInputStream(path, mutex);
|
2012-04-23 22:30:06 +02:00
|
|
|
|
2016-02-23 10:30:06 +01:00
|
|
|
const auto tag = tag_id3_load(*is);
|
2020-02-01 13:49:19 +01:00
|
|
|
if (tag == nullptr) {
|
2016-02-23 10:30:06 +01:00
|
|
|
fprintf(stderr, "No ID3 tag found\n");
|
2012-04-23 22:30:06 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-10-25 19:09:22 +02:00
|
|
|
ReplayGainInfo replay_gain;
|
2013-10-25 19:05:49 +02:00
|
|
|
replay_gain.Clear();
|
2012-04-23 22:30:06 +02:00
|
|
|
|
2016-02-19 19:16:40 +01:00
|
|
|
bool success = tag_rva2_parse(tag.get(), replay_gain);
|
2012-04-23 22:30:06 +02:00
|
|
|
if (!success) {
|
2013-12-24 14:44:08 +01:00
|
|
|
fprintf(stderr, "No RVA2 tag found\n");
|
2012-04-23 22:30:06 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-24 17:17:08 +01:00
|
|
|
DumpReplayGainInfo(replay_gain);
|
2012-04-23 22:30:06 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2018-07-17 21:56:43 +02:00
|
|
|
} catch (...) {
|
|
|
|
PrintException(std::current_exception());
|
2016-09-09 15:37:06 +02:00
|
|
|
return EXIT_FAILURE;
|
2012-04-23 22:30:06 +02:00
|
|
|
}
|