queue_save: save tags and range of non-database songs

Use the functions song_save() and song_load() to use the same format
as in the database file for those songs which need the tags.
This commit is contained in:
Max Kellermann
2010-07-25 12:21:47 +02:00
parent b01235e330
commit cbb1ab58cd
5 changed files with 64 additions and 22 deletions

View File

@@ -23,11 +23,12 @@
#include "song.h"
#include "uri.h"
#include "database.h"
#include "song_save.h"
#include <stdlib.h>
static void
queue_save_song(FILE *fp, int idx, const struct song *song)
queue_save_database_song(FILE *fp, int idx, const struct song *song)
{
char *uri = song_get_uri(song);
@@ -35,6 +36,21 @@ queue_save_song(FILE *fp, int idx, const struct song *song)
g_free(uri);
}
static void
queue_save_full_song(FILE *fp, const struct song *song)
{
song_save(fp, song);
}
static void
queue_save_song(FILE *fp, int idx, const struct song *song)
{
if (song_in_database(song))
queue_save_database_song(fp, idx, song);
else
queue_save_full_song(fp, song);
}
void
queue_save(FILE *fp, const struct queue *queue)
{
@@ -51,26 +67,40 @@ get_song(const char *uri)
}
void
queue_load_song(struct queue *queue, const char *line)
queue_load_song(FILE *fp, GString *buffer, const char *line,
struct queue *queue)
{
long ret;
char *endptr;
struct song *song;
if (queue_is_full(queue))
return;
ret = strtol(line, &endptr, 10);
if (ret < 0 || *endptr != ':' || endptr[1] == 0) {
g_warning("Malformed playlist line in state file");
return;
if (g_str_has_prefix(line, SONG_BEGIN)) {
const char *uri = line + sizeof(SONG_BEGIN) - 1;
if (!uri_has_scheme(uri) && !g_path_is_absolute(uri))
return;
GError *error = NULL;
song = song_load(fp, NULL, uri, buffer, &error);
if (song == NULL) {
g_warning("%s", error->message);
g_error_free(error);
return;
}
} else {
char *endptr;
long ret = strtol(line, &endptr, 10);
if (ret < 0 || *endptr != ':' || endptr[1] == 0) {
g_warning("Malformed playlist line in state file");
return;
}
line = endptr + 1;
song = get_song(line);
if (song == NULL)
return;
}
line = endptr + 1;
song = get_song(line);
if (song == NULL)
return;
queue_append(queue, song);
}