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"
38 #include "playtreeparser.h"
39 #include "stream/stream.h"
40 #include "libmpdemux/demuxer.h"
46 #define WHITES " \n\r\t"
54 for(i
= str
; i
[0] != '\0' && strchr(WHITES
,i
[0]) != NULL
; i
++)
57 memmove(str
,i
,strlen(i
) + 1);
58 for(i
= str
+ strlen(str
) - 1 ; strchr(WHITES
,i
[0]) != NULL
; i
--)
66 play_tree_parser_get_line(play_tree_parser_t
* p
) {
70 if(p
->buffer
== NULL
) {
71 p
->buffer
= malloc(BUF_STEP
);
72 p
->buffer_size
= BUF_STEP
;
77 if(p
->stream
->eof
&& (p
->buffer_end
== 0 || p
->iter
[0] == '\0'))
80 assert(p
->buffer_end
< p
->buffer_size
);
81 assert(!p
->buffer
[p
->buffer_end
]);
86 r
= p
->iter
- p
->buffer
;
87 end
= p
->buffer
+ p
->buffer_end
;
88 if (p
->buffer_size
> INT_MAX
- BUF_STEP
)
90 tmp
= realloc(p
->buffer
, p
->buffer_size
+ BUF_STEP
);
94 p
->iter
= p
->buffer
+ r
;
95 p
->buffer_size
+= BUF_STEP
;
99 if(p
->buffer_size
- p
->buffer_end
> 1 && ! p
->stream
->eof
) {
100 r
= stream_read(p
->stream
,p
->buffer
+ p
->buffer_end
,p
->buffer_size
- p
->buffer_end
- 1);
103 assert(p
->buffer_end
< p
->buffer_size
);
104 p
->buffer
[p
->buffer_end
] = '\0';
105 while(strlen(p
->buffer
+ p
->buffer_end
- r
) != r
)
106 p
->buffer
[p
->buffer_end
- r
+ strlen(p
->buffer
+ p
->buffer_end
- r
)] = '\n';
108 assert(!p
->buffer
[p
->buffer_end
]);
111 end
= strchr(p
->iter
,'\n');
114 end
= p
->buffer
+ p
->buffer_end
;
123 line_end
= (end
> p
->iter
&& *(end
-1) == '\r') ? end
-1 : end
;
124 if(line_end
- p
->iter
>= 0)
125 p
->line
= realloc(p
->line
, line_end
- p
->iter
+ 1);
128 if(line_end
- p
->iter
> 0)
129 strncpy(p
->line
,p
->iter
,line_end
- p
->iter
);
130 p
->line
[line_end
- p
->iter
] = '\0';
136 p
->buffer_end
-= end
-p
->iter
;
137 memmove(p
->buffer
,end
,p
->buffer_end
);
140 p
->buffer
[p
->buffer_end
] = '\0';
149 play_tree_parser_reset(play_tree_parser_t
* p
) {
154 play_tree_parser_stop_keeping(play_tree_parser_t
* p
) {
156 if(p
->iter
&& p
->iter
!= p
->buffer
) {
157 p
->buffer_end
-= p
->iter
-p
->buffer
;
159 memmove(p
->buffer
,p
->iter
,p
->buffer_end
);
160 p
->buffer
[p
->buffer_end
] = 0;
167 parse_asx(play_tree_parser_t
* p
) {
168 int comments
= 0,get_line
= 1;
171 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying asx...\n");
175 line
= play_tree_parser_get_line(p
);
184 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"First char isn't '<' but '%c'\n",line
[0]);
185 mp_msg(MSGT_PLAYTREE
,MSGL_DBG3
,"Buffer = [%s]\n",p
->buffer
);
187 } else if(strncmp(line
,"<!--",4) == 0) { // Comments
190 if(line
[0] != '\0' && strlen(line
) > 0)
192 } else if(strncasecmp(line
,"<ASX",4) == 0) // We got an asx element
194 else // We don't get an asx
198 c
= strchr(line
,'-');
200 if (strncmp(c
,"--!>",4) == 0) { // End of comments
203 if(line
[0] != '\0') // There is some more data on this line : keep it
207 line
= c
+1; // Jump the -
208 if(line
[0] != '\0') // Some more data
213 } else // No - on this line (or rest of line) : get next one
218 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected asx format\n");
220 // We have an asx : load it in memory and parse
222 while((line
= play_tree_parser_get_line(p
)) != NULL
)
225 mp_msg(MSGT_PLAYTREE
,MSGL_DBG3
,"Parsing asx file: [%s]\n",p
->buffer
);
226 return asx_parser_build_tree(p
->opts
, p
->buffer
,p
->deep
);
230 pls_entry_get_value(char* line
) {
233 i
= strchr(line
,'=');
234 if(!i
|| i
[1] == '\0')
240 typedef struct pls_entry
{
247 pls_read_entry(char* line
,pls_entry_t
** _e
,int* _max_entry
,char** val
) {
248 int num
,max_entry
= (*_max_entry
);
249 pls_entry_t
* e
= (*_e
);
250 int limit
= INT_MAX
/ sizeof(*e
);
253 v
= pls_entry_get_value(line
);
255 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
260 if(num
<= 0 || num
> limit
) {
261 if (max_entry
>= limit
) {
262 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "Too many index entries\n");
266 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"No or invalid entry index in entry %s\nAssuming %d\n",line
,num
);
268 if(num
> max_entry
) {
269 e
= realloc(e
, num
* sizeof(pls_entry_t
));
272 memset(&e
[max_entry
],0,(num
-max_entry
)*sizeof(pls_entry_t
));
276 (*_max_entry
) = max_entry
;
284 parse_pls(play_tree_parser_t
* p
) {
286 pls_entry_t
* entries
= NULL
;
287 int n_entries
= 0,max_entry
=0,num
;
288 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
290 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying Winamp playlist...\n");
291 while((line
= play_tree_parser_get_line(p
))) {
298 if(strcasecmp(line
,"[playlist]"))
300 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected Winamp playlist format\n");
301 play_tree_parser_stop_keeping(p
);
302 line
= play_tree_parser_get_line(p
);
306 if(strncasecmp(line
,"NumberOfEntries",15) == 0) {
307 v
= pls_entry_get_value(line
);
310 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Invalid number of entries: very funny!!!\n");
312 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Playlist claims to have %d entries. Let's see.\n",n_entries
);
313 line
= play_tree_parser_get_line(p
);
318 if(line
[0] == '\0') {
319 line
= play_tree_parser_get_line(p
);
322 if(strncasecmp(line
,"File",4) == 0) {
323 num
= pls_read_entry(line
+4,&entries
,&max_entry
,&v
);
325 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
327 entries
[num
-1].file
= strdup(v
);
328 } else if(strncasecmp(line
,"Title",5) == 0) {
329 num
= pls_read_entry(line
+5,&entries
,&max_entry
,&v
);
331 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
333 entries
[num
-1].title
= strdup(v
);
334 } else if(strncasecmp(line
,"Length",6) == 0) {
335 num
= pls_read_entry(line
+6,&entries
,&max_entry
,&v
);
337 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
340 long val
= strtol(v
, &end
, 10);
341 if (*end
|| (val
<= 0 && val
!= -1))
342 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"Invalid length value in entry %s\n",line
);
344 entries
[num
-1].length
= strdup(v
);
347 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"Unknown entry type %s\n",line
);
348 line
= play_tree_parser_get_line(p
);
351 for(num
= 0; num
< max_entry
; num
++) {
352 if(entries
[num
].file
== NULL
)
353 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"Entry %d don't have a file !!!!\n",num
+1);
355 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Adding entry %s\n",entries
[num
].file
);
356 entry
= play_tree_new();
357 play_tree_add_file(entry
,entries
[num
].file
);
358 if (entries
[num
].length
)
359 play_tree_set_param(entry
, bstr("endpos"), bstr(entries
[num
].length
));
360 free(entries
[num
].file
);
362 play_tree_append_entry(last_entry
,entry
);
367 // When we have info in playtree we add these info
368 free(entries
[num
].title
);
369 free(entries
[num
].length
);
377 entry
= play_tree_new();
378 play_tree_set_child(entry
,list
);
383 Reference Ini-Format: Each entry is assumed a reference
386 parse_ref_ini(play_tree_parser_t
* p
) {
388 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
390 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying reference-ini playlist...\n");
391 if (!(line
= play_tree_parser_get_line(p
)))
394 if(strcasecmp(line
,"[Reference]"))
396 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected reference-ini playlist format\n");
397 play_tree_parser_stop_keeping(p
);
398 line
= play_tree_parser_get_line(p
);
403 if(strncasecmp(line
,"Ref",3) == 0) {
404 v
= pls_entry_get_value(line
+3);
406 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
409 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Adding entry %s\n",v
);
410 entry
= play_tree_new();
411 play_tree_add_file(entry
,v
);
413 play_tree_append_entry(last_entry
,entry
);
419 line
= play_tree_parser_get_line(p
);
422 if(!list
) return NULL
;
423 entry
= play_tree_new();
424 play_tree_set_child(entry
,list
);
429 parse_m3u(play_tree_parser_t
* p
) {
431 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
433 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying extended m3u playlist...\n");
434 if (!(line
= play_tree_parser_get_line(p
)))
437 if(strcasecmp(line
,"#EXTM3U"))
439 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected extended m3u playlist format\n");
440 play_tree_parser_stop_keeping(p
);
442 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
446 /* EXTM3U files contain such lines:
447 * #EXTINF:<seconds>, <title>
448 * followed by a line with the filename
449 * for now we have no place to put that
450 * so we just skip that extra-info ::atmos
453 #if 0 /* code functional */
454 if(strncasecmp(line
,"#EXTINF:",8) == 0) {
455 mp_msg(MSGT_PLAYTREE
,MSGL_INFO
,"[M3U] Duration: %dsec Title: %s\n",
456 strtol(line
+8,&line
,10), line
+2);
461 entry
= play_tree_new();
462 play_tree_add_file(entry
,line
);
466 play_tree_append_entry(last_entry
,entry
);
470 if(!list
) return NULL
;
471 entry
= play_tree_new();
472 play_tree_set_child(entry
,list
);
477 parse_smil(play_tree_parser_t
* p
) {
479 char* line
,source
[512],*pos
,*s_start
,*s_end
,*src_line
;
480 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
482 unsigned int npkt
, ttlpkt
;
484 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying smil playlist...\n");
487 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
489 if(line
[0] == '\0') // Ignore empties
491 if (strncasecmp(line
,"<?xml",5)==0) // smil in xml
493 if (strncasecmp(line
,"<!DOCTYPE smil",13)==0) // smil in xml
495 if (strncasecmp(line
,"<smil",5)==0 || strncasecmp(line
,"<?wpl",5)==0 ||
496 strncasecmp(line
,"(smil-document",14)==0)
497 break; // smil header found
499 return NULL
; //line not smil exit
502 if (!line
) return NULL
;
503 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected smil playlist format\n");
504 play_tree_parser_stop_keeping(p
);
506 if (strncasecmp(line
,"(smil-document",14)==0) {
507 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Special smil-over-realrtsp playlist header\n");
509 if (sscanf(line
, "(smil-document (ver 1.0)(npkt %u)(ttlpkt %u", &npkt
, &ttlpkt
) != 2) {
510 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: header parsing failure, assuming single packet.\n");
513 if (ttlpkt
== 0 || npkt
> ttlpkt
) {
514 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: bad packet counters (npkk = %u, ttlpkt = %u), assuming single packet.\n",
520 //Get entries from smil
527 /* If we're parsing smil over realrtsp and this is not the last packet and
528 * this is the last line in the packet (terminating with ") ) we must get
529 * the next line, strip the header, and concatenate it to the current line.
531 if (is_rmsmil
&& npkt
!= ttlpkt
&& strstr(src_line
,"\")")) {
534 line
= strdup(src_line
);
535 if(!(src_line
= play_tree_parser_get_line(p
))) {
536 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: can't get line from packet %u/%u.\n", npkt
, ttlpkt
);
540 // Skip header, packet starts after "
541 if(!(payload
= strchr(src_line
,'\"'))) {
542 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: can't find start of packet, using complete line.\n");
546 // Skip ") at the end of the last line from the current packet
547 line
[strlen(line
)-2] = 0;
548 line
= realloc(line
, strlen(line
)+strlen(payload
)+1);
549 strcat (line
, payload
);
552 line
= strdup(src_line
);
553 /* Unescape \" to " for smil-over-rtsp */
554 if (is_rmsmil
&& line
[0] != '\0') {
557 for (i
= 0; i
< strlen(line
); i
++)
558 if (line
[i
] == '\\' && line
[i
+1] == '"')
559 for (j
= i
; line
[j
]; j
++)
564 if (!entrymode
) { // all entries filled so far
565 while ((pos
=strchr(pos
, '<'))) {
566 if (strncasecmp(pos
,"<video",6)==0 || strncasecmp(pos
,"<audio",6)==0 || strncasecmp(pos
,"<media",6)==0) {
568 break; // Got a valid tag, exit '<' search loop
573 if (entrymode
) { //Entry found but not yet filled
574 pos
= strstr(pos
,"src="); // Is source present on this line
577 if (pos
[4] != '"' && pos
[4] != '\'') {
578 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Unknown delimiter %c in source line %s\n", pos
[4], line
);
582 s_end
=strchr(s_start
,pos
[4]);
584 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Error parsing this source line %s\n",line
);
587 if (s_end
-s_start
> 511) {
588 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Cannot store such a large source %s\n",line
);
591 strncpy(source
,s_start
,s_end
-s_start
);
592 source
[(s_end
-s_start
)]='\0'; // Null terminate
593 entry
= play_tree_new();
594 play_tree_add_file(entry
,source
);
595 if(!list
) //Insert new entry
598 play_tree_append_entry(last_entry
,entry
);
604 } while((src_line
= play_tree_parser_get_line(p
)) != NULL
);
608 if(!list
) return NULL
; // Nothing found
610 entry
= play_tree_new();
611 play_tree_set_child(entry
,list
);
616 embedded_playlist_parse(struct MPOpts
*opts
, char *line
) {
617 int f
=DEMUXER_TYPE_PLAYLIST
;
619 play_tree_parser_t
* ptp
;
622 // Get stream opened to link
623 stream
=open_stream(line
, opts
, &f
);
625 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"Can't open playlist %s\n",line
);
630 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Adding playlist %s to element entryref\n",line
);
632 ptp
= play_tree_parser_new(stream
, opts
, 1);
633 entry
= play_tree_parser_get_play_tree(ptp
, 1);
634 play_tree_parser_free(ptp
);
641 parse_textplain(play_tree_parser_t
* p
) {
645 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
647 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying plaintext playlist...\n");
648 play_tree_parser_stop_keeping(p
);
650 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
652 if(line
[0] == '\0' || line
[0] == '#' || (line
[0] == '/' && line
[1] == '/'))
655 //Special check for embedded smil or ram reference in file
657 if (strlen(line
) > 5)
658 for(c
= line
; c
[0]; c
++ )
659 if ( ((c
[0] == '.') && //start with . and next have smil with optional ? or &
660 (tolower(c
[1]) == 's') && (tolower(c
[2])== 'm') &&
661 (tolower(c
[3]) == 'i') && (tolower(c
[4]) == 'l') &&
662 (!c
[5] || c
[5] == '?' || c
[5] == '&')) || // or
663 ((c
[0] == '.') && // start with . and next have smi or ram with optional ? or &
664 ( ((tolower(c
[1]) == 's') && (tolower(c
[2])== 'm') && (tolower(c
[3]) == 'i')) ||
665 ((tolower(c
[1]) == 'r') && (tolower(c
[2])== 'a') && (tolower(c
[3]) == 'm')) )
666 && (!c
[4] || c
[4] == '?' || c
[4] == '&')) ){
667 entry
=embedded_playlist_parse(p
->opts
, line
);
672 if (!embedded
) { //regular file link
673 entry
= play_tree_new();
674 play_tree_add_file(entry
,line
);
681 play_tree_append_entry(last_entry
,entry
);
686 if(!list
) return NULL
;
687 entry
= play_tree_new();
688 play_tree_set_child(entry
,list
);
693 * \brief decode the base64 used in nsc files
694 * \param in input string, 0-terminated
695 * \param buf output buffer, must point to memory suitable for realloc,
696 * will be NULL on failure.
697 * \return decoded length in bytes
699 static int decode_nsc_base64(char *in
, char **buf
) {
701 if (in
[0] != '0' || in
[1] != '2')
703 in
+= 2; // skip prefix
704 if (strlen(in
) < 16) // error out if nothing to decode
706 in
+= 12; // skip encoded string length
708 *buf
= realloc(*buf
, n
* 3);
709 for (i
= 0; i
< n
; i
++) {
711 for (j
= 0; j
< 4; j
++) {
712 c
[j
] = in
[4 * i
+ j
];
713 if (c
[j
] >= '0' && c
[j
] <= '9') c
[j
] += 0 - '0';
714 else if (c
[j
] >= 'A' && c
[j
] <= 'Z') c
[j
] += 10 - 'A';
715 else if (c
[j
] >= 'a' && c
[j
] <= 'z') c
[j
] += 36 - 'a';
716 else if (c
[j
] == '{') c
[j
] = 62;
717 else if (c
[j
] == '}') c
[j
] = 63;
719 mp_msg(MSGT_PLAYTREE
, MSGL_ERR
, "Invalid character %c (0x%02"PRIx8
")\n", c
[j
], c
[j
]);
723 (*buf
)[3 * i
] = (c
[0] << 2) | (c
[1] >> 4);
724 (*buf
)[3 * i
+ 1] = (c
[1] << 4) | (c
[2] >> 2);
725 (*buf
)[3 * i
+ 2] = (c
[2] << 6) | c
[3];
735 * \brief "converts" utf16 to ascii by just discarding every second byte
736 * \param buf buffer to convert
737 * \param len lenght of buffer, must be > 0
739 static void utf16_to_ascii(char *buf
, int len
) {
741 if (len
<= 0) return;
742 for (i
= 0; i
< len
/ 2; i
++)
744 buf
[i
] = 0; // just in case
747 static play_tree_t
*parse_nsc(play_tree_parser_t
* p
) {
748 char *line
, *addr
= NULL
, *url
, *unicast_url
= NULL
;
750 play_tree_t
*entry
= NULL
;
752 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying nsc playlist...\n");
753 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
755 if(!line
[0]) // Ignore empties
757 if (strncasecmp(line
,"[Address]", 9) == 0)
758 break; // nsc header found
762 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected nsc playlist format\n");
763 play_tree_parser_stop_keeping(p
);
764 while ((line
= play_tree_parser_get_line(p
)) != NULL
) {
768 if (strncasecmp(line
, "Unicast URL=", 12) == 0) {
769 int len
= decode_nsc_base64(&line
[12], &unicast_url
);
771 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "[nsc] Unsupported Unicast URL encoding\n");
773 utf16_to_ascii(unicast_url
, len
);
774 } else if (strncasecmp(line
, "IP Address=", 11) == 0) {
775 int len
= decode_nsc_base64(&line
[11], &addr
);
777 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "[nsc] Unsupported IP Address encoding\n");
779 utf16_to_ascii(addr
, len
);
780 } else if (strncasecmp(line
, "IP Port=", 8) == 0) {
781 port
= strtol(&line
[8], NULL
, 0);
786 url
= strdup(unicast_url
);
787 else if (addr
&& port
) {
788 url
= malloc(strlen(addr
) + 7 + 20 + 1);
789 sprintf(url
, "http://%s:%i", addr
, port
);
793 entry
= play_tree_new();
794 play_tree_add_file(entry
, url
);
803 parse_playtree(stream_t
*stream
, struct MPOpts
*opts
, int forced
) {
804 play_tree_parser_t
* p
;
807 assert(stream
!= NULL
);
809 p
= play_tree_parser_new(stream
, opts
, 0);
813 ret
= play_tree_parser_get_play_tree(p
, forced
);
814 play_tree_parser_free(p
);
820 play_tree_add_basepath(play_tree_t
* pt
, char* bp
) {
821 int i
,bl
= strlen(bp
),fl
;
825 for(i
= pt
->child
; i
!= NULL
; i
= i
->next
)
826 play_tree_add_basepath(i
,bp
);
833 for(i
= 0 ; pt
->files
[i
] != NULL
; i
++) {
834 fl
= strlen(pt
->files
[i
]);
835 // if we find a full unix path, url:// or X:\ at the beginning,
837 if(fl
<= 0 || strstr(pt
->files
[i
],"://") || (strstr(pt
->files
[i
],":\\") == pt
->files
[i
] + 1) || (pt
->files
[i
][0] == '/') )
839 // if the path begins with \ then prepend drive letter to it.
840 if (pt
->files
[i
][0] == '\\') {
841 if (pt
->files
[i
][1] == '\\')
843 pt
->files
[i
] = realloc(pt
->files
[i
], 2 + fl
+ 1);
844 memmove(pt
->files
[i
] + 2,pt
->files
[i
],fl
+1);
845 memcpy(pt
->files
[i
],bp
,2);
848 pt
->files
[i
] = realloc(pt
->files
[i
], bl
+ fl
+ 1);
849 memmove(pt
->files
[i
] + bl
,pt
->files
[i
],fl
+1);
850 memcpy(pt
->files
[i
],bp
,bl
);
854 // Wrapper for play_tree_add_basepath (add base path from file)
855 void play_tree_add_bpf(play_tree_t
*pt
, struct bstr filename
)
861 file
= bstrdup0(NULL
, filename
);
864 ls
= strrchr(file
,'/');
865 if(!ls
) ls
= strrchr(file
,'\\');
868 play_tree_add_basepath(pt
,file
);
876 parse_playlist_file(struct MPOpts
*opts
, struct bstr file
) {
879 int f
=DEMUXER_TYPE_PLAYLIST
;
881 char *file0
= bstrdup0(NULL
, file
);
882 stream
= open_stream(file0
, opts
, &f
);
886 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,
887 "Error while opening playlist file %.*s: %s\n",
888 BSTR_P(file
), strerror(errno
));
892 mp_msg(MSGT_PLAYTREE
, MSGL_V
,
893 "Parsing playlist file %.*s...\n", BSTR_P(file
));
895 ret
= parse_playtree(stream
, opts
, 1);
898 play_tree_add_bpf(ret
, file
);
906 play_tree_parser_new(stream_t
* stream
, struct MPOpts
*opts
, int deep
) {
907 play_tree_parser_t
* p
;
909 p
= calloc(1,sizeof(play_tree_parser_t
));
922 play_tree_parser_free(play_tree_parser_t
* p
) {
932 play_tree_parser_get_play_tree(play_tree_parser_t
* p
, int forced
) {
933 play_tree_t
* tree
= NULL
;
937 while(play_tree_parser_get_line(p
) != NULL
) {
938 play_tree_parser_reset(p
);
942 play_tree_parser_reset(p
);
946 play_tree_parser_reset(p
);
950 play_tree_parser_reset(p
);
952 tree
= parse_ref_ini(p
);
954 play_tree_parser_reset(p
);
956 tree
= parse_smil(p
);
958 play_tree_parser_reset(p
);
962 play_tree_parser_reset(p
);
964 // Here come the others formats ( textplain must stay the last one )
967 tree
= parse_textplain(p
);
974 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Playlist successfully parsed\n");
976 mp_msg(MSGT_PLAYTREE
,((forced
==1)?MSGL_ERR
:MSGL_V
),"Error while parsing playlist\n");
979 tree
= play_tree_cleanup(tree
);
981 if(!tree
) mp_msg(MSGT_PLAYTREE
,((forced
==1)?MSGL_WARN
:MSGL_V
),"Warning: empty playlist\n");