mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
playlist_parser: mp_msg conversion
This commit is contained in:
parent
8cd1b33a22
commit
9149e2af56
@ -45,6 +45,7 @@ struct ASX_Parser_t {
|
||||
char* last_body;
|
||||
int deep;
|
||||
struct playlist *pl;
|
||||
struct mp_log *log;
|
||||
};
|
||||
|
||||
ASX_Parser_t *asx_parser_new(struct playlist *pl);
|
||||
@ -105,8 +106,8 @@ asx_get_attrib(const char* attrib,char** attribs) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define asx_warning_attrib_required(p,e,a) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : element %s don't have the required attribute %s",p->line,e,a)
|
||||
#define asx_warning_body_parse_error(p,e) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing %s body",p->line,e)
|
||||
#define asx_warning_attrib_required(p,e,a) MP_WARN(parser, "At line %d : element %s don't have the required attribute %s",p->line,e,a)
|
||||
#define asx_warning_body_parse_error(p,e) MP_WARN(parser, "At line %d : error while parsing %s body",p->line,e)
|
||||
|
||||
ASX_Parser_t *asx_parser_new(struct playlist *pl)
|
||||
{
|
||||
@ -142,7 +143,7 @@ asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs) {
|
||||
if(ptr3 == NULL) break;
|
||||
for(ptr2 = ptr3-1; strchr(SPACE,*ptr2) != NULL; ptr2--) {
|
||||
if (ptr2 == ptr1) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : this should never append, back to attribute begin while skipping end space",parser->line);
|
||||
MP_ERR(parser, "At line %d : this should never append, back to attribute begin while skipping end space",parser->line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -153,13 +154,13 @@ asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs) {
|
||||
ptr1 = strchr(ptr3,'"');
|
||||
if(ptr1 == NULL || ptr1[1] == '\0') ptr1 = strchr(ptr3,'\'');
|
||||
if(ptr1 == NULL || ptr1[1] == '\0') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : can't find attribute %s value",parser->line,attrib);
|
||||
MP_WARN(parser, "At line %d : can't find attribute %s value",parser->line,attrib);
|
||||
free(attrib);
|
||||
break;
|
||||
}
|
||||
ptr2 = strchr(ptr1+1,ptr1[0]);
|
||||
if (ptr2 == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : value of attribute %s isn't finished",parser->line,attrib);
|
||||
MP_WARN(parser, "At line %d : value of attribute %s isn't finished",parser->line,attrib);
|
||||
free(attrib);
|
||||
break;
|
||||
}
|
||||
@ -198,7 +199,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
int quotes = 0;
|
||||
|
||||
if(_buffer == NULL || _element == NULL || _body == NULL || _attribs == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : asx_get_element called with invalid value",parser->line);
|
||||
MP_ERR(parser, "At line %d : asx_get_element called with invalid value",parser->line);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -254,7 +255,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
}
|
||||
//ptr1 = strstr(ptr1,"-->");
|
||||
if(!ptr1) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : unfinished comment",parser->line);
|
||||
MP_ERR(parser, "At line %d : unfinished comment",parser->line);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
@ -265,7 +266,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
// Is this space skip very useful ??
|
||||
for(ptr1++; strchr(SPACE,ptr1[0]) != NULL; ptr1++) { // Skip space
|
||||
if(ptr1[0] == '\0') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
|
||||
MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
|
||||
return -1;
|
||||
}
|
||||
if(ptr1[0] == '\n') parser->line++;
|
||||
@ -273,7 +274,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
|
||||
for(ptr2 = ptr1; strchr(LETTER,*ptr2) != NULL;ptr2++) { // Go to end of name
|
||||
if(*ptr2 == '\0'){
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
|
||||
MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
|
||||
return -1;
|
||||
}
|
||||
if(ptr2[0] == '\n') parser->line++;
|
||||
@ -285,7 +286,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
|
||||
for( ; strchr(SPACE,*ptr2) != NULL; ptr2++) { // Skip space
|
||||
if(ptr2[0] == '\0') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
|
||||
MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
|
||||
free(element);
|
||||
return -1;
|
||||
}
|
||||
@ -302,7 +303,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
if(ptr3[0] == '\n') parser->line++;
|
||||
}
|
||||
if(ptr3[0] == '\0' || ptr3[1] == '\0') { // End of file
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
|
||||
MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
|
||||
free(element);
|
||||
return -1;
|
||||
}
|
||||
@ -318,7 +319,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
ptr3++;
|
||||
for( ; strchr(SPACE,*ptr3) != NULL; ptr3++) { // Skip space on body begin
|
||||
if(*ptr3 == '\0') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element);
|
||||
MP_ERR(parser, "At line %d : EOB reached while parsing %s element body",parser->line,element);
|
||||
free(element);
|
||||
free(attribs);
|
||||
return -1;
|
||||
@ -346,7 +347,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
continue;
|
||||
}
|
||||
if(ptr4 == NULL || ptr4[1] == '\0') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element);
|
||||
MP_ERR(parser, "At line %d : EOB reached while parsing %s element body",parser->line,element);
|
||||
free(element);
|
||||
free(attribs);
|
||||
return -1;
|
||||
@ -392,7 +393,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
|
||||
n_attrib = asx_parse_attribs(parser,attribs,_attribs);
|
||||
free(attribs);
|
||||
if(n_attrib < 0) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing element %s attributes",parser->line,element);
|
||||
MP_WARN(parser, "At line %d : error while parsing element %s attributes",parser->line,element);
|
||||
free(element);
|
||||
free(body);
|
||||
return -1;
|
||||
@ -441,7 +442,7 @@ asx_parse_ref(ASX_Parser_t* parser, char** attribs) {
|
||||
|
||||
playlist_add_file(parser->pl, href);
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding file %s to element entry\n",href);
|
||||
MP_VERBOSE(parser, "Adding file %s to element entry\n",href);
|
||||
|
||||
free(href);
|
||||
|
||||
@ -458,10 +459,10 @@ static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs
|
||||
asx_warning_attrib_required(parser,"ENTRYREF" ,"HREF" );
|
||||
return;
|
||||
}
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Recursive playlist %s\n", href);
|
||||
MP_ERR(parser, "Recursive playlist %s\n", href);
|
||||
playlist_add_file(parser->pl, href);
|
||||
free(href);
|
||||
//mp_msg(MSGT_PLAYTREE,MSGL_INFO,"Need to implement entryref\n");
|
||||
//MP_INFO(parser, "Need to implement entryref\n");
|
||||
}
|
||||
|
||||
static void asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) {
|
||||
@ -478,9 +479,9 @@ static void asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) {
|
||||
}
|
||||
if(strcasecmp(element,"REF") == 0) {
|
||||
asx_parse_ref(parser,attribs);
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to entry\n",element);
|
||||
MP_DBG(parser, "Adding element %s to entry\n",element);
|
||||
} else
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
|
||||
MP_DBG(parser, "Ignoring element %s\n",element);
|
||||
free(body);
|
||||
asx_free_attribs(attribs);
|
||||
}
|
||||
@ -493,7 +494,7 @@ static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs)
|
||||
int r;
|
||||
|
||||
asx_get_attrib("COUNT",_attribs);
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Ignoring repeated playlist entries\n");
|
||||
MP_ERR(parser, "Ignoring repeated playlist entries\n");
|
||||
|
||||
while(buffer && buffer[0] != '\0') {
|
||||
r = asx_get_element(parser,&buffer,&element,&body,&attribs);
|
||||
@ -510,7 +511,7 @@ static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs)
|
||||
} else if(strcasecmp(element,"REPEAT") == 0) {
|
||||
asx_parse_repeat(parser,body,attribs);
|
||||
} else
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
|
||||
MP_DBG(parser, "Ignoring element %s\n",element);
|
||||
free(body);
|
||||
asx_free_attribs(attribs);
|
||||
}
|
||||
@ -518,35 +519,36 @@ static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs)
|
||||
}
|
||||
|
||||
|
||||
bool asx_parse(char* buffer, struct playlist *pl)
|
||||
bool asx_parse(char* buffer, struct playlist *pl, struct mp_log *log)
|
||||
{
|
||||
char *element,*asx_body,**asx_attribs,*body = NULL, **attribs;
|
||||
int r;
|
||||
ASX_Parser_t* parser = asx_parser_new(pl);
|
||||
parser->log = log;
|
||||
|
||||
parser->line = 1;
|
||||
parser->deep = 0;
|
||||
|
||||
r = asx_get_element(parser,&buffer,&element,&asx_body,&asx_attribs);
|
||||
if(r < 0) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : Syntax error ???",parser->line);
|
||||
MP_ERR(parser, "At line %d : Syntax error ???",parser->line);
|
||||
asx_parser_free(parser);
|
||||
return false;
|
||||
} else if(r == 0) { // No contents
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"empty asx element");
|
||||
MP_ERR(parser, "empty asx element");
|
||||
asx_parser_free(parser);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strcasecmp(element,"ASX") != 0) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"first element isn't ASX, it's %s\n",element);
|
||||
MP_ERR(parser, "first element isn't ASX, it's %s\n",element);
|
||||
asx_free_attribs(asx_attribs);
|
||||
asx_parser_free(parser);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!asx_body) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"ASX element is empty");
|
||||
MP_ERR(parser, "ASX element is empty");
|
||||
asx_free_attribs(asx_attribs);
|
||||
asx_parser_free(parser);
|
||||
return false;
|
||||
@ -569,7 +571,7 @@ bool asx_parse(char* buffer, struct playlist *pl)
|
||||
} else if(strcasecmp(element,"REPEAT") == 0) {
|
||||
asx_parse_repeat(parser,body,attribs);
|
||||
} else
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
|
||||
MP_DBG(parser, "Ignoring element %s\n",element);
|
||||
free(body);
|
||||
asx_free_attribs(attribs);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
struct playlist;
|
||||
bool asx_parse(char* buffer, struct playlist *pl);
|
||||
struct mp_log;
|
||||
bool asx_parse(char* buffer, struct playlist *pl, struct mp_log *log);
|
||||
|
||||
#endif /* MPLAYER_ASXPARSER_H */
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "playlist_parser.h"
|
||||
#include "stream/stream.h"
|
||||
#include "demux/demux.h"
|
||||
#include "common/global.h"
|
||||
#include "common/msg.h"
|
||||
#include "options/path.h"
|
||||
|
||||
@ -54,6 +55,7 @@ typedef struct play_tree_parser {
|
||||
int buffer_size , buffer_end;
|
||||
int keep;
|
||||
struct playlist *pl;
|
||||
struct mp_log *log;
|
||||
} play_tree_parser_t;
|
||||
|
||||
static void
|
||||
@ -178,7 +180,7 @@ static bool parse_asx(play_tree_parser_t* p) {
|
||||
int comments = 0,get_line = 1;
|
||||
char* line = NULL;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying asx...\n");
|
||||
MP_VERBOSE(p, "Trying asx...\n");
|
||||
|
||||
while(1) {
|
||||
if(get_line) {
|
||||
@ -191,8 +193,8 @@ static bool parse_asx(play_tree_parser_t* p) {
|
||||
}
|
||||
if(!comments) {
|
||||
if(line[0] != '<') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",line[0]);
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",p->buffer);
|
||||
MP_DBG(p, "First char isn't '<' but '%c'\n",line[0]);
|
||||
MP_TRACE(p, "Buffer = [%s]\n",p->buffer);
|
||||
return false;
|
||||
} else if(strncmp(line,"<!--",4) == 0) { // Comments
|
||||
comments = 1;
|
||||
@ -225,15 +227,15 @@ static bool parse_asx(play_tree_parser_t* p) {
|
||||
}
|
||||
}
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected asx format\n");
|
||||
MP_VERBOSE(p, "Detected asx format\n");
|
||||
|
||||
// We have an asx : load it in memory and parse
|
||||
|
||||
while((line = play_tree_parser_get_line(p)) != NULL)
|
||||
/* NOTHING */;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Parsing asx file: [%s]\n",p->buffer);
|
||||
return asx_parse(p->buffer,p->pl);
|
||||
MP_TRACE(p, "Parsing asx file: [%s]\n",p->buffer);
|
||||
return asx_parse(p->buffer,p->pl,p->log);
|
||||
}
|
||||
|
||||
static bool parse_smil(play_tree_parser_t* p) {
|
||||
@ -242,7 +244,7 @@ static bool parse_smil(play_tree_parser_t* p) {
|
||||
int is_rmsmil = 0;
|
||||
unsigned int npkt, ttlpkt;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying smil playlist...\n");
|
||||
MP_VERBOSE(p, "Trying smil playlist...\n");
|
||||
|
||||
// Check if smil
|
||||
while((line = play_tree_parser_get_line(p)) != NULL) {
|
||||
@ -261,18 +263,18 @@ static bool parse_smil(play_tree_parser_t* p) {
|
||||
}
|
||||
|
||||
if (!line) return NULL;
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected smil playlist format\n");
|
||||
MP_VERBOSE(p, "Detected smil playlist format\n");
|
||||
play_tree_parser_stop_keeping(p);
|
||||
|
||||
if (strncasecmp(line,"(smil-document",14)==0) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Special smil-over-realrtsp playlist header\n");
|
||||
MP_VERBOSE(p, "Special smil-over-realrtsp playlist header\n");
|
||||
is_rmsmil = 1;
|
||||
if (sscanf(line, "(smil-document (ver 1.0)(npkt %u)(ttlpkt %u", &npkt, &ttlpkt) != 2) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: header parsing failure, assuming single packet.\n");
|
||||
MP_WARN(p, "smil-over-realrtsp: header parsing failure, assuming single packet.\n");
|
||||
npkt = ttlpkt = 1;
|
||||
}
|
||||
if (ttlpkt == 0 || npkt > ttlpkt) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: bad packet counters (npkk = %u, ttlpkt = %u), assuming single packet.\n",
|
||||
MP_WARN(p, "smil-over-realrtsp: bad packet counters (npkk = %u, ttlpkt = %u), assuming single packet.\n",
|
||||
npkt, ttlpkt);
|
||||
npkt = ttlpkt = 1;
|
||||
}
|
||||
@ -294,13 +296,13 @@ static bool parse_smil(play_tree_parser_t* p) {
|
||||
|
||||
line = strdup(src_line);
|
||||
if(!(src_line = play_tree_parser_get_line(p))) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: can't get line from packet %u/%u.\n", npkt, ttlpkt);
|
||||
MP_WARN(p, "smil-over-realrtsp: can't get line from packet %u/%u.\n", npkt, ttlpkt);
|
||||
break;
|
||||
}
|
||||
strstrip(src_line);
|
||||
// Skip header, packet starts after "
|
||||
if(!(payload = strchr(src_line,'\"'))) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: can't find start of packet, using complete line.\n");
|
||||
MP_WARN(p, "smil-over-realrtsp: can't find start of packet, using complete line.\n");
|
||||
payload = src_line;
|
||||
} else
|
||||
payload++;
|
||||
@ -336,17 +338,17 @@ static bool parse_smil(play_tree_parser_t* p) {
|
||||
if (pos != NULL) {
|
||||
entrymode=0;
|
||||
if (pos[4] != '"' && pos[4] != '\'') {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Unknown delimiter %c in source line %s\n", pos[4], line);
|
||||
MP_VERBOSE(p, "Unknown delimiter %c in source line %s\n", pos[4], line);
|
||||
break;
|
||||
}
|
||||
s_start=pos+5;
|
||||
s_end=strchr(s_start,pos[4]);
|
||||
if (s_end == NULL) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line);
|
||||
MP_VERBOSE(p, "Error parsing this source line %s\n",line);
|
||||
break;
|
||||
}
|
||||
if (s_end-s_start> 511) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line);
|
||||
MP_VERBOSE(p, "Cannot store such a large source %s\n",line);
|
||||
break;
|
||||
}
|
||||
strncpy(source,s_start,s_end-s_start);
|
||||
@ -365,7 +367,7 @@ static bool parse_smil(play_tree_parser_t* p) {
|
||||
static bool parse_textplain(play_tree_parser_t* p) {
|
||||
char* line;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext playlist...\n");
|
||||
MP_VERBOSE(p, "Trying plaintext playlist...\n");
|
||||
play_tree_parser_stop_keeping(p);
|
||||
|
||||
while((line = play_tree_parser_get_line(p)) != NULL) {
|
||||
@ -386,7 +388,7 @@ static bool parse_textplain(play_tree_parser_t* p) {
|
||||
* will be NULL on failure.
|
||||
* \return decoded length in bytes
|
||||
*/
|
||||
static int decode_nsc_base64(char *in, char **buf) {
|
||||
static int decode_nsc_base64(struct mp_log *log, char *in, char **buf) {
|
||||
int i, j, n;
|
||||
if (in[0] != '0' || in[1] != '2')
|
||||
goto err_out;
|
||||
@ -406,7 +408,7 @@ static int decode_nsc_base64(char *in, char **buf) {
|
||||
else if (c[j] == '{') c[j] = 62;
|
||||
else if (c[j] == '}') c[j] = 63;
|
||||
else {
|
||||
mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Invalid character %c (0x%02"PRIx8")\n", c[j], c[j]);
|
||||
mp_err(log, "Invalid character %c (0x%02"PRIx8")\n", c[j], c[j]);
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
@ -438,7 +440,7 @@ static bool parse_nsc(play_tree_parser_t* p) {
|
||||
char *line, *addr = NULL, *url, *unicast_url = NULL;
|
||||
int port = 0;
|
||||
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying nsc playlist...\n");
|
||||
MP_VERBOSE(p, "Trying nsc playlist...\n");
|
||||
while((line = play_tree_parser_get_line(p)) != NULL) {
|
||||
strstrip(line);
|
||||
if(!line[0]) // Ignore empties
|
||||
@ -448,22 +450,22 @@ static bool parse_nsc(play_tree_parser_t* p) {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected nsc playlist format\n");
|
||||
MP_VERBOSE(p, "Detected nsc playlist format\n");
|
||||
play_tree_parser_stop_keeping(p);
|
||||
while ((line = play_tree_parser_get_line(p)) != NULL) {
|
||||
strstrip(line);
|
||||
if (!line[0])
|
||||
continue;
|
||||
if (strncasecmp(line, "Unicast URL=", 12) == 0) {
|
||||
int len = decode_nsc_base64(&line[12], &unicast_url);
|
||||
int len = decode_nsc_base64(p->log, &line[12], &unicast_url);
|
||||
if (len <= 0)
|
||||
mp_msg(MSGT_PLAYTREE, MSGL_WARN, "[nsc] Unsupported Unicast URL encoding\n");
|
||||
MP_WARN(p, "[nsc] Unsupported Unicast URL encoding\n");
|
||||
else
|
||||
utf16_to_ascii(unicast_url, len);
|
||||
} else if (strncasecmp(line, "IP Address=", 11) == 0) {
|
||||
int len = decode_nsc_base64(&line[11], &addr);
|
||||
int len = decode_nsc_base64(p->log, &line[11], &addr);
|
||||
if (len <= 0)
|
||||
mp_msg(MSGT_PLAYTREE, MSGL_WARN, "[nsc] Unsupported IP Address encoding\n");
|
||||
MP_WARN(p, "[nsc] Unsupported IP Address encoding\n");
|
||||
else
|
||||
utf16_to_ascii(addr, len);
|
||||
} else if (strncasecmp(line, "IP Port=", 8) == 0) {
|
||||
@ -490,29 +492,31 @@ err_out:
|
||||
return success;
|
||||
}
|
||||
|
||||
static struct playlist *do_parse(struct stream* stream, bool forced);
|
||||
static struct playlist *do_parse(struct stream* stream, bool forced,
|
||||
struct mp_log *log, struct mpv_global *global);
|
||||
|
||||
struct playlist *playlist_parse_file(const char *file, struct MPOpts *opts)
|
||||
struct playlist *playlist_parse_file(const char *file, struct mpv_global *global)
|
||||
{
|
||||
stream_t *stream = stream_open(file, opts);
|
||||
struct mp_log *log = mp_log_new(NULL, global->log, "!playlist_parser");
|
||||
struct playlist *ret = NULL;
|
||||
stream_t *stream = stream_open(file, global->opts);
|
||||
if(!stream) {
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_ERR,
|
||||
"Error while opening playlist file %s: %s\n",
|
||||
mp_err(log, "Error while opening playlist file %s: %s\n",
|
||||
file, strerror(errno));
|
||||
return false;
|
||||
goto done;
|
||||
}
|
||||
|
||||
mp_msg(MSGT_PLAYTREE, MSGL_V,
|
||||
"Parsing playlist file %s...\n", file);
|
||||
mp_verbose(log, "Parsing playlist file %s...\n", file);
|
||||
|
||||
struct playlist *ret = do_parse(stream, true);
|
||||
ret = do_parse(stream, true, log, global);
|
||||
free_stream(stream);
|
||||
|
||||
if (ret)
|
||||
playlist_add_base_path(ret, mp_dirname(file));
|
||||
|
||||
done:
|
||||
talloc_free(log);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
typedef bool (*parser_fn)(play_tree_parser_t *);
|
||||
@ -524,16 +528,18 @@ static const parser_fn pl_parsers[] = {
|
||||
};
|
||||
|
||||
|
||||
static struct playlist *do_parse(struct stream* stream, bool forced)
|
||||
static struct playlist *do_parse(struct stream* stream, bool forced,
|
||||
struct mp_log *log, struct mpv_global *global)
|
||||
{
|
||||
play_tree_parser_t p = {
|
||||
.stream = stream,
|
||||
.pl = talloc_zero(NULL, struct playlist),
|
||||
.keep = 1,
|
||||
.log = log,
|
||||
};
|
||||
|
||||
bool success = false;
|
||||
struct demuxer *pl_demux = demux_open(stream, "playlist", NULL, stream->opts);
|
||||
struct demuxer *pl_demux = demux_open(stream, "playlist", NULL, global->opts);
|
||||
if (pl_demux && pl_demux->playlist) {
|
||||
playlist_transfer_entries(p.pl, pl_demux->playlist);
|
||||
success = true;
|
||||
@ -552,15 +558,15 @@ static struct playlist *do_parse(struct stream* stream, bool forced)
|
||||
}
|
||||
|
||||
if(success)
|
||||
mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist successfully parsed\n");
|
||||
mp_verbose(log, "Playlist successfully parsed\n");
|
||||
else {
|
||||
mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_ERR:MSGL_V),"Error while parsing playlist\n");
|
||||
mp_msg_log(log,((forced==1)?MSGL_ERR:MSGL_V),"Error while parsing playlist\n");
|
||||
talloc_free(p.pl);
|
||||
p.pl = NULL;
|
||||
}
|
||||
|
||||
if (p.pl && !p.pl->first)
|
||||
mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_WARN:MSGL_V),"Warning: empty playlist\n");
|
||||
mp_msg_log(log, ((forced==1)?MSGL_WARN:MSGL_V),"Warning: empty playlist\n");
|
||||
|
||||
return p.pl;
|
||||
}
|
||||
|
@ -19,11 +19,9 @@
|
||||
#ifndef MPLAYER_PLAYLISTPARSER_H
|
||||
#define MPLAYER_PLAYLISTPARSER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct MPOpts;
|
||||
struct mpv_global;
|
||||
struct playlist;
|
||||
|
||||
struct playlist *playlist_parse_file(const char *file, struct MPOpts *opts);
|
||||
struct playlist *playlist_parse_file(const char *file, struct mpv_global *global);
|
||||
|
||||
#endif
|
||||
|
@ -114,7 +114,6 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
||||
struct mpv_global *global,
|
||||
int argc, char **argv)
|
||||
{
|
||||
struct MPOpts *opts = config->optstruct;
|
||||
int ret = M_OPT_UNKNOWN;
|
||||
int mode = 0;
|
||||
struct playlist_entry *local_start = NULL;
|
||||
@ -186,7 +185,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
|
||||
if (bstrcmp0(p.arg, "playlist") == 0) {
|
||||
// append the playlist to the local args
|
||||
char *param0 = bstrdup0(NULL, p.param);
|
||||
struct playlist *pl = playlist_parse_file(param0, opts);
|
||||
struct playlist *pl = playlist_parse_file(param0, global);
|
||||
talloc_free(param0);
|
||||
if (!pl) {
|
||||
MP_FATAL(config, "Error reading playlist '%.*s'", BSTR_P(p.param));
|
||||
|
@ -2792,7 +2792,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
case MP_CMD_LOADLIST: {
|
||||
char *filename = cmd->args[0].v.s;
|
||||
bool append = cmd->args[1].v.i;
|
||||
struct playlist *pl = playlist_parse_file(filename, opts);
|
||||
struct playlist *pl = playlist_parse_file(filename, mpctx->global);
|
||||
if (pl) {
|
||||
if (!append)
|
||||
playlist_clear(mpctx->playlist);
|
||||
|
Loading…
Reference in New Issue
Block a user