diff options
author | waker <wakeroid@gmail.com> | 2011-09-29 21:47:15 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-09-29 21:47:15 +0200 |
commit | c9ff1f744284c4164d39ab6fcc8e1d816253c5d3 (patch) | |
tree | 7111b7f82127a78797f0e5e230dc634a7496e681 /plugins/m3u | |
parent | 874036e8f0ef089ec06ad83758afb04c83edad25 (diff) |
added experimental EXTM3U support
Diffstat (limited to 'plugins/m3u')
-rw-r--r-- | plugins/m3u/m3u.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c index bcf6a13c..045e88f9 100644 --- a/plugins/m3u/m3u.c +++ b/plugins/m3u/m3u.c @@ -58,14 +58,45 @@ load_m3u (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pab } deadbeef->fread (buffer, 1, sz, fp); deadbeef->fclose (fp); + + int line = 0; + int read_extm3u = 0; + const uint8_t *p = buffer; const uint8_t *end = buffer+sz; + const uint8_t *e; + int length = -1; + char title[1000] = ""; + char artist[1000] = ""; while (p < end) { + line++; p = skipspaces (p, end); if (p >= end) { break; } if (*p == '#') { + if (line == 1) { + if (end - p >= 7 && !strncmp (p, "#EXTM3U", 7)) { + read_extm3u = 1; + } + } + else if (read_extm3u) { + if (end - p >= 8 && !strncmp (p, "#EXTINF:", 8)) { + length = -1; + title[0] = 0; + artist[0] = 0; + p += 8; + e = p; + while (e < end && *e >= 0x20) { + e++; + } + int n = e-p; + uint8_t nm[n+1]; + memcpy (nm, p, n); + nm[n] = 0; + sscanf (nm, "%d,%s - %s", &length, artist, title); + } + } while (p < end && *p >= 0x20) { p++; } @@ -74,7 +105,7 @@ load_m3u (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pab } continue; } - const uint8_t *e = p; + e = p; while (e < end && *e >= 0x20) { e++; } @@ -87,6 +118,18 @@ load_m3u (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname, int *pab if (strrchr (nm, '/')) { trace ("pl_insert_m3u: adding file %s\n", nm); it = deadbeef->plt_insert_file (plt, after, nm, pabort, cb, user_data); + if (length >= 0) { + deadbeef->plt_set_item_duration (plt, it, length); + } + if (title[0]) { + deadbeef->pl_replace_meta (it, "title", title); + } + else if (artist[0]) { + deadbeef->pl_replace_meta (it, "title", " "); + } + if (artist[0]) { + deadbeef->pl_replace_meta (it, "artist", artist); + } } else { int l = strlen (nm); |