diff options
-rw-r--r-- | playlist.c | 77 | ||||
-rw-r--r-- | plugins/m3u/m3u.c | 84 |
2 files changed, 116 insertions, 45 deletions
@@ -60,8 +60,8 @@ #define PLAYLIST_MAJOR_VER 1 #define PLAYLIST_MINOR_VER 2 -//#define trace(...) { fprintf(stderr, __VA_ARGS__); } -#define trace(fmt,...) +#define trace(...) { fprintf(stderr, __VA_ARGS__); } +//#define trace(fmt,...) #define SKIP_BLANK_CUE_TRACKS 0 @@ -1199,20 +1199,11 @@ pl_insert_pls (playItem_t *after, const char *fname, int *pabort, int (*cb)(play trace ("file %s finished before numberofentries had been read\n", fname); return NULL; } - if (strncasecmp (p, "numberofentries=", 16)) { - trace ("can't get number of entries from %s\n", fname); - return NULL; - } - p += 15; - // ignore numentries - no real need for it here - while (p < end && *p > 0x20) { - p++; - } - p = pl_str_skipspaces (p, end); // fetch all tracks char url[1024] = ""; char title[1024] = ""; char length[20] = ""; + int lastidx = -1; LOCK; while (p < end) { p = pl_str_skipspaces (p, end); @@ -1224,8 +1215,15 @@ pl_insert_pls (playItem_t *after, const char *fname, int *pabort, int (*cb)(play } const uint8_t *e; int n; - if (!strncasecmp (p, "file", 4)) { - if (url[0]) { + if (!strncasecmp (p, "numberofentries=", 16) || !strncasecmp (p, "version=", 8)) { + while (p < end && *p >= 0x20) { + p++; + } + continue; + } + else if (!strncasecmp (p, "file", 4)) { + int idx = atoi (p + 4); + if (url[0] && idx != lastidx && lastidx != -1) { // add track playItem_t *it = pl_insert_file (after, url, pabort, cb, user_data); if (it) { @@ -1244,6 +1242,7 @@ pl_insert_pls (playItem_t *after, const char *fname, int *pabort, int (*cb)(play title[0] = 0; length[0] = 0; } + lastidx = idx; p += 4; while (p < end && *p != '=') { p++; @@ -1264,6 +1263,27 @@ pl_insert_pls (playItem_t *after, const char *fname, int *pabort, int (*cb)(play p = ++e; } else if (!strncasecmp (p, "title", 5)) { + int idx = atoi (p + 5); + if (url[0] && idx != lastidx && lastidx != -1) { + // add track + playItem_t *it = pl_insert_file (after, url, pabort, cb, user_data); + if (it) { + after = it; + pl_set_item_duration (it, atoi (length)); + if (title[0]) { + pl_delete_all_meta (it); + pl_add_meta (it, "title", title); + } + } + if (pabort && *pabort) { + UNLOCK; + return after; + } + url[0] = 0; + title[0] = 0; + length[0] = 0; + } + lastidx = idx; p += 5; while (p < end && *p != '=') { p++; @@ -1284,6 +1304,27 @@ pl_insert_pls (playItem_t *after, const char *fname, int *pabort, int (*cb)(play p = ++e; } else if (!strncasecmp (p, "length", 6)) { + int idx = atoi (p + 6); + if (url[0] && idx != lastidx && lastidx != -1) { + // add track + playItem_t *it = pl_insert_file (after, url, pabort, cb, user_data); + if (it) { + after = it; + pl_set_item_duration (it, atoi (length)); + if (title[0]) { + pl_delete_all_meta (it); + pl_add_meta (it, "title", title); + } + } + if (pabort && *pabort) { + UNLOCK; + return after; + } + url[0] = 0; + title[0] = 0; + length[0] = 0; + } + lastidx = idx; p += 6; // skip = while (p < end && *p != '=') { @@ -1436,7 +1477,7 @@ pl_insert_file (playItem_t *after, const char *fname, int *pabort, int (*cb)(pla it->filetype = "content"; it->_duration = -1; pl_add_meta (it, "title", NULL); - after = plt_insert_item (addfiles_playlist, after, it); + after = plt_insert_item (addfiles_playlist ? addfiles_playlist : playlist, after, it); pl_item_unref (it); return after; } @@ -2243,10 +2284,8 @@ pl_load (const char *fname) { for (e = 0; plug[p]->extensions[e]; e++) { if (plug[p]->load && !strcasecmp (ext, plug[p]->extensions[e])) { DB_playItem_t *it = plug[p]->load (it, fname, NULL, NULL, NULL); - if (it) { - GLOBAL_UNLOCK; - return 0; - } + GLOBAL_UNLOCK; + return 0; } } } diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c index 2f78bdd5..6421ff8b 100644 --- a/plugins/m3u/m3u.c +++ b/plugins/m3u/m3u.c @@ -119,12 +119,12 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } static DB_playItem_t * -pls_insert_file (DB_playItem_t *after, const char *fname, const char *uri, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data) { +pls_insert_file (DB_playItem_t *after, const char *fname, const char *uri, int *pabort, int (*cb)(DB_playItem_t *it, void *data), void *user_data, const char *title, const char *length) { + trace ("pls_insert_file uri: %s\n", uri); DB_playItem_t *it = NULL; const char *slash = NULL; if (strrchr (uri, '/')) { - trace ("pls: adding file %s\n", uri); it = deadbeef->pl_insert_file (after, uri, pabort, cb, user_data); } else if (slash = strrchr (fname, '/')) { @@ -132,9 +132,15 @@ pls_insert_file (DB_playItem_t *after, const char *fname, const char *uri, int * char fullpath[slash - fname + l + 2]; memcpy (fullpath, fname, slash - fname + 1); strcpy (fullpath + (slash - fname + 1), uri); - trace ("pl_insert_m3u: adding file %s\n", fullpath); + trace ("pls_insert_file: adding file %s\n", fullpath); it = deadbeef->pl_insert_file (after, fullpath, pabort, cb, user_data); } + if (length[0]) { + deadbeef->pl_set_item_duration (it, atoi (length)); + } + if (title[0]) { + deadbeef->pl_replace_meta (it, "title", title); + } return it; } @@ -174,20 +180,11 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla trace ("file %s finished before numberofentries had been read\n", fname); return NULL; } - if (strncasecmp (p, "numberofentries=", 16)) { - trace ("can't get number of entries from %s\n", fname); - return NULL; - } - p += 15; - // ignore numentries - no real need for it here - while (p < end && *p > 0x20) { - p++; - } - p = skipspaces (p, end); // fetch all tracks char uri[1024] = ""; char title[1024] = ""; char length[20] = ""; + int lastidx = -1; deadbeef->pl_lock (); while (p < end) { p = skipspaces (p, end); @@ -199,15 +196,19 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } const uint8_t *e; int n; - if (!strncasecmp (p, "file", 4)) { - if (uri[0]) { - DB_playItem_t *it = pls_insert_file (after, fname, uri, pabort, cb, user_data); + if (!strncasecmp (p, "numberofentries=", 16) || !strncasecmp (p, "version=", 8)) { + while (p < end && *p >= 0x20) { + p++; + } + continue; + } + else if (!strncasecmp (p, "file", 4)) { + int idx = atoi (p + 4); + if (uri[0] && idx != lastidx && lastidx != -1) { + trace ("uri%d\n", idx); + DB_playItem_t *it = pls_insert_file (after, fname, uri, pabort, cb, user_data, title, length); if (it) { after = it; - deadbeef->pl_set_item_duration (it, atoi (length)); - if (title[0]) { - deadbeef->pl_add_meta (it, "title", title); - } } if (pabort && *pabort) { deadbeef->pl_unlock (); @@ -217,6 +218,7 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla title[0] = 0; length[0] = 0; } + lastidx = idx; p += 4; while (p < end && *p != '=') { p++; @@ -234,9 +236,26 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla memcpy (uri, p, n); uri[n] = 0; trace ("uri: %s\n", uri); + trace ("uri%d=%s\n", idx, uri); p = ++e; } else if (!strncasecmp (p, "title", 5)) { + int idx = atoi (p + 5); + if (uri[0] && idx != lastidx && lastidx != -1) { + trace ("title%d\n", idx); + DB_playItem_t *it = pls_insert_file (after, fname, uri, pabort, cb, user_data, title, length); + if (it) { + after = it; + } + if (pabort && *pabort) { + deadbeef->pl_unlock (); + return after; + } + uri[0] = 0; + title[0] = 0; + length[0] = 0; + } + lastidx = idx; p += 5; while (p < end && *p != '=') { p++; @@ -253,10 +272,26 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla n = min (n, sizeof (title)-1); memcpy (title, p, n); title[n] = 0; - trace ("title: %s\n", title); + trace ("title%d=%s\n", idx, title); p = ++e; } else if (!strncasecmp (p, "length", 6)) { + int idx = atoi (p + 6); + if (uri[0] && idx != lastidx && lastidx != -1) { + trace ("length%d\n", idx); + DB_playItem_t *it = pls_insert_file (after, fname, uri, pabort, cb, user_data, title, length); + if (it) { + after = it; + } + if (pabort && *pabort) { + deadbeef->pl_unlock (); + return after; + } + uri[0] = 0; + title[0] = 0; + length[0] = 0; + } + lastidx = idx; p += 6; // skip = while (p < end && *p != '=') { @@ -273,6 +308,7 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla n = e-p; n = min (n, sizeof (length)-1); memcpy (length, p, n); + trace ("length%d=%s\n", idx, length); } else { trace ("invalid entry in pls file: %s\n", p); @@ -284,13 +320,9 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla p = e; } if (uri[0]) { - DB_playItem_t *it = pls_insert_file (after, fname, uri, pabort, cb, user_data); + DB_playItem_t *it = pls_insert_file (after, fname, uri, pabort, cb, user_data, title, length); if (it) { after = it; - deadbeef->pl_set_item_duration (it, atoi (length)); - if (title[0]) { - deadbeef->pl_add_meta (it, "title", title); - } } } deadbeef->pl_unlock (); |