SongUpdate: move code to handle_lsinfo()
Don't create a temporary Song object in handle_lsinfo(). Instead, print all tags while parsing the remote file.
This commit is contained in:
parent
10406c73b3
commit
8f9ba96c59
@ -130,7 +130,6 @@ struct Song {
|
|||||||
|
|
||||||
bool UpdateFile();
|
bool UpdateFile();
|
||||||
bool UpdateFileInArchive();
|
bool UpdateFileInArchive();
|
||||||
bool UpdateStream();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the URI of the song in UTF-8 encoding, including its
|
* Returns the URI of the song in UTF-8 encoding, including its
|
||||||
|
@ -132,17 +132,3 @@ Song::UpdateFileInArchive()
|
|||||||
tag = tag_builder.CommitNew();
|
tag = tag_builder.CommitNew();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
Song::UpdateStream()
|
|
||||||
{
|
|
||||||
assert(!IsFile());
|
|
||||||
|
|
||||||
TagBuilder tag_builder;
|
|
||||||
if (!tag_stream_scan(uri, full_tag_handler, &tag_builder))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
delete tag;
|
|
||||||
tag = tag_builder.CommitNew();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
@ -35,6 +35,12 @@ void tag_print_types(Client &client)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tag_print(Client &client, TagType type, const char *value)
|
||||||
|
{
|
||||||
|
client_printf(client, "%s: %s\n", tag_item_names[type], value);
|
||||||
|
}
|
||||||
|
|
||||||
void tag_print(Client &client, const Tag &tag)
|
void tag_print(Client &client, const Tag &tag)
|
||||||
{
|
{
|
||||||
if (tag.time >= 0)
|
if (tag.time >= 0)
|
||||||
|
@ -20,11 +20,18 @@
|
|||||||
#ifndef MPD_TAG_PRINT_HXX
|
#ifndef MPD_TAG_PRINT_HXX
|
||||||
#define MPD_TAG_PRINT_HXX
|
#define MPD_TAG_PRINT_HXX
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum TagType : uint8_t;
|
||||||
|
|
||||||
struct Tag;
|
struct Tag;
|
||||||
class Client;
|
class Client;
|
||||||
|
|
||||||
void tag_print_types(Client &client);
|
void tag_print_types(Client &client);
|
||||||
|
|
||||||
|
void
|
||||||
|
tag_print(Client &client, TagType type, const char *value);
|
||||||
|
|
||||||
void
|
void
|
||||||
tag_print(Client &client, const Tag &tag);
|
tag_print(Client &client, const Tag &tag);
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include "Song.hxx"
|
#include "Song.hxx"
|
||||||
#include "SongPrint.hxx"
|
#include "SongPrint.hxx"
|
||||||
#include "TagPrint.hxx"
|
#include "TagPrint.hxx"
|
||||||
|
#include "TagStream.hxx"
|
||||||
|
#include "tag/TagHandler.hxx"
|
||||||
#include "TimePrint.hxx"
|
#include "TimePrint.hxx"
|
||||||
#include "Mapper.hxx"
|
#include "Mapper.hxx"
|
||||||
#include "DecoderPrint.hxx"
|
#include "DecoderPrint.hxx"
|
||||||
@ -98,6 +100,20 @@ handle_close(gcc_unused Client &client,
|
|||||||
return CommandResult::FINISH;
|
return CommandResult::FINISH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_tag(TagType type, const char *value, void *ctx)
|
||||||
|
{
|
||||||
|
Client &client = *(Client *)ctx;
|
||||||
|
|
||||||
|
tag_print(client, type, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr tag_handler print_tag_handler = {
|
||||||
|
nullptr,
|
||||||
|
print_tag,
|
||||||
|
nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
CommandResult
|
CommandResult
|
||||||
handle_lsinfo(Client &client, int argc, char *argv[])
|
handle_lsinfo(Client &client, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -143,16 +159,12 @@ handle_lsinfo(Client &client, int argc, char *argv[])
|
|||||||
return CommandResult::ERROR;
|
return CommandResult::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Song *song = Song::NewRemote(uri);
|
if (!tag_stream_scan(uri, print_tag_handler, &client)) {
|
||||||
if (!song->UpdateStream()) {
|
|
||||||
song->Free();
|
|
||||||
command_error(client, ACK_ERROR_NO_EXIST,
|
command_error(client, ACK_ERROR_NO_EXIST,
|
||||||
"No such file");
|
"No such file");
|
||||||
return CommandResult::ERROR;
|
return CommandResult::ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
song_print_info(client, *song);
|
|
||||||
song->Free();
|
|
||||||
return CommandResult::OK;
|
return CommandResult::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user