aboutsummaryrefslogtreecommitdiff
path: root/src/queue_save.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-07-25 12:21:47 +0200
committerMax Kellermann <max@duempel.org>2010-07-25 13:28:54 +0200
commitcbb1ab58cdf18b59488d543427cd4ec238426bf8 (patch)
tree06049f1f6ea443d5aeacfc7cbc84a1836aeca1f9 /src/queue_save.c
parentb01235e3307ae9908c3cc08f34a08a13a1b18029 (diff)
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.
Diffstat (limited to 'src/queue_save.c')
-rw-r--r--src/queue_save.c56
1 files changed, 43 insertions, 13 deletions
diff --git a/src/queue_save.c b/src/queue_save.c
index b09f1ecc..afe04ca2 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 <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;
- 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);
}