diff options
author | waker <wakeroid@gmail.com> | 2010-12-05 16:07:59 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2010-12-05 16:07:59 +0100 |
commit | 92aa0e95f1d2f006acc8ebaf4c4451a854d2d0ec (patch) | |
tree | 4115b70c71b13a2b7686e64e83e07c6f768512f9 | |
parent | 3629cd4e9959093cd38fc630604d04dce93eda6c (diff) |
added support for filetype prefix-test (for uade2 mod.title files); some code cleanup
-rw-r--r-- | deadbeef.h | 4 | ||||
-rw-r--r-- | playlist.c | 28 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 37 |
3 files changed, 53 insertions, 16 deletions
@@ -714,6 +714,10 @@ typedef struct DB_decoder_s { // NULL terminated array of all supported extensions const char **exts; + // NULL terminated array of all supported prefixes (UADE support needs that) + // e.g. "mod.song_title" + const char **prefixes; + // NULL terminated array of all file type names const char **filetypes; } DB_decoder_t; @@ -1289,12 +1289,20 @@ pl_insert_file (playItem_t *after, const char *fname, int *pabort, int (*cb)(pla } // detect decoder - const char *eol = fname + strlen (fname) - 1; - while (eol > fname && *eol != '.') { - eol--; + const char *eol = strrchr (fname, '.'); + if (!eol) { + return NULL; } eol++; + const char *fn = strrchr (fname, '/'); + if (!fn) { + fn = fname; + } + else { + fn++; + } + // detect pls/m3u files // they must be handled before checking for http://, // so that remote playlist files referenced from other playlist files could @@ -1370,6 +1378,20 @@ pl_insert_file (playItem_t *after, const char *fname, int *pabort, int (*cb)(pla } } } + if (decoders[i]->prefixes && decoders[i]->insert) { + const char **prefixes = decoders[i]->prefixes; + for (int e = 0; prefixes[e]; e++) { + if (!strncasecmp (prefixes[e], fn, strlen(prefixes[e])) && *(fn + strlen (prefixes[e])) == '.') { + playItem_t *inserted = (playItem_t *)decoders[i]->insert (DB_PLAYITEM (after), fname); + if (inserted != NULL) { + if (cb && cb (inserted, user_data) < 0) { + *pabort = 1; + } + return inserted; + } + } + } + } } trace ("no decoder found for %s\n", fname); return NULL; diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index 8cd520bc..e7f6f77c 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -58,26 +58,37 @@ extern DB_functions_t *deadbeef; // defined in gtkui.c static gboolean file_filter_func (const GtkFileFilterInfo *filter_info, gpointer data) { // get ext - const char *p = filter_info->filename + strlen (filter_info->filename)-1; - while (p >= filter_info->filename) { - if (*p == '.') { - break; - } - p--; - } - if (*p != '.') { + const char *p = strrchr (filter_info->filename, '.'); + if (!p) { return FALSE; } p++; + + // get beginning of fname + const char *fn = strrchr (filter_info->filename, '/'); + if (!fn) { + fn = filter_info->filename; + } + else { + fn++; + } + + DB_decoder_t **codecs = deadbeef->plug_get_decoder_list (); for (int i = 0; codecs[i]; i++) { if (codecs[i]->exts && codecs[i]->insert) { const char **exts = codecs[i]->exts; - if (exts) { - for (int e = 0; exts[e]; e++) { - if (!strcasecmp (exts[e], p)) { - return TRUE; - } + for (int e = 0; exts[e]; e++) { + if (!strcasecmp (exts[e], p)) { + return TRUE; + } + } + } + if (codecs[i]->prefixes && codecs[i]->insert) { + const char **prefixes = codecs[i]->prefixes; + for (int e = 0; prefixes[e]; e++) { + if (!strncasecmp (prefixes[e], fn, strlen(prefixes[e])) && *(fn + strlen (prefixes[e])) == '.') { + return TRUE; } } } |