00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #include "stdinc.h"
00032
00033 #include "vfs.h"
00034 #include "vfs_modules.h"
00035
00040 static void
00041 vfs_playlist_add_tail(struct vfsent *ve, char *fn, char *title, char *dirname)
00042 {
00043 struct vfsref *nvr;
00044
00045 #if G_DIR_SEPARATOR != '\\'
00046
00047 g_strdelimit(fn, "\\", G_DIR_SEPARATOR);
00048 #endif
00049 nvr = vfs_lookup(fn, title, dirname, 0);
00050
00051 if (nvr != NULL)
00052 vfs_list_insert_tail(&ve->population, nvr);
00053 }
00054
00055
00056
00057
00058
00059 int
00060 vfs_pls_match(struct vfsent *ve, int isdir)
00061 {
00062
00063 if (isdir || !g_str_has_suffix(ve->name, ".pls"))
00064 return (-1);
00065
00066 ve->recurse = 0;
00067 return (0);
00068 }
00069
00070 int
00071 vfs_pls_populate(struct vfsent *ve)
00072 {
00073 FILE *fio;
00074 char fbuf[1024];
00075 char *ch, *dn, **out;
00076 int idxoff, nidx;
00077
00078
00079 int idx = -1;
00080 char *fn = NULL;
00081 char *title = NULL;
00082
00083 if ((fio = fopen(ve->filename, "r")) == NULL)
00084 return (-1);
00085 dn = g_path_get_dirname(ve->filename);
00086
00087 while (vfs_fgets(fbuf, sizeof fbuf, fio) == 0) {
00088 if (strncmp(fbuf, "File", 4) == 0) {
00089
00090 out = &fn;
00091 idxoff = 4;
00092 } else if (strncmp(fbuf, "Title", 5) == 0) {
00093
00094 out = &title;
00095 idxoff = 5;
00096 } else {
00097 continue;
00098 }
00099
00100
00101 if ((nidx = atoi(fbuf + idxoff)) == 0)
00102 continue;
00103
00104
00105 ch = strchr(fbuf + idxoff, '=');
00106 if ((ch == NULL) || (ch[1] == '\0'))
00107 continue;
00108
00109 if (nidx != idx) {
00110
00111 if (fn != NULL)
00112 vfs_playlist_add_tail(ve, fn, title, dn);
00113
00114 g_free(fn); fn = NULL;
00115 g_free(title); title = NULL;
00116 idx = nidx;
00117 }
00118
00119
00120 g_free(*out);
00121 *out = g_strdup(ch + 1);
00122 }
00123
00124
00125 if (fn != NULL)
00126 vfs_playlist_add_tail(ve, fn, title, dn);
00127
00128 g_free(fn);
00129 g_free(title);
00130
00131 fclose(fio);
00132 g_free(dn);
00133
00134 return (0);
00135 }
00136
00137 int
00138 vfs_pls_write(const struct vfslist *vl, const char *filename)
00139 {
00140 const char *base = NULL;
00141 size_t cmplen;
00142 FILE *fio;
00143 struct vfsref *vr;
00144 unsigned int idx = 1;
00145
00146 fio = fopen(filename, "w");
00147 if (fio == NULL)
00148 return (-1);
00149
00150
00151 base = strrchr(filename, G_DIR_SEPARATOR);
00152 g_assert(base != NULL);
00153 cmplen = base - filename + 1;
00154
00155 fprintf(fio, "[playlist]\nNumberOfEntries=%u\n",
00156 vfs_list_items(vl));
00157 VFS_LIST_FOREACH(vl, vr) {
00158
00159 base = vfs_filename(vr);
00160 if (strncmp(filename, base, cmplen) == 0)
00161 base += cmplen;
00162
00163 fprintf(fio, "File%u=%s\nTitle%u=%s\n",
00164 idx, base,
00165 idx, vfs_name(vr));
00166 idx++;
00167 }
00168 fclose(fio);
00169
00170 return (0);
00171 }
00172
00173
00174
00175
00176
00177 int
00178 vfs_m3u_match(struct vfsent *ve, int isdir)
00179 {
00180
00181 if (isdir || !g_str_has_suffix(ve->name, ".m3u"))
00182 return (-1);
00183
00184 ve->recurse = 0;
00185 return (0);
00186 }
00187
00188 int
00189 vfs_m3u_populate(struct vfsent *ve)
00190 {
00191 FILE *fio;
00192 char fbuf[1024];
00193 char *ch, *dn;
00194 char *title = NULL;
00195
00196 if ((fio = fopen(ve->filename, "r")) == NULL)
00197 return (-1);
00198 dn = g_path_get_dirname(ve->filename);
00199
00200 while (vfs_fgets(fbuf, sizeof fbuf, fio) == 0) {
00201 if (fbuf[0] == '#') {
00202
00203 if (strncmp(fbuf, "#EXTINF:", 8) == 0) {
00204
00205 g_free(title); title = NULL;
00206
00207
00208 if (((ch = strchr(fbuf + 8, ',')) != NULL)
00209 && (ch[1] != '\0'))
00210 title = g_strdup(ch + 1);
00211 }
00212 } else if (fbuf[0] != '\0') {
00213 vfs_playlist_add_tail(ve, fbuf, title, dn);
00214 g_free(title); title = NULL;
00215 }
00216 }
00217
00218
00219 g_free(title);
00220
00221 fclose(fio);
00222 g_free(dn);
00223
00224 return (0);
00225 }
00226
00227 int
00228 vfs_m3u_write(const struct vfslist *vl, const char *filename)
00229 {
00230 const char *base = NULL;
00231 size_t cmplen;
00232 FILE *fio;
00233 struct vfsref *vr;
00234
00235 fio = fopen(filename, "w");
00236 if (fio == NULL)
00237 return (-1);
00238
00239
00240 base = strrchr(filename, G_DIR_SEPARATOR);
00241 g_assert(base != NULL);
00242 cmplen = base - filename + 1;
00243
00244 fprintf(fio, "#EXTM3U\n");
00245 VFS_LIST_FOREACH(vl, vr) {
00246
00247 base = vfs_filename(vr);
00248 if (strncmp(filename, base, cmplen) == 0)
00249 base += cmplen;
00250
00251 fprintf(fio, "#EXTINF:-1,%s\n%s\n", vfs_name(vr), base);
00252 }
00253 fclose(fio);
00254
00255 return (0);
00256 }