2012-04-23 22:30:06 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2012-04-23 22:30:06 +02: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
2013-10-02 12:22:12 +02:00
|
|
|
#include "ReplayGainInfo.hxx"
|
2018-07-16 19:50:07 +02:00
|
|
|
#include "config/Global.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"
|
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
|
|
|
|
|
|
|
const char *
|
2013-01-30 17:52:51 +01:00
|
|
|
config_get_string(gcc_unused enum ConfigOption option,
|
2017-05-08 14:44:49 +02:00
|
|
|
const char *default_value) noexcept
|
2012-04-23 22:30:06 +02:00
|
|
|
{
|
|
|
|
return default_value;
|
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
name, tuple.gain, tuple.peak);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-02-23 10:30:06 +01:00
|
|
|
const Path path = Path::FromFS(argv[1]);
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (tag == NULL) {
|
|
|
|
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
|
|
|
}
|