2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /// \ingroup PlaytreeParser
28 #include <sys/types.h>
36 #include "asxparser.h"
39 #include "playtreeparser.h"
40 #include "stream/stream.h"
41 #include "libmpdemux/demuxer.h"
47 #define WHITES " \n\r\t"
55 for(i
= str
; i
[0] != '\0' && strchr(WHITES
,i
[0]) != NULL
; i
++)
58 memmove(str
,i
,strlen(i
) + 1);
59 for(i
= str
+ strlen(str
) - 1 ; strchr(WHITES
,i
[0]) != NULL
; i
--)
67 play_tree_parser_get_line(play_tree_parser_t
* p
) {
71 if(p
->buffer
== NULL
) {
72 p
->buffer
= malloc(BUF_STEP
);
73 p
->buffer_size
= BUF_STEP
;
78 if(p
->stream
->eof
&& (p
->buffer_end
== 0 || p
->iter
[0] == '\0'))
81 assert(p
->buffer_end
< p
->buffer_size
);
82 assert(!p
->buffer
[p
->buffer_end
]);
87 r
= p
->iter
- p
->buffer
;
88 end
= p
->buffer
+ p
->buffer_end
;
89 if (p
->buffer_size
> INT_MAX
- BUF_STEP
)
91 tmp
= realloc(p
->buffer
, p
->buffer_size
+ BUF_STEP
);
95 p
->iter
= p
->buffer
+ r
;
96 p
->buffer_size
+= BUF_STEP
;
100 if(p
->buffer_size
- p
->buffer_end
> 1 && ! p
->stream
->eof
) {
101 r
= stream_read(p
->stream
,p
->buffer
+ p
->buffer_end
,p
->buffer_size
- p
->buffer_end
- 1);
104 assert(p
->buffer_end
< p
->buffer_size
);
105 p
->buffer
[p
->buffer_end
] = '\0';
106 while(strlen(p
->buffer
+ p
->buffer_end
- r
) != r
)
107 p
->buffer
[p
->buffer_end
- r
+ strlen(p
->buffer
+ p
->buffer_end
- r
)] = '\n';
109 assert(!p
->buffer
[p
->buffer_end
]);
112 end
= strchr(p
->iter
,'\n');
115 end
= p
->buffer
+ p
->buffer_end
;
124 line_end
= (end
> p
->iter
&& *(end
-1) == '\r') ? end
-1 : end
;
125 if(line_end
- p
->iter
>= 0)
126 p
->line
= realloc(p
->line
, line_end
- p
->iter
+ 1);
129 if(line_end
- p
->iter
> 0)
130 strncpy(p
->line
,p
->iter
,line_end
- p
->iter
);
131 p
->line
[line_end
- p
->iter
] = '\0';
137 p
->buffer_end
-= end
-p
->iter
;
138 memmove(p
->buffer
,end
,p
->buffer_end
);
141 p
->buffer
[p
->buffer_end
] = '\0';
150 play_tree_parser_reset(play_tree_parser_t
* p
) {
155 play_tree_parser_stop_keeping(play_tree_parser_t
* p
) {
157 if(p
->iter
&& p
->iter
!= p
->buffer
) {
158 p
->buffer_end
-= p
->iter
-p
->buffer
;
160 memmove(p
->buffer
,p
->iter
,p
->buffer_end
);
161 p
->buffer
[p
->buffer_end
] = 0;
168 parse_asx(play_tree_parser_t
* p
) {
169 int comments
= 0,get_line
= 1;
172 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying asx...\n");
176 line
= play_tree_parser_get_line(p
);
185 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"First char isn't '<' but '%c'\n",line
[0]);
186 mp_msg(MSGT_PLAYTREE
,MSGL_DBG3
,"Buffer = [%s]\n",p
->buffer
);
188 } else if(strncmp(line
,"<!--",4) == 0) { // Comments
191 if(line
[0] != '\0' && strlen(line
) > 0)
193 } else if(strncasecmp(line
,"<ASX",4) == 0) // We got an asx element
195 else // We don't get an asx
199 c
= strchr(line
,'-');
201 if (strncmp(c
,"--!>",4) == 0) { // End of comments
204 if(line
[0] != '\0') // There is some more data on this line : keep it
208 line
= c
+1; // Jump the -
209 if(line
[0] != '\0') // Some more data
214 } else // No - on this line (or rest of line) : get next one
219 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected asx format\n");
221 // We have an asx : load it in memory and parse
223 while((line
= play_tree_parser_get_line(p
)) != NULL
)
226 mp_msg(MSGT_PLAYTREE
,MSGL_DBG3
,"Parsing asx file: [%s]\n",p
->buffer
);
227 return asx_parser_build_tree(p
->mconfig
, p
->buffer
,p
->deep
);
231 pls_entry_get_value(char* line
) {
234 i
= strchr(line
,'=');
235 if(!i
|| i
[1] == '\0')
241 typedef struct pls_entry
{
248 pls_read_entry(char* line
,pls_entry_t
** _e
,int* _max_entry
,char** val
) {
249 int num
,max_entry
= (*_max_entry
);
250 pls_entry_t
* e
= (*_e
);
251 int limit
= INT_MAX
/ sizeof(*e
);
254 v
= pls_entry_get_value(line
);
256 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
261 if(num
<= 0 || num
> limit
) {
262 if (max_entry
>= limit
) {
263 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "Too many index entries\n");
267 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"No or invalid entry index in entry %s\nAssuming %d\n",line
,num
);
269 if(num
> max_entry
) {
270 e
= realloc(e
, num
* sizeof(pls_entry_t
));
273 memset(&e
[max_entry
],0,(num
-max_entry
)*sizeof(pls_entry_t
));
277 (*_max_entry
) = max_entry
;
285 parse_pls(play_tree_parser_t
* p
) {
287 pls_entry_t
* entries
= NULL
;
288 int n_entries
= 0,max_entry
=0,num
;
289 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
291 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying Winamp playlist...\n");
292 while((line
= play_tree_parser_get_line(p
))) {
299 if(strcasecmp(line
,"[playlist]"))
301 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected Winamp playlist format\n");
302 play_tree_parser_stop_keeping(p
);
303 line
= play_tree_parser_get_line(p
);
307 if(strncasecmp(line
,"NumberOfEntries",15) == 0) {
308 v
= pls_entry_get_value(line
);
311 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Invalid number of entries: very funny!!!\n");
313 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Playlist claims to have %d entries. Let's see.\n",n_entries
);
314 line
= play_tree_parser_get_line(p
);
319 if(line
[0] == '\0') {
320 line
= play_tree_parser_get_line(p
);
323 if(strncasecmp(line
,"File",4) == 0) {
324 num
= pls_read_entry(line
+4,&entries
,&max_entry
,&v
);
326 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
328 entries
[num
-1].file
= strdup(v
);
329 } else if(strncasecmp(line
,"Title",5) == 0) {
330 num
= pls_read_entry(line
+5,&entries
,&max_entry
,&v
);
332 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
334 entries
[num
-1].title
= strdup(v
);
335 } else if(strncasecmp(line
,"Length",6) == 0) {
336 num
= pls_read_entry(line
+6,&entries
,&max_entry
,&v
);
338 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
341 long val
= strtol(v
, &end
, 10);
342 if (*end
|| (val
<= 0 && val
!= -1))
343 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"Invalid length value in entry %s\n",line
);
345 entries
[num
-1].length
= strdup(v
);
348 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"Unknown entry type %s\n",line
);
349 line
= play_tree_parser_get_line(p
);
352 for(num
= 0; num
< max_entry
; num
++) {
353 if(entries
[num
].file
== NULL
)
354 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"Entry %d don't have a file !!!!\n",num
+1);
356 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Adding entry %s\n",entries
[num
].file
);
357 entry
= play_tree_new();
358 play_tree_add_file(entry
,entries
[num
].file
);
359 if (entries
[num
].length
)
360 play_tree_set_param(entry
, bstr("endpos"), bstr(entries
[num
].length
));
361 free(entries
[num
].file
);
363 play_tree_append_entry(last_entry
,entry
);
368 // When we have info in playtree we add these info
369 free(entries
[num
].title
);
370 free(entries
[num
].length
);
378 entry
= play_tree_new();
379 play_tree_set_child(entry
,list
);
384 Reference Ini-Format: Each entry is assumed a reference
387 parse_ref_ini(play_tree_parser_t
* p
) {
389 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
391 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying reference-ini playlist...\n");
392 if (!(line
= play_tree_parser_get_line(p
)))
395 if(strcasecmp(line
,"[Reference]"))
397 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected reference-ini playlist format\n");
398 play_tree_parser_stop_keeping(p
);
399 line
= play_tree_parser_get_line(p
);
404 if(strncasecmp(line
,"Ref",3) == 0) {
405 v
= pls_entry_get_value(line
+3);
407 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
410 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Adding entry %s\n",v
);
411 entry
= play_tree_new();
412 play_tree_add_file(entry
,v
);
414 play_tree_append_entry(last_entry
,entry
);
420 line
= play_tree_parser_get_line(p
);
423 if(!list
) return NULL
;
424 entry
= play_tree_new();
425 play_tree_set_child(entry
,list
);
430 parse_m3u(play_tree_parser_t
* p
) {
432 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
434 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying extended m3u playlist...\n");
435 if (!(line
= play_tree_parser_get_line(p
)))
438 if(strcasecmp(line
,"#EXTM3U"))
440 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected extended m3u playlist format\n");
441 play_tree_parser_stop_keeping(p
);
443 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
447 /* EXTM3U files contain such lines:
448 * #EXTINF:<seconds>, <title>
449 * followed by a line with the filename
450 * for now we have no place to put that
451 * so we just skip that extra-info ::atmos
454 #if 0 /* code functional */
455 if(strncasecmp(line
,"#EXTINF:",8) == 0) {
456 mp_msg(MSGT_PLAYTREE
,MSGL_INFO
,"[M3U] Duration: %dsec Title: %s\n",
457 strtol(line
+8,&line
,10), line
+2);
462 entry
= play_tree_new();
463 play_tree_add_file(entry
,line
);
467 play_tree_append_entry(last_entry
,entry
);
471 if(!list
) return NULL
;
472 entry
= play_tree_new();
473 play_tree_set_child(entry
,list
);
478 parse_smil(play_tree_parser_t
* p
) {
480 char* line
,source
[512],*pos
,*s_start
,*s_end
,*src_line
;
481 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
483 unsigned int npkt
, ttlpkt
;
485 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying smil playlist...\n");
488 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
490 if(line
[0] == '\0') // Ignore empties
492 if (strncasecmp(line
,"<?xml",5)==0) // smil in xml
494 if (strncasecmp(line
,"<!DOCTYPE smil",13)==0) // smil in xml
496 if (strncasecmp(line
,"<smil",5)==0 || strncasecmp(line
,"<?wpl",5)==0 ||
497 strncasecmp(line
,"(smil-document",14)==0)
498 break; // smil header found
500 return NULL
; //line not smil exit
503 if (!line
) return NULL
;
504 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected smil playlist format\n");
505 play_tree_parser_stop_keeping(p
);
507 if (strncasecmp(line
,"(smil-document",14)==0) {
508 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Special smil-over-realrtsp playlist header\n");
510 if (sscanf(line
, "(smil-document (ver 1.0)(npkt %u)(ttlpkt %u", &npkt
, &ttlpkt
) != 2) {
511 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: header parsing failure, assuming single packet.\n");
514 if (ttlpkt
== 0 || npkt
> ttlpkt
) {
515 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: bad packet counters (npkk = %u, ttlpkt = %u), assuming single packet.\n",
521 //Get entries from smil
528 /* If we're parsing smil over realrtsp and this is not the last packet and
529 * this is the last line in the packet (terminating with ") ) we must get
530 * the next line, strip the header, and concatenate it to the current line.
532 if (is_rmsmil
&& npkt
!= ttlpkt
&& strstr(src_line
,"\")")) {
535 line
= strdup(src_line
);
536 if(!(src_line
= play_tree_parser_get_line(p
))) {
537 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: can't get line from packet %u/%u.\n", npkt
, ttlpkt
);
541 // Skip header, packet starts after "
542 if(!(payload
= strchr(src_line
,'\"'))) {
543 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: can't find start of packet, using complete line.\n");
547 // Skip ") at the end of the last line from the current packet
548 line
[strlen(line
)-2] = 0;
549 line
= realloc(line
, strlen(line
)+strlen(payload
)+1);
550 strcat (line
, payload
);
553 line
= strdup(src_line
);
554 /* Unescape \" to " for smil-over-rtsp */
555 if (is_rmsmil
&& line
[0] != '\0') {
558 for (i
= 0; i
< strlen(line
); i
++)
559 if (line
[i
] == '\\' && line
[i
+1] == '"')
560 for (j
= i
; line
[j
]; j
++)
565 if (!entrymode
) { // all entries filled so far
566 while ((pos
=strchr(pos
, '<'))) {
567 if (strncasecmp(pos
,"<video",6)==0 || strncasecmp(pos
,"<audio",6)==0 || strncasecmp(pos
,"<media",6)==0) {
569 break; // Got a valid tag, exit '<' search loop
574 if (entrymode
) { //Entry found but not yet filled
575 pos
= strstr(pos
,"src="); // Is source present on this line
578 if (pos
[4] != '"' && pos
[4] != '\'') {
579 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Unknown delimiter %c in source line %s\n", pos
[4], line
);
583 s_end
=strchr(s_start
,pos
[4]);
585 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Error parsing this source line %s\n",line
);
588 if (s_end
-s_start
> 511) {
589 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Cannot store such a large source %s\n",line
);
592 strncpy(source
,s_start
,s_end
-s_start
);
593 source
[(s_end
-s_start
)]='\0'; // Null terminate
594 entry
= play_tree_new();
595 play_tree_add_file(entry
,source
);
596 if(!list
) //Insert new entry
599 play_tree_append_entry(last_entry
,entry
);
605 } while((src_line
= play_tree_parser_get_line(p
)) != NULL
);
609 if(!list
) return NULL
; // Nothing found
611 entry
= play_tree_new();
612 play_tree_set_child(entry
,list
);
617 embedded_playlist_parse(struct m_config
*mconfig
, char *line
) {
618 int f
=DEMUXER_TYPE_PLAYLIST
;
620 play_tree_parser_t
* ptp
;
623 // Get stream opened to link
624 stream
=open_stream(line
,0,&f
);
626 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"Can't open playlist %s\n",line
);
631 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Adding playlist %s to element entryref\n",line
);
633 ptp
= play_tree_parser_new(stream
, mconfig
, 1);
634 entry
= play_tree_parser_get_play_tree(ptp
, 1);
635 play_tree_parser_free(ptp
);
642 parse_textplain(play_tree_parser_t
* p
) {
646 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
648 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying plaintext playlist...\n");
649 play_tree_parser_stop_keeping(p
);
651 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
653 if(line
[0] == '\0' || line
[0] == '#' || (line
[0] == '/' && line
[1] == '/'))
656 //Special check for embedded smil or ram reference in file
658 if (strlen(line
) > 5)
659 for(c
= line
; c
[0]; c
++ )
660 if ( ((c
[0] == '.') && //start with . and next have smil with optional ? or &
661 (tolower(c
[1]) == 's') && (tolower(c
[2])== 'm') &&
662 (tolower(c
[3]) == 'i') && (tolower(c
[4]) == 'l') &&
663 (!c
[5] || c
[5] == '?' || c
[5] == '&')) || // or
664 ((c
[0] == '.') && // start with . and next have smi or ram with optional ? or &
665 ( ((tolower(c
[1]) == 's') && (tolower(c
[2])== 'm') && (tolower(c
[3]) == 'i')) ||
666 ((tolower(c
[1]) == 'r') && (tolower(c
[2])== 'a') && (tolower(c
[3]) == 'm')) )
667 && (!c
[4] || c
[4] == '?' || c
[4] == '&')) ){
668 entry
=embedded_playlist_parse(p
->mconfig
, line
);
673 if (!embedded
) { //regular file link
674 entry
= play_tree_new();
675 play_tree_add_file(entry
,line
);
682 play_tree_append_entry(last_entry
,entry
);
687 if(!list
) return NULL
;
688 entry
= play_tree_new();
689 play_tree_set_child(entry
,list
);
694 * \brief decode the base64 used in nsc files
695 * \param in input string, 0-terminated
696 * \param buf output buffer, must point to memory suitable for realloc,
697 * will be NULL on failure.
698 * \return decoded length in bytes
700 static int decode_nsc_base64(char *in
, char **buf
) {
702 if (in
[0] != '0' || in
[1] != '2')
704 in
+= 2; // skip prefix
705 if (strlen(in
) < 16) // error out if nothing to decode
707 in
+= 12; // skip encoded string length
709 *buf
= realloc(*buf
, n
* 3);
710 for (i
= 0; i
< n
; i
++) {
712 for (j
= 0; j
< 4; j
++) {
713 c
[j
] = in
[4 * i
+ j
];
714 if (c
[j
] >= '0' && c
[j
] <= '9') c
[j
] += 0 - '0';
715 else if (c
[j
] >= 'A' && c
[j
] <= 'Z') c
[j
] += 10 - 'A';
716 else if (c
[j
] >= 'a' && c
[j
] <= 'z') c
[j
] += 36 - 'a';
717 else if (c
[j
] == '{') c
[j
] = 62;
718 else if (c
[j
] == '}') c
[j
] = 63;
720 mp_msg(MSGT_PLAYTREE
, MSGL_ERR
, "Invalid character %c (0x%02"PRIx8
")\n", c
[j
], c
[j
]);
724 (*buf
)[3 * i
] = (c
[0] << 2) | (c
[1] >> 4);
725 (*buf
)[3 * i
+ 1] = (c
[1] << 4) | (c
[2] >> 2);
726 (*buf
)[3 * i
+ 2] = (c
[2] << 6) | c
[3];
736 * \brief "converts" utf16 to ascii by just discarding every second byte
737 * \param buf buffer to convert
738 * \param len lenght of buffer, must be > 0
740 static void utf16_to_ascii(char *buf
, int len
) {
742 if (len
<= 0) return;
743 for (i
= 0; i
< len
/ 2; i
++)
745 buf
[i
] = 0; // just in case
748 static play_tree_t
*parse_nsc(play_tree_parser_t
* p
) {
749 char *line
, *addr
= NULL
, *url
, *unicast_url
= NULL
;
751 play_tree_t
*entry
= NULL
;
753 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying nsc playlist...\n");
754 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
756 if(!line
[0]) // Ignore empties
758 if (strncasecmp(line
,"[Address]", 9) == 0)
759 break; // nsc header found
763 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected nsc playlist format\n");
764 play_tree_parser_stop_keeping(p
);
765 while ((line
= play_tree_parser_get_line(p
)) != NULL
) {
769 if (strncasecmp(line
, "Unicast URL=", 12) == 0) {
770 int len
= decode_nsc_base64(&line
[12], &unicast_url
);
772 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "[nsc] Unsupported Unicast URL encoding\n");
774 utf16_to_ascii(unicast_url
, len
);
775 } else if (strncasecmp(line
, "IP Address=", 11) == 0) {
776 int len
= decode_nsc_base64(&line
[11], &addr
);
778 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "[nsc] Unsupported IP Address encoding\n");
780 utf16_to_ascii(addr
, len
);
781 } else if (strncasecmp(line
, "IP Port=", 8) == 0) {
782 port
= strtol(&line
[8], NULL
, 0);
787 url
= strdup(unicast_url
);
788 else if (addr
&& port
) {
789 url
= malloc(strlen(addr
) + 7 + 20 + 1);
790 sprintf(url
, "http://%s:%i", addr
, port
);
794 entry
= play_tree_new();
795 play_tree_add_file(entry
, url
);
804 parse_playtree(stream_t
*stream
, struct m_config
*mconfig
, int forced
) {
805 play_tree_parser_t
* p
;
808 assert(stream
!= NULL
);
810 p
= play_tree_parser_new(stream
, mconfig
, 0);
814 ret
= play_tree_parser_get_play_tree(p
, forced
);
815 play_tree_parser_free(p
);
821 play_tree_add_basepath(play_tree_t
* pt
, char* bp
) {
822 int i
,bl
= strlen(bp
),fl
;
826 for(i
= pt
->child
; i
!= NULL
; i
= i
->next
)
827 play_tree_add_basepath(i
,bp
);
834 for(i
= 0 ; pt
->files
[i
] != NULL
; i
++) {
835 fl
= strlen(pt
->files
[i
]);
836 // if we find a full unix path, url:// or X:\ at the beginning,
838 if(fl
<= 0 || strstr(pt
->files
[i
],"://") || (strstr(pt
->files
[i
],":\\") == pt
->files
[i
] + 1) || (pt
->files
[i
][0] == '/') )
840 // if the path begins with \ then prepend drive letter to it.
841 if (pt
->files
[i
][0] == '\\') {
842 if (pt
->files
[i
][1] == '\\')
844 pt
->files
[i
] = realloc(pt
->files
[i
], 2 + fl
+ 1);
845 memmove(pt
->files
[i
] + 2,pt
->files
[i
],fl
+1);
846 memcpy(pt
->files
[i
],bp
,2);
849 pt
->files
[i
] = realloc(pt
->files
[i
], bl
+ fl
+ 1);
850 memmove(pt
->files
[i
] + bl
,pt
->files
[i
],fl
+1);
851 memcpy(pt
->files
[i
],bp
,bl
);
855 // Wrapper for play_tree_add_basepath (add base path from file)
856 void play_tree_add_bpf(play_tree_t
*pt
, struct bstr filename
)
862 file
= bstrdup0(NULL
, filename
);
865 ls
= strrchr(file
,'/');
866 if(!ls
) ls
= strrchr(file
,'\\');
869 play_tree_add_basepath(pt
,file
);
877 parse_playlist_file(struct m_config
*mconfig
, struct bstr file
) {
880 int f
=DEMUXER_TYPE_PLAYLIST
;
882 char *file0
= bstrdup0(NULL
, file
);
883 stream
= open_stream(file0
, 0, &f
);
887 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,
888 "Error while opening playlist file %.*s: %s\n",
889 BSTR_P(file
), strerror(errno
));
893 mp_msg(MSGT_PLAYTREE
, MSGL_V
,
894 "Parsing playlist file %.*s...\n", BSTR_P(file
));
896 ret
= parse_playtree(stream
, mconfig
, 1);
899 play_tree_add_bpf(ret
, file
);
907 play_tree_parser_new(stream_t
* stream
, struct m_config
*mconfig
, int deep
) {
908 play_tree_parser_t
* p
;
910 p
= calloc(1,sizeof(play_tree_parser_t
));
914 p
->mconfig
= mconfig
;
923 play_tree_parser_free(play_tree_parser_t
* p
) {
933 play_tree_parser_get_play_tree(play_tree_parser_t
* p
, int forced
) {
934 play_tree_t
* tree
= NULL
;
938 while(play_tree_parser_get_line(p
) != NULL
) {
939 play_tree_parser_reset(p
);
943 play_tree_parser_reset(p
);
947 play_tree_parser_reset(p
);
951 play_tree_parser_reset(p
);
953 tree
= parse_ref_ini(p
);
955 play_tree_parser_reset(p
);
957 tree
= parse_smil(p
);
959 play_tree_parser_reset(p
);
963 play_tree_parser_reset(p
);
965 // Here come the others formats ( textplain must stay the last one )
968 tree
= parse_textplain(p
);
975 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Playlist successfully parsed\n");
977 mp_msg(MSGT_PLAYTREE
,((forced
==1)?MSGL_ERR
:MSGL_V
),"Error while parsing playlist\n");
980 tree
= play_tree_cleanup(tree
);
982 if(!tree
) mp_msg(MSGT_PLAYTREE
,((forced
==1)?MSGL_WARN
:MSGL_V
),"Warning: empty playlist\n");