2016-11-22 16:03:10 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2016-11-22 16:03:10 +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.
|
|
|
|
*/
|
|
|
|
|
2018-08-02 13:45:43 +02:00
|
|
|
#include "song/DetachedSong.hxx"
|
2016-11-22 12:25:52 +01:00
|
|
|
#include "SongSave.hxx"
|
2018-07-17 21:31:06 +02:00
|
|
|
#include "config/Data.hxx"
|
2016-11-22 16:03:10 +01:00
|
|
|
#include "decoder/DecoderList.hxx"
|
|
|
|
#include "decoder/DecoderPlugin.hxx"
|
|
|
|
#include "fs/Path.hxx"
|
2020-04-02 16:40:18 +02:00
|
|
|
#include "fs/NarrowPath.hxx"
|
2016-11-22 16:03:10 +01:00
|
|
|
#include "fs/io/StdioOutputStream.hxx"
|
|
|
|
#include "fs/io/BufferedOutputStream.hxx"
|
2018-07-17 21:56:43 +02:00
|
|
|
#include "util/PrintException.hxx"
|
2019-08-09 15:54:13 +02:00
|
|
|
#include "util/UriExtract.hxx"
|
2016-11-22 16:03:10 +01:00
|
|
|
|
2020-03-12 23:20:59 +01:00
|
|
|
#include <cassert>
|
2016-11-22 16:03:10 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
static const DecoderPlugin *
|
2020-11-04 20:39:06 +01:00
|
|
|
FindContainerDecoderPlugin(std::string_view suffix)
|
2016-11-22 16:03:10 +01:00
|
|
|
{
|
|
|
|
return decoder_plugins_find([suffix](const DecoderPlugin &plugin){
|
|
|
|
return plugin.container_scan != nullptr &&
|
|
|
|
plugin.SupportsSuffix(suffix);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static const DecoderPlugin *
|
|
|
|
FindContainerDecoderPlugin(Path path)
|
|
|
|
{
|
2020-11-04 20:39:06 +01:00
|
|
|
const auto suffix = uri_get_suffix(path.ToUTF8Throw().c_str());
|
|
|
|
if (suffix.empty())
|
2016-11-22 16:03:10 +01:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return FindContainerDecoderPlugin(suffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
try {
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage: ContainerScan PATH\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-04-02 16:40:18 +02:00
|
|
|
const FromNarrowPath path = argv[1];
|
2016-11-22 16:03:10 +01:00
|
|
|
|
2019-02-05 22:11:45 +01:00
|
|
|
const ScopeDecoderPluginsInit decoder_plugins_init({});
|
2016-11-22 16:03:10 +01:00
|
|
|
|
|
|
|
const auto *plugin = FindContainerDecoderPlugin(path);
|
|
|
|
if (plugin == nullptr) {
|
|
|
|
fprintf(stderr, "No decoder found for this file\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto v = plugin->container_scan(path);
|
|
|
|
if (v.empty()) {
|
|
|
|
fprintf(stderr, "File is not a container\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
StdioOutputStream sos(stdout);
|
|
|
|
BufferedOutputStream bos(sos);
|
|
|
|
|
|
|
|
for (const auto &song : v)
|
2016-11-22 12:25:52 +01:00
|
|
|
song_save(bos, song);
|
2016-11-22 16:03:10 +01:00
|
|
|
|
|
|
|
bos.Flush();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2018-07-17 21:56:43 +02:00
|
|
|
} catch (...) {
|
|
|
|
PrintException(std::current_exception());
|
2016-11-22 16:03:10 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|