From cbb1ab58cdf18b59488d543427cd4ec238426bf8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 25 Jul 2010 12:21:47 +0200 Subject: 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. --- src/queue_save.c | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'src/queue_save.c') diff --git a/src/queue_save.c b/src/queue_save.c index b09f1ecc0..afe04ca2d 100644 --- a/src/queue_save.c +++ b/src/queue_save.c @@ -23,11 +23,12 @@ #include "song.h" #include "uri.h" #include "database.h" +#include "song_save.h" #include 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; - line = endptr + 1; + 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; + } - song = get_song(line); - if (song == NULL) - return; + line = endptr + 1; + + song = get_song(line); + if (song == NULL) + return; + } queue_append(queue, song); } -- cgit v1.2.3