6f952e65c1372b3a21ffba4819fd3bae34dbd2f5
7 /** \file playlist.c Functions for loading and saving playlists. */
9 /** Structure used for adding entries to a playlist. */
10 struct playlist_info
{
11 /** The name of the playlist. */
13 /** The number of entries currently in the playlist. */
16 static struct playlist_info playlist
;
19 * Re-insert an audio file into the tree of admissible files.
21 * \param aft_row Determines the audio file.
23 * \return The return value of score_update().
25 int playlist_update_audio_file(struct osl_row
*aft_row
)
27 /* always re-insert to the top of the tree */
28 return score_update(aft_row
, 0);
31 static int add_playlist_entry(char *line
, void *private_data
)
33 struct osl_row
*aft_row
;
34 struct playlist_info
*pli
= private_data
;
35 int ret
= aft_get_row_of_path(line
, &aft_row
);
38 PARA_NOTICE_LOG("path not found in audio file table: %s\n",
42 ret
= score_add(aft_row
, -pli
->length
);
44 PARA_ERROR_LOG("failed to add %s: %d\n", line
, ret
);
51 static int load_playlist(struct osl_row
*row
)
53 struct osl_object obj
;
56 ret
= osl_get_object(playlists_table
, row
, BLOBCOL_NAME
, &obj
);
59 playlist
.name
= para_strdup(obj
.data
);
61 ret
= osl_open_disk_object(playlists_table
, row
, BLOBCOL_DEF
, &obj
);
64 ret
= for_each_line_ro(obj
.data
, obj
.size
, add_playlist_entry
,
66 osl_close_disk_object(&obj
);
69 ret
= -E_PLAYLIST_EMPTY
;
72 PARA_NOTICE_LOG("loaded playlist %s (%u files)\n", playlist
.name
,
80 /* returns -E_PLAYLIST_LOADED on _success_ to terminate the loop */
81 static int playlist_loop(struct osl_row
*row
, __a_unused
void *private_data
)
83 int ret
= load_playlist(row
);
85 if (ret
!= -E_DUMMY_ROW
)
86 PARA_NOTICE_LOG("unable to load playlist, trying next\n");
89 return -E_PLAYLIST_LOADED
;
92 static int load_first_available_playlist(void)
94 int ret
= osl_rbtree_loop(playlists_table
, BLOBCOL_NAME
, NULL
,
96 if (ret
== -E_PLAYLIST_LOADED
) /* success */
99 return ret
; /* error */
100 PARA_NOTICE_LOG("no valid playlist found\n");
101 return -E_NO_PLAYLIST
;
105 * Close the current playlist.
107 * \sa playlist_open().
109 void playlist_close(void)
112 playlist
.name
= NULL
;
116 * Open the given playlist.
118 * \param name The name of the playlist to open.
120 * If name is \p NULL, load the first available playlist. Files which are
121 * listed in the playlist, but not contained in the database are ignored.
122 * This is not considered an error.
124 * \return Positive on success, negative on errors. Possible errors
125 * include: Given playlist not found, -E_NO_PLAYLIST (no playlist defined).
127 int playlist_open(char *name
)
129 struct osl_object obj
;
134 return load_first_available_playlist();
136 obj
.size
= strlen(obj
.data
);
137 ret
= osl_get_row(playlists_table
, BLOBCOL_NAME
, &obj
, &row
);
139 PARA_NOTICE_LOG("failed to load playlist %s\n", name
);
142 return load_playlist(row
);