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>
34 #include "asxparser.h"
37 #include "playtreeparser.h"
38 #include "stream/stream.h"
39 #include "libmpdemux/demuxer.h"
45 #define WHITES " \n\r\t"
53 for(i
= str
; i
[0] != '\0' && strchr(WHITES
,i
[0]) != NULL
; i
++)
56 memmove(str
,i
,strlen(i
) + 1);
57 for(i
= str
+ strlen(str
) - 1 ; strchr(WHITES
,i
[0]) != NULL
; i
--)
65 play_tree_parser_get_line(play_tree_parser_t
* p
) {
69 if(p
->buffer
== NULL
) {
70 p
->buffer
= malloc(BUF_STEP
);
71 p
->buffer_size
= BUF_STEP
;
76 if(p
->stream
->eof
&& (p
->buffer_end
== 0 || p
->iter
[0] == '\0'))
79 assert(p
->buffer_end
< p
->buffer_size
);
80 assert(!p
->buffer
[p
->buffer_end
]);
85 r
= p
->iter
- p
->buffer
;
86 end
= p
->buffer
+ p
->buffer_end
;
87 if (p
->buffer_size
> INT_MAX
- BUF_STEP
)
89 tmp
= realloc(p
->buffer
, p
->buffer_size
+ BUF_STEP
);
93 p
->iter
= p
->buffer
+ r
;
94 p
->buffer_size
+= BUF_STEP
;
98 if(p
->buffer_size
- p
->buffer_end
> 1 && ! p
->stream
->eof
) {
99 r
= stream_read(p
->stream
,p
->buffer
+ p
->buffer_end
,p
->buffer_size
- p
->buffer_end
- 1);
102 assert(p
->buffer_end
< p
->buffer_size
);
103 p
->buffer
[p
->buffer_end
] = '\0';
104 while(strlen(p
->buffer
+ p
->buffer_end
- r
) != r
)
105 p
->buffer
[p
->buffer_end
- r
+ strlen(p
->buffer
+ p
->buffer_end
- r
)] = '\n';
107 assert(!p
->buffer
[p
->buffer_end
]);
110 end
= strchr(p
->iter
,'\n');
113 end
= p
->buffer
+ p
->buffer_end
;
122 line_end
= (end
> p
->iter
&& *(end
-1) == '\r') ? end
-1 : end
;
123 if(line_end
- p
->iter
>= 0)
124 p
->line
= realloc(p
->line
, line_end
- p
->iter
+ 1);
127 if(line_end
- p
->iter
> 0)
128 strncpy(p
->line
,p
->iter
,line_end
- p
->iter
);
129 p
->line
[line_end
- p
->iter
] = '\0';
135 p
->buffer_end
-= end
-p
->iter
;
136 memmove(p
->buffer
,end
,p
->buffer_end
);
139 p
->buffer
[p
->buffer_end
] = '\0';
148 play_tree_parser_reset(play_tree_parser_t
* p
) {
153 play_tree_parser_stop_keeping(play_tree_parser_t
* p
) {
155 if(p
->iter
&& p
->iter
!= p
->buffer
) {
156 p
->buffer_end
-= p
->iter
-p
->buffer
;
158 memmove(p
->buffer
,p
->iter
,p
->buffer_end
);
159 p
->buffer
[p
->buffer_end
] = 0;
166 parse_asx(play_tree_parser_t
* p
) {
167 int comments
= 0,get_line
= 1;
170 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying asx...\n");
174 line
= play_tree_parser_get_line(p
);
183 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"First char isn't '<' but '%c'\n",line
[0]);
184 mp_msg(MSGT_PLAYTREE
,MSGL_DBG3
,"Buffer = [%s]\n",p
->buffer
);
186 } else if(strncmp(line
,"<!--",4) == 0) { // Comments
189 if(line
[0] != '\0' && strlen(line
) > 0)
191 } else if(strncasecmp(line
,"<ASX",4) == 0) // We got an asx element
193 else // We don't get an asx
197 c
= strchr(line
,'-');
199 if (strncmp(c
,"--!>",4) == 0) { // End of comments
202 if(line
[0] != '\0') // There is some more data on this line : keep it
206 line
= c
+1; // Jump the -
207 if(line
[0] != '\0') // Some more data
212 } else // No - on this line (or rest of line) : get next one
217 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected asx format\n");
219 // We have an asx : load it in memory and parse
221 while((line
= play_tree_parser_get_line(p
)) != NULL
)
224 mp_msg(MSGT_PLAYTREE
,MSGL_DBG3
,"Parsing asx file: [%s]\n",p
->buffer
);
225 return asx_parser_build_tree(p
->mconfig
, p
->buffer
,p
->deep
);
229 pls_entry_get_value(char* line
) {
232 i
= strchr(line
,'=');
233 if(!i
|| i
[1] == '\0')
239 typedef struct pls_entry
{
246 pls_read_entry(char* line
,pls_entry_t
** _e
,int* _max_entry
,char** val
) {
247 int num
,max_entry
= (*_max_entry
);
248 pls_entry_t
* e
= (*_e
);
249 int limit
= INT_MAX
/ sizeof(*e
);
252 v
= pls_entry_get_value(line
);
254 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
259 if(num
<= 0 || num
> limit
) {
260 if (max_entry
>= limit
) {
261 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "Too many index entries\n");
265 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"No or invalid entry index in entry %s\nAssuming %d\n",line
,num
);
267 if(num
> max_entry
) {
268 e
= realloc(e
, num
* sizeof(pls_entry_t
));
271 memset(&e
[max_entry
],0,(num
-max_entry
)*sizeof(pls_entry_t
));
275 (*_max_entry
) = max_entry
;
283 parse_pls(play_tree_parser_t
* p
) {
285 pls_entry_t
* entries
= NULL
;
286 int n_entries
= 0,max_entry
=0,num
;
287 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
289 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying Winamp playlist...\n");
290 while((line
= play_tree_parser_get_line(p
))) {
297 if(strcasecmp(line
,"[playlist]"))
299 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected Winamp playlist format\n");
300 play_tree_parser_stop_keeping(p
);
301 line
= play_tree_parser_get_line(p
);
305 if(strncasecmp(line
,"NumberOfEntries",15) == 0) {
306 v
= pls_entry_get_value(line
);
309 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Invalid number of entries: very funny!!!\n");
311 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Playlist claims to have %d entries. Let's see.\n",n_entries
);
312 line
= play_tree_parser_get_line(p
);
317 if(line
[0] == '\0') {
318 line
= play_tree_parser_get_line(p
);
321 if(strncasecmp(line
,"File",4) == 0) {
322 num
= pls_read_entry(line
+4,&entries
,&max_entry
,&v
);
324 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
326 entries
[num
-1].file
= strdup(v
);
327 } else if(strncasecmp(line
,"Title",5) == 0) {
328 num
= pls_read_entry(line
+5,&entries
,&max_entry
,&v
);
330 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
332 entries
[num
-1].title
= strdup(v
);
333 } else if(strncasecmp(line
,"Length",6) == 0) {
334 num
= pls_read_entry(line
+6,&entries
,&max_entry
,&v
);
336 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
338 entries
[num
-1].length
= strdup(v
);
340 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"Unknown entry type %s\n",line
);
341 line
= play_tree_parser_get_line(p
);
344 for(num
= 0; num
< max_entry
; num
++) {
345 if(entries
[num
].file
== NULL
)
346 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"Entry %d don't have a file !!!!\n",num
+1);
348 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Adding entry %s\n",entries
[num
].file
);
349 entry
= play_tree_new();
350 play_tree_add_file(entry
,entries
[num
].file
);
351 free(entries
[num
].file
);
353 play_tree_append_entry(last_entry
,entry
);
358 // When we have info in playtree we add these info
359 free(entries
[num
].title
);
360 free(entries
[num
].length
);
368 entry
= play_tree_new();
369 play_tree_set_child(entry
,list
);
374 Reference Ini-Format: Each entry is assumed a reference
377 parse_ref_ini(play_tree_parser_t
* p
) {
379 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
381 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying reference-ini playlist...\n");
382 if (!(line
= play_tree_parser_get_line(p
)))
385 if(strcasecmp(line
,"[Reference]"))
387 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected reference-ini playlist format\n");
388 play_tree_parser_stop_keeping(p
);
389 line
= play_tree_parser_get_line(p
);
394 if(strncasecmp(line
,"Ref",3) == 0) {
395 v
= pls_entry_get_value(line
+3);
397 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"No value in entry %s\n",line
);
400 mp_msg(MSGT_PLAYTREE
,MSGL_DBG2
,"Adding entry %s\n",v
);
401 entry
= play_tree_new();
402 play_tree_add_file(entry
,v
);
404 play_tree_append_entry(last_entry
,entry
);
410 line
= play_tree_parser_get_line(p
);
413 if(!list
) return NULL
;
414 entry
= play_tree_new();
415 play_tree_set_child(entry
,list
);
420 parse_m3u(play_tree_parser_t
* p
) {
422 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
424 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying extended m3u playlist...\n");
425 if (!(line
= play_tree_parser_get_line(p
)))
428 if(strcasecmp(line
,"#EXTM3U"))
430 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected extended m3u playlist format\n");
431 play_tree_parser_stop_keeping(p
);
433 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
437 /* EXTM3U files contain such lines:
438 * #EXTINF:<seconds>, <title>
439 * followed by a line with the filename
440 * for now we have no place to put that
441 * so we just skip that extra-info ::atmos
444 #if 0 /* code functional */
445 if(strncasecmp(line
,"#EXTINF:",8) == 0) {
446 mp_msg(MSGT_PLAYTREE
,MSGL_INFO
,"[M3U] Duration: %dsec Title: %s\n",
447 strtol(line
+8,&line
,10), line
+2);
452 entry
= play_tree_new();
453 play_tree_add_file(entry
,line
);
457 play_tree_append_entry(last_entry
,entry
);
461 if(!list
) return NULL
;
462 entry
= play_tree_new();
463 play_tree_set_child(entry
,list
);
468 parse_smil(play_tree_parser_t
* p
) {
470 char* line
,source
[512],*pos
,*s_start
,*s_end
,*src_line
;
471 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
473 unsigned int npkt
, ttlpkt
;
475 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying smil playlist...\n");
478 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
480 if(line
[0] == '\0') // Ignore empties
482 if (strncasecmp(line
,"<?xml",5)==0) // smil in xml
484 if (strncasecmp(line
,"<!DOCTYPE smil",13)==0) // smil in xml
486 if (strncasecmp(line
,"<smil",5)==0 || strncasecmp(line
,"<?wpl",5)==0 ||
487 strncasecmp(line
,"(smil-document",14)==0)
488 break; // smil header found
490 return NULL
; //line not smil exit
493 if (!line
) return NULL
;
494 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected smil playlist format\n");
495 play_tree_parser_stop_keeping(p
);
497 if (strncasecmp(line
,"(smil-document",14)==0) {
498 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Special smil-over-realrtsp playlist header\n");
500 if (sscanf(line
, "(smil-document (ver 1.0)(npkt %u)(ttlpkt %u", &npkt
, &ttlpkt
) != 2) {
501 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: header parsing failure, assuming single packet.\n");
504 if (ttlpkt
== 0 || npkt
> ttlpkt
) {
505 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: bad packet counters (npkk = %u, ttlpkt = %u), assuming single packet.\n",
511 //Get entries from smil
518 /* If we're parsing smil over realrtsp and this is not the last packet and
519 * this is the last line in the packet (terminating with ") ) we must get
520 * the next line, strip the header, and concatenate it to the current line.
522 if (is_rmsmil
&& npkt
!= ttlpkt
&& strstr(src_line
,"\")")) {
525 line
= strdup(src_line
);
526 if(!(src_line
= play_tree_parser_get_line(p
))) {
527 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: can't get line from packet %u/%u.\n", npkt
, ttlpkt
);
531 // Skip header, packet starts after "
532 if(!(payload
= strchr(src_line
,'\"'))) {
533 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"smil-over-realrtsp: can't find start of packet, using complete line.\n");
537 // Skip ") at the end of the last line from the current packet
538 line
[strlen(line
)-2] = 0;
539 line
= realloc(line
, strlen(line
)+strlen(payload
)+1);
540 strcat (line
, payload
);
543 line
= strdup(src_line
);
544 /* Unescape \" to " for smil-over-rtsp */
545 if (is_rmsmil
&& line
[0] != '\0') {
548 for (i
= 0; i
< strlen(line
); i
++)
549 if (line
[i
] == '\\' && line
[i
+1] == '"')
550 for (j
= i
; line
[j
]; j
++)
555 if (!entrymode
) { // all entries filled so far
556 while ((pos
=strchr(pos
, '<'))) {
557 if (strncasecmp(pos
,"<video",6)==0 || strncasecmp(pos
,"<audio",6)==0 || strncasecmp(pos
,"<media",6)==0) {
559 break; // Got a valid tag, exit '<' search loop
564 if (entrymode
) { //Entry found but not yet filled
565 pos
= strstr(pos
,"src="); // Is source present on this line
568 if (pos
[4] != '"' && pos
[4] != '\'') {
569 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Unknown delimiter %c in source line %s\n", pos
[4], line
);
573 s_end
=strchr(s_start
,pos
[4]);
575 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Error parsing this source line %s\n",line
);
578 if (s_end
-s_start
> 511) {
579 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Cannot store such a large source %s\n",line
);
582 strncpy(source
,s_start
,s_end
-s_start
);
583 source
[(s_end
-s_start
)]='\0'; // Null terminate
584 entry
= play_tree_new();
585 play_tree_add_file(entry
,source
);
586 if(!list
) //Insert new entry
589 play_tree_append_entry(last_entry
,entry
);
595 } while((src_line
= play_tree_parser_get_line(p
)) != NULL
);
599 if(!list
) return NULL
; // Nothing found
601 entry
= play_tree_new();
602 play_tree_set_child(entry
,list
);
607 embedded_playlist_parse(struct m_config
*mconfig
, char *line
) {
608 int f
=DEMUXER_TYPE_PLAYLIST
;
610 play_tree_parser_t
* ptp
;
613 // Get stream opened to link
614 stream
=open_stream(line
,0,&f
);
616 mp_msg(MSGT_PLAYTREE
,MSGL_WARN
,"Can't open playlist %s\n",line
);
621 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Adding playlist %s to element entryref\n",line
);
623 ptp
= play_tree_parser_new(stream
, mconfig
, 1);
624 entry
= play_tree_parser_get_play_tree(ptp
, 1);
625 play_tree_parser_free(ptp
);
632 parse_textplain(play_tree_parser_t
* p
) {
636 play_tree_t
*list
= NULL
, *entry
= NULL
, *last_entry
= NULL
;
638 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying plaintext playlist...\n");
639 play_tree_parser_stop_keeping(p
);
641 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
643 if(line
[0] == '\0' || line
[0] == '#' || (line
[0] == '/' && line
[1] == '/'))
646 //Special check for embedded smil or ram reference in file
648 if (strlen(line
) > 5)
649 for(c
= line
; c
[0]; c
++ )
650 if ( ((c
[0] == '.') && //start with . and next have smil with optional ? or &
651 (tolower(c
[1]) == 's') && (tolower(c
[2])== 'm') &&
652 (tolower(c
[3]) == 'i') && (tolower(c
[4]) == 'l') &&
653 (!c
[5] || c
[5] == '?' || c
[5] == '&')) || // or
654 ((c
[0] == '.') && // start with . and next have smi or ram with optional ? or &
655 ( ((tolower(c
[1]) == 's') && (tolower(c
[2])== 'm') && (tolower(c
[3]) == 'i')) ||
656 ((tolower(c
[1]) == 'r') && (tolower(c
[2])== 'a') && (tolower(c
[3]) == 'm')) )
657 && (!c
[4] || c
[4] == '?' || c
[4] == '&')) ){
658 entry
=embedded_playlist_parse(p
->mconfig
, line
);
663 if (!embedded
) { //regular file link
664 entry
= play_tree_new();
665 play_tree_add_file(entry
,line
);
672 play_tree_append_entry(last_entry
,entry
);
677 if(!list
) return NULL
;
678 entry
= play_tree_new();
679 play_tree_set_child(entry
,list
);
684 * \brief decode the base64 used in nsc files
685 * \param in input string, 0-terminated
686 * \param buf output buffer, must point to memory suitable for realloc,
687 * will be NULL on failure.
688 * \return decoded length in bytes
690 static int decode_nsc_base64(char *in
, char **buf
) {
692 if (in
[0] != '0' || in
[1] != '2')
694 in
+= 2; // skip prefix
695 if (strlen(in
) < 16) // error out if nothing to decode
697 in
+= 12; // skip encoded string length
699 *buf
= realloc(*buf
, n
* 3);
700 for (i
= 0; i
< n
; i
++) {
702 for (j
= 0; j
< 4; j
++) {
703 c
[j
] = in
[4 * i
+ j
];
704 if (c
[j
] >= '0' && c
[j
] <= '9') c
[j
] += 0 - '0';
705 else if (c
[j
] >= 'A' && c
[j
] <= 'Z') c
[j
] += 10 - 'A';
706 else if (c
[j
] >= 'a' && c
[j
] <= 'z') c
[j
] += 36 - 'a';
707 else if (c
[j
] == '{') c
[j
] = 62;
708 else if (c
[j
] == '}') c
[j
] = 63;
710 mp_msg(MSGT_PLAYTREE
, MSGL_ERR
, "Invalid character %c (0x%02"PRIx8
")\n", c
[j
], c
[j
]);
714 (*buf
)[3 * i
] = (c
[0] << 2) | (c
[1] >> 4);
715 (*buf
)[3 * i
+ 1] = (c
[1] << 4) | (c
[2] >> 2);
716 (*buf
)[3 * i
+ 2] = (c
[2] << 6) | c
[3];
726 * \brief "converts" utf16 to ascii by just discarding every second byte
727 * \param buf buffer to convert
728 * \param len lenght of buffer, must be > 0
730 static void utf16_to_ascii(char *buf
, int len
) {
732 if (len
<= 0) return;
733 for (i
= 0; i
< len
/ 2; i
++)
735 buf
[i
] = 0; // just in case
738 static play_tree_t
*parse_nsc(play_tree_parser_t
* p
) {
739 char *line
, *addr
= NULL
, *url
, *unicast_url
= NULL
;
741 play_tree_t
*entry
= NULL
;
743 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Trying nsc playlist...\n");
744 while((line
= play_tree_parser_get_line(p
)) != NULL
) {
746 if(!line
[0]) // Ignore empties
748 if (strncasecmp(line
,"[Address]", 9) == 0)
749 break; // nsc header found
753 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Detected nsc playlist format\n");
754 play_tree_parser_stop_keeping(p
);
755 while ((line
= play_tree_parser_get_line(p
)) != NULL
) {
759 if (strncasecmp(line
, "Unicast URL=", 12) == 0) {
760 int len
= decode_nsc_base64(&line
[12], &unicast_url
);
762 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "[nsc] Unsupported Unicast URL encoding\n");
764 utf16_to_ascii(unicast_url
, len
);
765 } else if (strncasecmp(line
, "IP Address=", 11) == 0) {
766 int len
= decode_nsc_base64(&line
[11], &addr
);
768 mp_msg(MSGT_PLAYTREE
, MSGL_WARN
, "[nsc] Unsupported IP Address encoding\n");
770 utf16_to_ascii(addr
, len
);
771 } else if (strncasecmp(line
, "IP Port=", 8) == 0) {
772 port
= strtol(&line
[8], NULL
, 0);
777 url
= strdup(unicast_url
);
778 else if (addr
&& port
) {
779 url
= malloc(strlen(addr
) + 7 + 20 + 1);
780 sprintf(url
, "http://%s:%i", addr
, port
);
784 entry
= play_tree_new();
785 play_tree_add_file(entry
, url
);
794 parse_playtree(stream_t
*stream
, struct m_config
*mconfig
, int forced
) {
795 play_tree_parser_t
* p
;
799 assert(stream
!= NULL
);
802 p
= play_tree_parser_new(stream
, mconfig
, 0);
806 ret
= play_tree_parser_get_play_tree(p
, forced
);
807 play_tree_parser_free(p
);
813 play_tree_add_basepath(play_tree_t
* pt
, char* bp
) {
814 int i
,bl
= strlen(bp
),fl
;
818 for(i
= pt
->child
; i
!= NULL
; i
= i
->next
)
819 play_tree_add_basepath(i
,bp
);
826 for(i
= 0 ; pt
->files
[i
] != NULL
; i
++) {
827 fl
= strlen(pt
->files
[i
]);
828 // if we find a full unix path, url:// or X:\ at the beginning,
830 if(fl
<= 0 || strstr(pt
->files
[i
],"://") || (strstr(pt
->files
[i
],":\\") == pt
->files
[i
] + 1) || (pt
->files
[i
][0] == '/') )
832 // if the path begins with \ then prepend drive letter to it.
833 if (pt
->files
[i
][0] == '\\') {
834 if (pt
->files
[i
][1] == '\\')
836 pt
->files
[i
] = realloc(pt
->files
[i
], 2 + fl
+ 1);
837 memmove(pt
->files
[i
] + 2,pt
->files
[i
],fl
+1);
838 memcpy(pt
->files
[i
],bp
,2);
841 pt
->files
[i
] = realloc(pt
->files
[i
], bl
+ fl
+ 1);
842 memmove(pt
->files
[i
] + bl
,pt
->files
[i
],fl
+1);
843 memcpy(pt
->files
[i
],bp
,bl
);
847 // Wrapper for play_tree_add_basepath (add base path from file)
848 void play_tree_add_bpf(play_tree_t
* pt
, char* filename
)
854 file
= strdup(filename
);
857 ls
= strrchr(file
,'/');
858 if(!ls
) ls
= strrchr(file
,'\\');
861 play_tree_add_basepath(pt
,file
);
869 parse_playlist_file(struct m_config
*mconfig
, char* file
) {
872 int f
=DEMUXER_TYPE_PLAYLIST
;
874 stream
= open_stream(file
,0,&f
);
877 mp_msg(MSGT_PLAYTREE
,MSGL_ERR
,"Error while opening playlist file %s: %s\n",file
,strerror(errno
));
881 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Parsing playlist file %s...\n",file
);
883 ret
= parse_playtree(stream
, mconfig
, 1);
886 play_tree_add_bpf(ret
, file
);
894 play_tree_parser_new(stream_t
* stream
, struct m_config
*mconfig
, int deep
) {
895 play_tree_parser_t
* p
;
897 p
= calloc(1,sizeof(play_tree_parser_t
));
901 p
->mconfig
= mconfig
;
910 play_tree_parser_free(play_tree_parser_t
* p
) {
922 play_tree_parser_get_play_tree(play_tree_parser_t
* p
, int forced
) {
923 play_tree_t
* tree
= NULL
;
930 while(play_tree_parser_get_line(p
) != NULL
) {
931 play_tree_parser_reset(p
);
935 play_tree_parser_reset(p
);
939 play_tree_parser_reset(p
);
943 play_tree_parser_reset(p
);
945 tree
= parse_ref_ini(p
);
947 play_tree_parser_reset(p
);
949 tree
= parse_smil(p
);
951 play_tree_parser_reset(p
);
955 play_tree_parser_reset(p
);
957 // Here come the others formats ( textplain must stay the last one )
960 tree
= parse_textplain(p
);
967 mp_msg(MSGT_PLAYTREE
,MSGL_V
,"Playlist successfully parsed\n");
969 mp_msg(MSGT_PLAYTREE
,((forced
==1)?MSGL_ERR
:MSGL_V
),"Error while parsing playlist\n");
972 tree
= play_tree_cleanup(tree
);
974 if(!tree
) mp_msg(MSGT_PLAYTREE
,((forced
==1)?MSGL_WARN
:MSGL_V
),"Warning: empty playlist\n");