mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-10 13:18:14 -05:00
Read EXTINF metadata (without regex)
This commit is contained in:
parent
3e484f1cae
commit
d891c6a7a4
@ -34,81 +34,44 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <regex.h>
|
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "filescanner.h"
|
#include "filescanner.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Get metadata from the EXTINF tag */
|
||||||
static int
|
static int
|
||||||
extinf_get(char *string, struct extinf_ctx *extinf)
|
extinf_get(char *string, struct extinf_ctx *extinf)
|
||||||
{
|
{
|
||||||
regex_t *regex;
|
char *ptr;
|
||||||
regmatch_t *regmatch;
|
|
||||||
size_t matchlen;
|
|
||||||
|
|
||||||
if (strcmp(string, "#EXTINF:") <= 0)
|
if (strcmp(string, "#EXTINF:") <= 0)
|
||||||
{
|
return 0;
|
||||||
DPRINTF(E_DBG, L_SCAN, "Playlist line has no EXTINF data\n");
|
|
||||||
|
|
||||||
return 0;
|
ptr = strchr(string, ',');
|
||||||
|
if (!ptr || strlen(ptr) < 2)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* New extinf found, so clear old data */
|
||||||
|
if (extinf->found)
|
||||||
|
{
|
||||||
|
free(extinf->artist);
|
||||||
|
free(extinf->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
regex = (regex_t*)malloc(sizeof(regex_t));
|
extinf->found = 1;
|
||||||
if (!regex)
|
extinf->artist = strdup(ptr + 1);
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Out of memory for playlist regex.\n");
|
|
||||||
|
|
||||||
return 0;
|
ptr = strstr(extinf->artist, " -");
|
||||||
}
|
if (ptr && strlen(ptr) > 3)
|
||||||
|
extinf->title = strdup(ptr + 3);
|
||||||
|
else
|
||||||
|
extinf->title = strdup("");
|
||||||
|
if (ptr)
|
||||||
|
*ptr = '\0';
|
||||||
|
|
||||||
regcomp(regex, "^#EXTINF:.*,(.*?)-(.*)",REG_EXTENDED|REG_NEWLINE);
|
return 1;
|
||||||
regmatch = (regmatch_t*)malloc(sizeof(regmatch_t) * (1 + regex->re_nsub));
|
|
||||||
if (!regmatch)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_SCAN, "Out of memory for playlist regmatch.\n");
|
|
||||||
|
|
||||||
goto regexfail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regexec(regex, string, 1 + regex->re_nsub, regmatch, 0))
|
|
||||||
goto regmatchfail;
|
|
||||||
|
|
||||||
/* Found extinf */
|
|
||||||
if (regmatch[0].rm_so != -1)
|
|
||||||
{
|
|
||||||
if (extinf->found)
|
|
||||||
{
|
|
||||||
free(extinf->artist);
|
|
||||||
free(extinf->title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Artist */
|
|
||||||
matchlen = regmatch[1].rm_eo - regmatch[1].rm_so;
|
|
||||||
extinf->artist = (char*)malloc(matchlen + 1);
|
|
||||||
strncpy(extinf->artist, string + regmatch[1].rm_so, matchlen + 1);
|
|
||||||
extinf->artist[matchlen]='\0';
|
|
||||||
|
|
||||||
/* Title */
|
|
||||||
matchlen = regmatch[2].rm_eo - regmatch[2].rm_so;
|
|
||||||
extinf->title = (char*)malloc(matchlen + 1);
|
|
||||||
strncpy(extinf->title, string + regmatch[2].rm_so, matchlen + 1);
|
|
||||||
extinf->title[matchlen]='\0';
|
|
||||||
|
|
||||||
free(regmatch);
|
|
||||||
regfree(regex);
|
|
||||||
|
|
||||||
extinf->found = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
regmatchfail:
|
|
||||||
free(regmatch);
|
|
||||||
regexfail:
|
|
||||||
regfree(regex);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user