aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/playlist_state.c2
-rw-r--r--src/queue_save.c56
-rw-r--r--src/queue_save.h4
-rw-r--r--src/song_save.c18
-rw-r--r--src/song_save.h4
5 files changed, 63 insertions, 21 deletions
diff --git a/src/playlist_state.c b/src/playlist_state.c
index b0f99dd05..89bb56607 100644
--- a/src/playlist_state.c
+++ b/src/playlist_state.c
@@ -108,7 +108,7 @@ playlist_state_load(FILE *fp, GString *buffer, struct playlist *playlist)
}
while (!g_str_has_prefix(line, PLAYLIST_STATE_FILE_PLAYLIST_END)) {
- queue_load_song(&playlist->queue, line);
+ queue_load_song(fp, buffer, line, &playlist->queue);
line = read_text_line(fp, buffer);
if (line == NULL) {
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 <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);
}
diff --git a/src/queue_save.h b/src/queue_save.h
index a3372c1f2..287683390 100644
--- a/src/queue_save.h
+++ b/src/queue_save.h
@@ -25,6 +25,7 @@
#ifndef QUEUE_SAVE_H
#define QUEUE_SAVE_H
+#include <glib.h>
#include <stdio.h>
struct queue;
@@ -36,6 +37,7 @@ queue_save(FILE *fp, const struct queue *queue);
* Loads one song from the state file and appends it to the queue.
*/
void
-queue_load_song(struct queue *queue, const char *line);
+queue_load_song(FILE *fp, GString *buffer, const char *line,
+ struct queue *queue);
#endif
diff --git a/src/song_save.c b/src/song_save.c
index d52f7f51c..a1a573298 100644
--- a/src/song_save.c
+++ b/src/song_save.c
@@ -41,11 +41,9 @@ song_save_quark(void)
return g_quark_from_static_string("song_save");
}
-static int
-song_save(struct song *song, void *data)
+void
+song_save(FILE *fp, const struct song *song)
{
- FILE *fp = data;
-
fprintf(fp, SONG_BEGIN "%s\n", song->uri);
if (song->end_ms > 0)
@@ -58,20 +56,28 @@ song_save(struct song *song, void *data)
fprintf(fp, SONG_MTIME ": %li\n", (long)song->mtime);
fprintf(fp, SONG_END "\n");
+}
+static int
+song_save_callback(struct song *song, void *data)
+{
+ FILE *fp = data;
+ song_save(fp, song);
return 0;
}
void songvec_save(FILE *fp, const struct songvec *sv)
{
- songvec_for_each(sv, song_save, fp);
+ songvec_for_each(sv, song_save_callback, fp);
}
struct song *
song_load(FILE *fp, struct directory *parent, const char *uri,
GString *buffer, GError **error_r)
{
- struct song *song = song_file_new(uri, parent);
+ struct song *song = parent != NULL
+ ? song_file_new(uri, parent)
+ : song_remote_new(uri);
char *line, *colon;
enum tag_type type;
const char *value;
diff --git a/src/song_save.h b/src/song_save.h
index 0be36feca..03285015a 100644
--- a/src/song_save.h
+++ b/src/song_save.h
@@ -26,10 +26,14 @@
#define SONG_BEGIN "song_begin: "
+struct song;
struct songvec;
struct directory;
void
+song_save(FILE *fp, const struct song *song);
+
+void
songvec_save(FILE *fp, const struct songvec *sv);
/**