summaryrefslogtreecommitdiff
path: root/nncmpp.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-06-22 21:25:52 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2017-06-22 21:25:52 +0200
commit99f35a509c7c8a96078fc03e7646a1c4a5b72e68 (patch)
tree649a509369dc674ee7a0678356462a61558f5ef7 /nncmpp.c
parentf875109201477d262c489dc9e588659be6d842a7 (diff)
downloadnncmpp-99f35a509c7c8a96078fc03e7646a1c4a5b72e68.tar.gz
nncmpp-99f35a509c7c8a96078fc03e7646a1c4a5b72e68.tar.xz
nncmpp-99f35a509c7c8a96078fc03e7646a1c4a5b72e68.zip
Handle weird playlists better
Diffstat (limited to 'nncmpp.c')
-rw-r--r--nncmpp.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/nncmpp.c b/nncmpp.c
index 876458b..3a4b1e2 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -2325,6 +2325,32 @@ is_content_type (const char *content_type,
}
static void
+streams_tab_filter (char *line, regex_t *re, struct strv *out)
+{
+ regmatch_t groups[2];
+ if (regexec (re, line, 2, groups, 0) == REG_NOMATCH)
+ return;
+
+ // It may happen that playlist files contain useless, invalid quotes,
+ // let's be liberal in what we accept
+ regoff_t start = groups[1].rm_so, end = groups[1].rm_eo;
+ while (end > start + 1 && line[start] == '"' && line[end - 1] == '"')
+ {
+ start++;
+ end--;
+ }
+
+ char *target = xstrndup (line + start, end - start);
+ if (utf8_validate (target, end - start))
+ strv_append_owned (out, target);
+ else
+ {
+ strv_append_owned (out, latin1_to_utf8 (target));
+ free (target);
+ }
+}
+
+static void
streams_tab_parse_playlist (const char *playlist, const char *content_type,
struct strv *out)
{
@@ -2338,28 +2364,15 @@ streams_tab_parse_playlist (const char *playlist, const char *content_type,
"(https?://([][a-z0-9._~:/?#@!$&'()*+,;=-]|%[a-f0-9]{2})+)";
if ((lines.len && !strcasecmp_ascii (lines.vector[0], "[playlist]"))
|| (content_type && is_content_type (content_type, "audio", "x-scpls")))
- extract_re = "^File[^=]*=(.*)";
+ extract_re = "^File[^=]*=(.+)";
else if ((lines.len && !strcasecmp_ascii (lines.vector[0], "#EXTM3U"))
|| (content_type && is_content_type (content_type, "audio", "x-mpegurl")))
extract_re = "^([^#].*)";
regex_t *re = regex_compile (extract_re, REG_EXTENDED, NULL);
hard_assert (re != NULL);
-
- regmatch_t groups[2];
for (size_t i = 0; i < lines.len; i++)
- if (regexec (re, lines.vector[i], 2, groups, 0) != REG_NOMATCH)
- {
- char *target = xstrndup (lines.vector[i] + groups[1].rm_so,
- groups[1].rm_eo - groups[1].rm_so);
- if (utf8_validate (target, strlen (target)))
- strv_append_owned (out, target);
- else
- {
- strv_append_owned (out, latin1_to_utf8 (target));
- free (target);
- }
- }
+ streams_tab_filter (lines.vector[i], re, out);
regex_free (re);
strv_free (&lines);
}