annotate playtreeparser.c @ 33428:043d9e61e043

Ensure 0-termination even if line does not start with FILE " Part of patch by Ivan Kalvachev [ikalvachev gmail com].
author reimar
date Sun, 29 May 2011 11:47:18 +0000
parents bfe41b532fe9
children 5a3aa408c9ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
1 /*
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
3 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
8 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
13 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29263
diff changeset
17 */
18265
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 16871
diff changeset
18
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 16871
diff changeset
19 /// \file
1a14fde7680d Doxygen Attack! - Chapter 3
albeu
parents: 16871
diff changeset
20 /// \ingroup PlaytreeParser
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
21
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
22 #include "config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
23 #include <stdlib.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
24 #include <stdio.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
25 #include <string.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
26 #include <assert.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
27 #include <errno.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
28 #include <sys/types.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
29 #include <sys/stat.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
30 #include <fcntl.h>
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
31 #include <unistd.h>
12300
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
32 #include <ctype.h>
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
33 #include <limits.h>
30632
dad8e0eb182a Add asx_parser_build_tree() to asxparser.h instead of forward declaring it.
diego
parents: 30429
diff changeset
34 #include "asxparser.h"
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
35 #include "m_config.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
36 #include "playtree.h"
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
37 #include "playtreeparser.h"
19271
64d82a45a05d introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents: 18928
diff changeset
38 #include "stream/stream.h"
12223
e7c8200ffdc5 Respect -playlist for asx streams
rtognimp
parents: 12097
diff changeset
39 #include "libmpdemux/demuxer.h"
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
40 #include "mp_msg.h"
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
41
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
42
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
43 #define BUF_STEP 1024
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
44
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
45 #define WHITES " \n\r\t"
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
46
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
47 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
48 strstrip(char* str) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
49 char* i;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
50
8907
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
51 if (str==NULL)
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
52 return;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
53 for(i = str ; i[0] != '\0' && strchr(WHITES,i[0]) != NULL; i++)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
54 /* NOTHING */;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
55 if(i[0] != '\0') {
8907
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
56 memmove(str,i,strlen(i) + 1);
e82149e697a7 bunkus: Another nice off-by-one :)
mosu
parents: 8897
diff changeset
57 for(i = str + strlen(str) - 1 ; strchr(WHITES,i[0]) != NULL; i--)
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
58 /* NOTHING */;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
59 i[1] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
60 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
61 str[0] = '\0';
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
62 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
63
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
64 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
65 play_tree_parser_get_line(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
66 char *end,*line_end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
67 int r,resize = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
68
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
69 if(p->buffer == NULL) {
18869
682a16136d6c rm unnecesary void* casts - part 1
reynaldo
parents: 18265
diff changeset
70 p->buffer = malloc(BUF_STEP);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
71 p->buffer_size = BUF_STEP;
28183
b197740bf718 Add zero termination missing in two cases.
reimar
parents: 28182
diff changeset
72 p->buffer[0] = 0;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
73 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
74 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
75
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
76 if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0'))
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
77 return NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
78
28182
26ab2d01157f Add asserts to detect when assumptions for play_tree_parser_get_line
reimar
parents: 25141
diff changeset
79 assert(p->buffer_end < p->buffer_size);
26ab2d01157f Add asserts to detect when assumptions for play_tree_parser_get_line
reimar
parents: 25141
diff changeset
80 assert(!p->buffer[p->buffer_end]);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
81 while(1) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
82
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
83 if(resize) {
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
84 char *tmp;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
85 r = p->iter - p->buffer;
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
86 end = p->buffer + p->buffer_end;
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
87 if (p->buffer_size > INT_MAX - BUF_STEP)
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
88 break;
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
89 tmp = realloc(p->buffer, p->buffer_size + BUF_STEP);
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
90 if (!tmp)
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
91 break;
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
92 p->buffer = tmp;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
93 p->iter = p->buffer + r;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
94 p->buffer_size += BUF_STEP;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
95 resize = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
96 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
97
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
98 if(p->buffer_size - p->buffer_end > 1 && ! p->stream->eof) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
99 r = stream_read(p->stream,p->buffer + p->buffer_end,p->buffer_size - p->buffer_end - 1);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
100 if(r > 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
101 p->buffer_end += r;
28182
26ab2d01157f Add asserts to detect when assumptions for play_tree_parser_get_line
reimar
parents: 25141
diff changeset
102 assert(p->buffer_end < p->buffer_size);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
103 p->buffer[p->buffer_end] = '\0';
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
104 while(strlen(p->buffer + p->buffer_end - r) != r)
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
105 p->buffer[p->buffer_end - r + strlen(p->buffer + p->buffer_end - r)] = '\n';
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
106 }
28182
26ab2d01157f Add asserts to detect when assumptions for play_tree_parser_get_line
reimar
parents: 25141
diff changeset
107 assert(!p->buffer[p->buffer_end]);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
108 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
109
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
110 end = strchr(p->iter,'\n');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
111 if(!end) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
112 if(p->stream->eof) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
113 end = p->buffer + p->buffer_end;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
114 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
115 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
116 resize = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
117 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
118 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
119 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
120 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
121
25141
fba022abe464 100l in play_tree_parser_get_line, check that there actually is
reimar
parents: 24962
diff changeset
122 line_end = (end > p->iter && *(end-1) == '\r') ? end-1 : end;
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
123 if(line_end - p->iter >= 0)
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30632
diff changeset
124 p->line = realloc(p->line, line_end - p->iter + 1);
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
125 else
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
126 return NULL;
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
127 if(line_end - p->iter > 0)
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
128 strncpy(p->line,p->iter,line_end - p->iter);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
129 p->line[line_end - p->iter] = '\0';
5802
35f19046f809 Portability fix with realloc
albeu
parents: 5788
diff changeset
130 if(end[0] != '\0')
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
131 end++;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
132
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
133 if(!p->keep) {
4857
f3f94fb55398 Small bugfix with getting playlist last line.
albeu
parents: 4782
diff changeset
134 if(end[0] != '\0') {
5788
8bd1c1e319fb Fix a bug produced when line are terminated with \r\n and not a single
albeu
parents: 4857
diff changeset
135 p->buffer_end -= end-p->iter;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
136 memmove(p->buffer,end,p->buffer_end);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
137 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
138 p->buffer_end = 0;
28183
b197740bf718 Add zero termination missing in two cases.
reimar
parents: 28182
diff changeset
139 p->buffer[p->buffer_end] = '\0';
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
140 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
141 } else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
142 p->iter = end;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
143
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
144 return p->line;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
145 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
146
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
147 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
148 play_tree_parser_reset(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
149 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
150 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
151
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
152 static void
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
153 play_tree_parser_stop_keeping(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
154 p->keep = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
155 if(p->iter && p->iter != p->buffer) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
156 p->buffer_end -= p->iter -p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
157 if(p->buffer_end)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
158 memmove(p->buffer,p->iter,p->buffer_end);
28184
0fb5551413f7 1000l, play_tree_parser_stop_keeping broke 0-termination of buffer
reimar
parents: 28183
diff changeset
159 p->buffer[p->buffer_end] = 0;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
160 p->iter = p->buffer;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
161 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
162 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
163
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
164
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
165 static play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
166 parse_asx(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
167 int comments = 0,get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
168 char* line = NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
169
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
170 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying asx...\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
171
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
172 while(1) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
173 if(get_line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
174 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
175 if(!line)
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
176 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
177 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
178 if(line[0] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
179 continue;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
180 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
181 if(!comments) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
182 if(line[0] != '<') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
183 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"First char isn't '<' but '%c'\n",line[0]);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
184 mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Buffer = [%s]\n",p->buffer);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
185 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
186 } else if(strncmp(line,"<!--",4) == 0) { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
187 comments = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
188 line += 4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
189 if(line[0] != '\0' && strlen(line) > 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
190 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
191 } else if(strncasecmp(line,"<ASX",4) == 0) // We got an asx element
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
192 break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
193 else // We don't get an asx
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
194 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
195 } else { // Comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
196 char* c;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
197 c = strchr(line,'-');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
198 if(c) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
199 if (strncmp(c,"--!>",4) == 0) { // End of comments
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
200 comments = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
201 line = c+4;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
202 if(line[0] != '\0') // There is some more data on this line : keep it
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
203 get_line = 0;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
204
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
205 } else {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
206 line = c+1; // Jump the -
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
207 if(line[0] != '\0') // Some more data
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
208 get_line = 0;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
209 else // End of line
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
210 get_line = 1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
211 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
212 } else // No - on this line (or rest of line) : get next one
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
213 get_line = 1;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
214 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
215 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
216
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
217 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected asx format\n");
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
218
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
219 // We have an asx : load it in memory and parse
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
220
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
221 while((line = play_tree_parser_get_line(p)) != NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
222 /* NOTHING */;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
223
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
224 mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Parsing asx file: [%s]\n",p->buffer);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
225 return asx_parser_build_tree(p->buffer,p->deep);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
226 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
227
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
228 static char*
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
229 pls_entry_get_value(char* line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
230 char* i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
231
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
232 i = strchr(line,'=');
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
233 if(!i || i[1] == '\0')
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
234 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
235 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
236 return i+1;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
237 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
238
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
239 typedef struct pls_entry {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
240 char* file;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
241 char* title;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
242 char* length;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
243 } pls_entry_t;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
244
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
245 static int
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
246 pls_read_entry(char* line,pls_entry_t** _e,int* _max_entry,char** val) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
247 int num,max_entry = (*_max_entry);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
248 pls_entry_t* e = (*_e);
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
249 int limit = INT_MAX / sizeof(*e);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
250 char* v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
251
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
252 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
253 if(!v) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
254 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
30751
a375d947381b Use negative return values for errors in pls_read_entry to make it match
reimar
parents: 30750
diff changeset
255 return -1;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
256 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
257
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
258 num = atoi(line);
30750
b9ec8956164f A playlist entry number of 0 is invalid for pls playlists.
reimar
parents: 30749
diff changeset
259 if(num <= 0 || num > limit) {
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
260 if (max_entry >= limit) {
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
261 mp_msg(MSGT_PLAYTREE, MSGL_WARN, "Too many index entries\n");
30751
a375d947381b Use negative return values for errors in pls_read_entry to make it match
reimar
parents: 30750
diff changeset
262 return -1;
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
263 }
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
264 num = max_entry+1;
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
265 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"No or invalid entry index in entry %s\nAssuming %d\n",line,num);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
266 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
267 if(num > max_entry) {
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30632
diff changeset
268 e = realloc(e, num * sizeof(pls_entry_t));
30749
88cd611f49dd Improve integer overflow and realloc error handling in playlist parser.
reimar
parents: 30702
diff changeset
269 if (!e)
30751
a375d947381b Use negative return values for errors in pls_read_entry to make it match
reimar
parents: 30750
diff changeset
270 return -1;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
271 memset(&e[max_entry],0,(num-max_entry)*sizeof(pls_entry_t));
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
272 max_entry = num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
273 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
274 (*_e) = e;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
275 (*_max_entry) = max_entry;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
276 (*val) = v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
277
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
278 return num;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
279 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
280
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
281
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
282 static play_tree_t*
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
283 parse_pls(play_tree_parser_t* p) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
284 char *line,*v;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
285 pls_entry_t* entries = NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
286 int n_entries = 0,max_entry=0,num;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
287 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
288
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
289 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying Winamp playlist...\n");
20834
e00250fc2b51 Skip empty lines in front of winamp playlist.
rtogni
parents: 19271
diff changeset
290 while((line = play_tree_parser_get_line(p))) {
e00250fc2b51 Skip empty lines in front of winamp playlist.
rtogni
parents: 19271
diff changeset
291 strstrip(line);
e00250fc2b51 Skip empty lines in front of winamp playlist.
rtogni
parents: 19271
diff changeset
292 if(strlen(line))
e00250fc2b51 Skip empty lines in front of winamp playlist.
rtogni
parents: 19271
diff changeset
293 break;
e00250fc2b51 Skip empty lines in front of winamp playlist.
rtogni
parents: 19271
diff changeset
294 }
e00250fc2b51 Skip empty lines in front of winamp playlist.
rtogni
parents: 19271
diff changeset
295 if (!line)
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
296 return NULL;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
297 if(strcasecmp(line,"[playlist]"))
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
298 return NULL;
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
299 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected Winamp playlist format\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
300 play_tree_parser_stop_keeping(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
301 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
302 if(!line)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
303 return NULL;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
304 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
305 if(strncasecmp(line,"NumberOfEntries",15) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
306 v = pls_entry_get_value(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
307 n_entries = atoi(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
308 if(n_entries < 0)
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
309 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Invalid number of entries: very funny!!!\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
310 else
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
311 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Playlist claims to have %d entries. Let's see.\n",n_entries);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
312 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
313 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
314
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
315 while(line) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
316 strstrip(line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
317 if(line[0] == '\0') {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
318 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
319 continue;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
320 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
321 if(strncasecmp(line,"File",4) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
322 num = pls_read_entry(line+4,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
323 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
324 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
325 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
326 entries[num-1].file = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
327 } else if(strncasecmp(line,"Title",5) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
328 num = pls_read_entry(line+5,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
329 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
330 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
331 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
332 entries[num-1].title = strdup(v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
333 } else if(strncasecmp(line,"Length",6) == 0) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
334 num = pls_read_entry(line+6,&entries,&max_entry,&v);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
335 if(num < 0)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
336 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
337 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
338 entries[num-1].length = strdup(v);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
339 } else
10397
6180d7558f75 output typo fixes: unknow --> unknown
diego
parents: 9789
diff changeset
340 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Unknown entry type %s\n",line);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
341 line = play_tree_parser_get_line(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
342 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
343
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
344 for(num = 0; num < max_entry ; num++) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
345 if(entries[num].file == NULL)
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
346 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Entry %d don't have a file !!!!\n",num+1);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
347 else {
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
348 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",entries[num].file);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
349 entry = play_tree_new();
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
350 play_tree_add_file(entry,entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
351 free(entries[num].file);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
352 if(list)
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
353 play_tree_append_entry(last_entry,entry);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
354 else
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
355 list = entry;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
356 last_entry = entry;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
357 }
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
358 // When we have info in playtree we add these info
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
359 free(entries[num].title);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
360 free(entries[num].length);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
361 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
362
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
363 free(entries);
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
364
31880
4f837c9acc58 Avoid trying to parse playlists without any recognized entries.
siretart
parents: 30751
diff changeset
365 if (!list)
4f837c9acc58 Avoid trying to parse playlists without any recognized entries.
siretart
parents: 30751
diff changeset
366 return NULL;
4f837c9acc58 Avoid trying to parse playlists without any recognized entries.
siretart
parents: 30751
diff changeset
367
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
368 entry = play_tree_new();
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
369 play_tree_set_child(entry,list);
5866
0f5f626e5151 Handle winamp playlist as sublist.
albeu
parents: 5802
diff changeset
370 return entry;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
371 }
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
372
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
373 /*
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
374 Reference Ini-Format: Each entry is assumed a reference
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
375 */
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
376 static play_tree_t*
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
377 parse_ref_ini(play_tree_parser_t* p) {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
378 char *line,*v;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
379 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
380
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
381 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying reference-ini playlist...\n");
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
382 if (!(line = play_tree_parser_get_line(p)))
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
383 return NULL;
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
384 strstrip(line);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
385 if(strcasecmp(line,"[Reference]"))
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
386 return NULL;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
387 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected reference-ini playlist format\n");
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
388 play_tree_parser_stop_keeping(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
389 line = play_tree_parser_get_line(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
390 if(!line)
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
391 return NULL;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
392 while(line) {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
393 strstrip(line);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
394 if(strncasecmp(line,"Ref",3) == 0) {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
395 v = pls_entry_get_value(line+3);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
396 if(!v)
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
397 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
398 else
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
399 {
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
400 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",v);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
401 entry = play_tree_new();
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
402 play_tree_add_file(entry,v);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
403 if(list)
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
404 play_tree_append_entry(last_entry,entry);
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
405 else
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
406 list = entry;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
407 last_entry = entry;
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
408 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
409 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
410 line = play_tree_parser_get_line(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
411 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
412
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
413 if(!list) return NULL;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
414 entry = play_tree_new();
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
415 play_tree_set_child(entry,list);
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
416 return entry;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
417 }
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
418
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
419 static play_tree_t*
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
420 parse_m3u(play_tree_parser_t* p) {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
421 char* line;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
422 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
423
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
424 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying extended m3u playlist...\n");
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
425 if (!(line = play_tree_parser_get_line(p)))
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
426 return NULL;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
427 strstrip(line);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
428 if(strcasecmp(line,"#EXTM3U"))
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
429 return NULL;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
430 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected extended m3u playlist format\n");
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
431 play_tree_parser_stop_keeping(p);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
432
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
433 while((line = play_tree_parser_get_line(p)) != NULL) {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
434 strstrip(line);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
435 if(line[0] == '\0')
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
436 continue;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
437 /* EXTM3U files contain such lines:
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
438 * #EXTINF:<seconds>, <title>
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
439 * followed by a line with the filename
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
440 * for now we have no place to put that
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
441 * so we just skip that extra-info ::atmos
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
442 */
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
443 if(line[0] == '#') {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
444 #if 0 /* code functional */
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
445 if(strncasecmp(line,"#EXTINF:",8) == 0) {
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
446 mp_msg(MSGT_PLAYTREE,MSGL_INFO,"[M3U] Duration: %dsec Title: %s\n",
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
447 strtol(line+8,&line,10), line+2);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
448 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
449 #endif
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
450 continue;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
451 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
452 entry = play_tree_new();
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
453 play_tree_add_file(entry,line);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
454 if(!list)
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
455 list = entry;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
456 else
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
457 play_tree_append_entry(last_entry,entry);
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
458 last_entry = entry;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
459 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
460
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
461 if(!list) return NULL;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
462 entry = play_tree_new();
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
463 play_tree_set_child(entry,list);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
464 return entry;
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
465 }
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
466
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
467 static play_tree_t*
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
468 parse_smil(play_tree_parser_t* p) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
469 int entrymode=0;
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
470 char* line,source[512],*pos,*s_start,*s_end,*src_line;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
471 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
472 int is_rmsmil = 0;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
473 unsigned int npkt, ttlpkt;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
474
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
475 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying smil playlist...\n");
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
476
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
477 // Check if smil
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
478 while((line = play_tree_parser_get_line(p)) != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
479 strstrip(line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
480 if(line[0] == '\0') // Ignore empties
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
481 continue;
22518
29a3bb75db47 Support smil embedded into xml, fixes bugzilla #768
rtogni
parents: 22477
diff changeset
482 if (strncasecmp(line,"<?xml",5)==0) // smil in xml
29a3bb75db47 Support smil embedded into xml, fixes bugzilla #768
rtogni
parents: 22477
diff changeset
483 continue;
28314
3e4486488465 add "<!DOCTYPE smil" to smil playlist
compn
parents: 28184
diff changeset
484 if (strncasecmp(line,"<!DOCTYPE smil",13)==0) // smil in xml
3e4486488465 add "<!DOCTYPE smil" to smil playlist
compn
parents: 28184
diff changeset
485 continue;
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
486 if (strncasecmp(line,"<smil",5)==0 || strncasecmp(line,"<?wpl",5)==0 ||
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
487 strncasecmp(line,"(smil-document",14)==0)
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
488 break; // smil header found
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
489 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
490 return NULL; //line not smil exit
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
491 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
492
24962
fb50e37df836 Fix possible null-pointer-dereference in parse_smil().
cehoyos
parents: 24424
diff changeset
493 if (!line) return NULL;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
494 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected smil playlist format\n");
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
495 play_tree_parser_stop_keeping(p);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
496
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
497 if (strncasecmp(line,"(smil-document",14)==0) {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
498 mp_msg(MSGT_PLAYTREE,MSGL_V,"Special smil-over-realrtsp playlist header\n");
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
499 is_rmsmil = 1;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
500 if (sscanf(line, "(smil-document (ver 1.0)(npkt %u)(ttlpkt %u", &npkt, &ttlpkt) != 2) {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
501 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: header parsing failure, assuming single packet.\n");
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
502 npkt = ttlpkt = 1;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
503 }
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
504 if (ttlpkt == 0 || npkt > ttlpkt) {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
505 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: bad packet counters (npkk = %u, ttlpkt = %u), assuming single packet.\n",
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
506 npkt, ttlpkt);
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
507 npkt = ttlpkt = 1;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
508 }
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
509 }
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
510
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
511 //Get entries from smil
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
512 src_line = line;
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
513 line = NULL;
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
514 do {
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
515 strstrip(src_line);
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
516 free(line);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
517 line = NULL;
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
518 /* If we're parsing smil over realrtsp and this is not the last packet and
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
519 * this is the last line in the packet (terminating with ") ) we must get
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
520 * the next line, strip the header, and concatenate it to the current line.
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
521 */
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
522 if (is_rmsmil && npkt != ttlpkt && strstr(src_line,"\")")) {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
523 char *payload;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
524
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
525 line = strdup(src_line);
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
526 if(!(src_line = play_tree_parser_get_line(p))) {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
527 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: can't get line from packet %u/%u.\n", npkt, ttlpkt);
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
528 break;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
529 }
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
530 strstrip(src_line);
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
531 // Skip header, packet starts after "
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
532 if(!(payload = strchr(src_line,'\"'))) {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
533 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"smil-over-realrtsp: can't find start of packet, using complete line.\n");
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
534 payload = src_line;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
535 } else
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
536 payload++;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
537 // Skip ") at the end of the last line from the current packet
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
538 line[strlen(line)-2] = 0;
22477
e305132d083b 100l, allocated buffer was too small.
rtogni
parents: 22242
diff changeset
539 line = realloc(line, strlen(line)+strlen(payload)+1);
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
540 strcat (line, payload);
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
541 npkt++;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
542 } else
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
543 line = strdup(src_line);
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
544 /* Unescape \" to " for smil-over-rtsp */
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
545 if (is_rmsmil && line[0] != '\0') {
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
546 int i, j;
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
547
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
548 for (i = 0; i < strlen(line); i++)
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
549 if (line[i] == '\\' && line[i+1] == '"')
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
550 for (j = i; line[j]; j++)
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
551 line[j] = line[j+1];
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
552 }
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
553 pos = line;
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
554 while (pos) {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
555 if (!entrymode) { // all entries filled so far
24424
0c4f1a88eaae warning fixes:
diego
parents: 23774
diff changeset
556 while ((pos=strchr(pos, '<'))) {
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
557 if (strncasecmp(pos,"<video",6)==0 || strncasecmp(pos,"<audio",6)==0 || strncasecmp(pos,"<media",6)==0) {
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
558 entrymode=1;
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
559 break; // Got a valid tag, exit '<' search loop
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
560 }
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
561 pos++;
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
562 }
22520
e227eb76450d Remove code duplication in smil parser
rtogni
parents: 22518
diff changeset
563 }
e227eb76450d Remove code duplication in smil parser
rtogni
parents: 22518
diff changeset
564 if (entrymode) { //Entry found but not yet filled
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
565 pos = strstr(pos,"src="); // Is source present on this line
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
566 if (pos != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
567 entrymode=0;
23774
16a67232e916 realrtsp smil files can also use ' as field delimiter instead of "
rtogni
parents: 22712
diff changeset
568 if (pos[4] != '"' && pos[4] != '\'') {
16a67232e916 realrtsp smil files can also use ' as field delimiter instead of "
rtogni
parents: 22712
diff changeset
569 mp_msg(MSGT_PLAYTREE,MSGL_V,"Unknown delimiter %c in source line %s\n", pos[4], line);
16a67232e916 realrtsp smil files can also use ' as field delimiter instead of "
rtogni
parents: 22712
diff changeset
570 break;
16a67232e916 realrtsp smil files can also use ' as field delimiter instead of "
rtogni
parents: 22712
diff changeset
571 }
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
572 s_start=pos+5;
23774
16a67232e916 realrtsp smil files can also use ' as field delimiter instead of "
rtogni
parents: 22712
diff changeset
573 s_end=strchr(s_start,pos[4]);
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
574 if (s_end == NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
575 mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line);
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
576 break;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
577 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
578 if (s_end-s_start> 511) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
579 mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line);
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
580 break;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
581 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
582 strncpy(source,s_start,s_end-s_start);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
583 source[(s_end-s_start)]='\0'; // Null terminate
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
584 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
585 play_tree_add_file(entry,source);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
586 if(!list) //Insert new entry
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
587 list = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
588 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
589 play_tree_append_entry(last_entry,entry);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
590 last_entry = entry;
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
591 pos = s_end;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
592 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
593 }
22712
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
594 }
c7eee1ecbe8c Support multiple tags in a single line and tags on the same line as the
rtogni
parents: 22520
diff changeset
595 } while((src_line = play_tree_parser_get_line(p)) != NULL);
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
596
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
597 free(line);
22242
4cabf7499fef Add support for smil playlist served over realrtsp
rtogni
parents: 21910
diff changeset
598
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
599 if(!list) return NULL; // Nothing found
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
600
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
601 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
602 play_tree_set_child(entry,list);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
603 return entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
604 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
605
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
606 static play_tree_t*
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
607 embedded_playlist_parse(char *line) {
12223
e7c8200ffdc5 Respect -playlist for asx streams
rtognimp
parents: 12097
diff changeset
608 int f=DEMUXER_TYPE_PLAYLIST;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
609 stream_t* stream;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
610 play_tree_parser_t* ptp;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
611 play_tree_t* entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
612
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
613 // Get stream opened to link
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
614 stream=open_stream(line,0,&f);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
615 if(!stream) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
616 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
617 return NULL;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
618 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
619
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
620 //add new playtree
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
621 mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding playlist %s to element entryref\n",line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
622
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
623 ptp = play_tree_parser_new(stream,1);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
624 entry = play_tree_parser_get_play_tree(ptp, 1);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
625 play_tree_parser_free(ptp);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
626 free_stream(stream);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
627
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
628 return entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
629 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
630
18916
a95ed361d16b several function from playtreeparser.c maked static,
reynaldo
parents: 18879
diff changeset
631 static play_tree_t*
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
632 parse_textplain(play_tree_parser_t* p) {
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
633 char* line;
12300
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
634 char *c;
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
635 int embedded;
9789
45173e0d34cc Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents: 9749
diff changeset
636 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
637
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
638 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext playlist...\n");
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
639 play_tree_parser_stop_keeping(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
640
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
641 while((line = play_tree_parser_get_line(p)) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
642 strstrip(line);
12689
050c90536ddd Support for comments in plaintext playlist by adland
alex
parents: 12538
diff changeset
643 if(line[0] == '\0' || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
644 continue;
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
645
12538
2beafad68f68 Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents: 12300
diff changeset
646 //Special check for embedded smil or ram reference in file
12300
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
647 embedded = 0;
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
648 if (strlen(line) > 5)
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
649 for(c = line; c[0]; c++ )
12538
2beafad68f68 Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents: 12300
diff changeset
650 if ( ((c[0] == '.') && //start with . and next have smil with optional ? or &
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
651 (tolower(c[1]) == 's') && (tolower(c[2])== 'm') &&
12300
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
652 (tolower(c[3]) == 'i') && (tolower(c[4]) == 'l') &&
12538
2beafad68f68 Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents: 12300
diff changeset
653 (!c[5] || c[5] == '?' || c[5] == '&')) || // or
2beafad68f68 Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents: 12300
diff changeset
654 ((c[0] == '.') && // start with . and next have smi or ram with optional ? or &
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
655 ( ((tolower(c[1]) == 's') && (tolower(c[2])== 'm') && (tolower(c[3]) == 'i')) ||
12538
2beafad68f68 Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents: 12300
diff changeset
656 ((tolower(c[1]) == 'r') && (tolower(c[2])== 'a') && (tolower(c[3]) == 'm')) )
2beafad68f68 Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents: 12300
diff changeset
657 && (!c[4] || c[4] == '?' || c[4] == '&')) ){
12300
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
658 entry=embedded_playlist_parse(line);
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
659 embedded = 1;
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
660 break;
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
661 }
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
662
95ea9f5f6f14 Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents: 12223
diff changeset
663 if (!embedded) { //regular file link
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
664 entry = play_tree_new();
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
665 play_tree_add_file(entry,line);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
666 }
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
667
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
668 if (entry != NULL) {
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
669 if(!list)
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
670 list = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
671 else
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
672 play_tree_append_entry(last_entry,entry);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
673 last_entry = entry;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
674 }
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
675 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
676
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
677 if(!list) return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
678 entry = play_tree_new();
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
679 play_tree_set_child(entry,list);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
680 return entry;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
681 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
682
32623
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
683 /**
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
684 * \brief decode the base64 used in nsc files
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
685 * \param in input string, 0-terminated
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
686 * \param buf output buffer, must point to memory suitable for realloc,
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
687 * will be NULL on failure.
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
688 * \return decoded length in bytes
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
689 */
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
690 static int decode_nsc_base64(char *in, char **buf) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
691 int i, j, n;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
692 if (in[0] != '0' || in[1] != '2')
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
693 goto err_out;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
694 in += 2; // skip prefix
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
695 if (strlen(in) < 16) // error out if nothing to decode
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
696 goto err_out;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
697 in += 12; // skip encoded string length
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
698 n = strlen(in) / 4;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
699 *buf = realloc(*buf, n * 3);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
700 for (i = 0; i < n; i++) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
701 uint8_t c[4];
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
702 for (j = 0; j < 4; j++) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
703 c[j] = in[4 * i + j];
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
704 if (c[j] >= '0' && c[j] <= '9') c[j] += 0 - '0';
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
705 else if (c[j] >= 'A' && c[j] <= 'Z') c[j] += 10 - 'A';
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
706 else if (c[j] >= 'a' && c[j] <= 'z') c[j] += 36 - 'a';
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
707 else if (c[j] == '{') c[j] = 62;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
708 else if (c[j] == '}') c[j] = 63;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
709 else {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
710 mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Invalid character %c (0x%02"PRIx8")\n", c[j], c[j]);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
711 goto err_out;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
712 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
713 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
714 (*buf)[3 * i] = (c[0] << 2) | (c[1] >> 4);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
715 (*buf)[3 * i + 1] = (c[1] << 4) | (c[2] >> 2);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
716 (*buf)[3 * i + 2] = (c[2] << 6) | c[3];
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
717 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
718 return 3 * n;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
719 err_out:
32628
bfe41b532fe9 Remove pointless NULL checks before free.
reimar
parents: 32623
diff changeset
720 free(*buf);
32623
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
721 *buf = NULL;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
722 return 0;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
723 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
724
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
725 /**
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
726 * \brief "converts" utf16 to ascii by just discarding every second byte
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
727 * \param buf buffer to convert
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
728 * \param len lenght of buffer, must be > 0
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
729 */
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
730 static void utf16_to_ascii(char *buf, int len) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
731 int i;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
732 if (len <= 0) return;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
733 for (i = 0; i < len / 2; i++)
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
734 buf[i] = buf[i * 2];
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
735 buf[i] = 0; // just in case
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
736 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
737
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
738 static play_tree_t *parse_nsc(play_tree_parser_t* p) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
739 char *line, *addr = NULL, *url, *unicast_url = NULL;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
740 int port = 0;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
741 play_tree_t *entry = NULL;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
742
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
743 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying nsc playlist...\n");
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
744 while((line = play_tree_parser_get_line(p)) != NULL) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
745 strstrip(line);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
746 if(!line[0]) // Ignore empties
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
747 continue;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
748 if (strncasecmp(line,"[Address]", 9) == 0)
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
749 break; // nsc header found
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
750 else
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
751 return NULL;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
752 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
753 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected nsc playlist format\n");
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
754 play_tree_parser_stop_keeping(p);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
755 while ((line = play_tree_parser_get_line(p)) != NULL) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
756 strstrip(line);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
757 if (!line[0])
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
758 continue;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
759 if (strncasecmp(line, "Unicast URL=", 12) == 0) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
760 int len = decode_nsc_base64(&line[12], &unicast_url);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
761 if (len <= 0)
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
762 mp_msg(MSGT_PLAYTREE, MSGL_WARN, "[nsc] Unsupported Unicast URL encoding\n");
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
763 else
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
764 utf16_to_ascii(unicast_url, len);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
765 } else if (strncasecmp(line, "IP Address=", 11) == 0) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
766 int len = decode_nsc_base64(&line[11], &addr);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
767 if (len <= 0)
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
768 mp_msg(MSGT_PLAYTREE, MSGL_WARN, "[nsc] Unsupported IP Address encoding\n");
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
769 else
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
770 utf16_to_ascii(addr, len);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
771 } else if (strncasecmp(line, "IP Port=", 8) == 0) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
772 port = strtol(&line[8], NULL, 0);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
773 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
774 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
775
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
776 if (unicast_url)
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
777 url = strdup(unicast_url);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
778 else if (addr && port) {
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
779 url = malloc(strlen(addr) + 7 + 20 + 1);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
780 sprintf(url, "http://%s:%i", addr, port);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
781 } else
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
782 goto out;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
783
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
784 entry = play_tree_new();
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
785 play_tree_add_file(entry, url);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
786 free(url);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
787 out:
32628
bfe41b532fe9 Remove pointless NULL checks before free.
reimar
parents: 32623
diff changeset
788 free(addr);
bfe41b532fe9 Remove pointless NULL checks before free.
reimar
parents: 32623
diff changeset
789 free(unicast_url);
32623
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
790 return entry;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
791 }
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
792
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
793 play_tree_t*
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
794 parse_playtree(stream_t *stream, int forced) {
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
795 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
796 play_tree_t* ret;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
797
4156
22fadd4022b5 playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents: 4043
diff changeset
798 #ifdef MP_DEBUG
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
799 assert(stream != NULL);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
800 #endif
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
801
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
802 p = play_tree_parser_new(stream,0);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
803 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
804 return NULL;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
805
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
806 ret = play_tree_parser_get_play_tree(p, forced);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
807 play_tree_parser_free(p);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
808
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
809 return ret;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
810 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
811
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
812 static void
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
813 play_tree_add_basepath(play_tree_t* pt, char* bp) {
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
814 int i,bl = strlen(bp),fl;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
815
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
816 if(pt->child) {
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
817 play_tree_t* i;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
818 for(i = pt->child ; i != NULL ; i = i->next)
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
819 play_tree_add_basepath(i,bp);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
820 return;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
821 }
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
822
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
823 if(!pt->files)
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
824 return;
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
825
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
826 for(i = 0 ; pt->files[i] != NULL ; i++) {
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
827 fl = strlen(pt->files[i]);
13305
90ffe76b5b25 Don't prepend basepath to a full unix path. ( 10l to Joey. )
al
parents: 13010
diff changeset
828 // if we find a full unix path, url:// or X:\ at the beginning,
90ffe76b5b25 Don't prepend basepath to a full unix path. ( 10l to Joey. )
al
parents: 13010
diff changeset
829 // don't mangle it.
90ffe76b5b25 Don't prepend basepath to a full unix path. ( 10l to Joey. )
al
parents: 13010
diff changeset
830 if(fl <= 0 || strstr(pt->files[i],"://") || (strstr(pt->files[i],":\\") == pt->files[i] + 1) || (pt->files[i][0] == '/') )
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
831 continue;
13010
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
832 // if the path begins with \ then prepend drive letter to it.
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
833 if (pt->files[i][0] == '\\') {
18928
586777f09b1b relative-to-absolute path fixes: Do not prepend drive letter to \\ paths.
reimar
parents: 18916
diff changeset
834 if (pt->files[i][1] == '\\')
586777f09b1b relative-to-absolute path fixes: Do not prepend drive letter to \\ paths.
reimar
parents: 18916
diff changeset
835 continue;
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30632
diff changeset
836 pt->files[i] = realloc(pt->files[i], 2 + fl + 1);
13010
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
837 memmove(pt->files[i] + 2,pt->files[i],fl+1);
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
838 memcpy(pt->files[i],bp,2);
18928
586777f09b1b relative-to-absolute path fixes: Do not prepend drive letter to \\ paths.
reimar
parents: 18916
diff changeset
839 continue;
13010
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
840 }
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30632
diff changeset
841 pt->files[i] = realloc(pt->files[i], bl + fl + 1);
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
842 memmove(pt->files[i] + bl,pt->files[i],fl+1);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
843 memcpy(pt->files[i],bp,bl);
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
844 }
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
845 }
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
846
9301
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
847 // Wrapper for play_tree_add_basepath (add base path from file)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
848 void play_tree_add_bpf(play_tree_t* pt, char* filename)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
849 {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
850 char *ls, *file;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
851
9301
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
852 if (pt && filename)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
853 {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
854 file = strdup(filename);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
855 if (file)
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
856 {
13010
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
857 ls = strrchr(file,'/');
047bbb973011 windows path seperator fixes
joey
parents: 12689
diff changeset
858 if(!ls) ls = strrchr(file,'\\');
9301
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
859 if(ls) {
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
860 ls[1] = '\0';
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
861 play_tree_add_basepath(pt,file);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
862 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
863 free(file);
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
864 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
865 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
866 }
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
867
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
868 play_tree_t*
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
869 parse_playlist_file(char* file) {
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
870 stream_t *stream;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
871 play_tree_t* ret;
12223
e7c8200ffdc5 Respect -playlist for asx streams
rtognimp
parents: 12097
diff changeset
872 int f=DEMUXER_TYPE_PLAYLIST;
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
873
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
874 stream = open_stream(file,0,&f);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
875
9749
58e5880f4788 Use new config headers
albeu
parents: 9301
diff changeset
876 if(!stream) {
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
877 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while opening playlist file %s: %s\n",file,strerror(errno));
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
878 return NULL;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
879 }
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
880
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
881 mp_msg(MSGT_PLAYTREE,MSGL_V,"Parsing playlist file %s...\n",file);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
882
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
883 ret = parse_playtree(stream,1);
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
884 free_stream(stream);
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
885
9301
7841308ad250 this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents: 9089
diff changeset
886 play_tree_add_bpf(ret, file);
6662
f8e25756a5ec Relative filename in playlist are now relative to the playlist path
albeu
parents: 6661
diff changeset
887
4043
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
888 return ret;
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
889
25590564842f tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff changeset
890 }
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
891
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
892
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
893 play_tree_parser_t*
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
894 play_tree_parser_new(stream_t* stream,int deep) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
895 play_tree_parser_t* p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
896
18879
cc65a585fdcc rm unnecesary casts from void* - part 3
reynaldo
parents: 18869
diff changeset
897 p = calloc(1,sizeof(play_tree_parser_t));
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
898 if(!p)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
899 return NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
900 p->stream = stream;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
901 p->deep = deep;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
902 p->keep = 1;
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
903
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
904 return p;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
905
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
906 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
907
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
908 void
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
909 play_tree_parser_free(play_tree_parser_t* p) {
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
910
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
911 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
912 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
913 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
914
32511
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
915 free(p->buffer);
b39155e98ac3 Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents: 31880
diff changeset
916 free(p->line);
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
917 free(p);
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
918 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
919
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
920 play_tree_t*
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
921 play_tree_parser_get_play_tree(play_tree_parser_t* p, int forced) {
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
922 play_tree_t* tree = NULL;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
923
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
924 #ifdef MP_DEBUG
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
925 assert(p != NULL);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
926 #endif
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
927
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
928
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
929 while(play_tree_parser_get_line(p) != NULL) {
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
930 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
931
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
932 tree = parse_asx(p);
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
933 if(tree) break;
4782
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
934 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
935
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
936 tree = parse_pls(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
937 if(tree) break;
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
938 play_tree_parser_reset(p);
4b728967bd77 Playtree parser switch to a by line mode.
albeu
parents: 4714
diff changeset
939
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
940 tree = parse_m3u(p);
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
941 if(tree) break;
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
942 play_tree_parser_reset(p);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
943
8897
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
944 tree = parse_ref_ini(p);
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
945 if(tree) break;
ef01554542fb This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents: 8164
diff changeset
946 play_tree_parser_reset(p);
6661
dc61b6b159e4 Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents: 5866
diff changeset
947
12097
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
948 tree = parse_smil(p);
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
949 if(tree) break;
cb0cdaa0bddf Support for smil playlist, both standalone and embedded into other
rtognimp
parents: 10694
diff changeset
950 play_tree_parser_reset(p);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
951
32623
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
952 tree = parse_nsc(p);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
953 if(tree) break;
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
954 play_tree_parser_reset(p);
d90ee6158b89 Add playlist parser for .nsc files.
reimar
parents: 32511
diff changeset
955
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
956 // Here come the others formats ( textplain must stay the last one )
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
957 if (forced)
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
958 {
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
959 tree = parse_textplain(p);
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
960 if(tree) break;
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
961 }
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
962 break;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
963 }
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
964
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
965 if(tree)
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
966 mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist successfully parsed\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
967 else
8925
5c15777f1c07 this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents: 8907
diff changeset
968 mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_ERR:MSGL_V),"Error while parsing playlist\n");
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
969
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
970 if(tree)
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
971 tree = play_tree_cleanup(tree);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28314
diff changeset
972
10487
11ec7586a0fe Typos fixed, based on patch sent by Alex.
diego
parents: 10397
diff changeset
973 if(!tree) mp_msg(MSGT_PLAYTREE,((forced==1)?MSGL_WARN:MSGL_V),"Warning: empty playlist\n");
4308
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
974
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
975 return tree;
d752f99fd535 Objectization of the play_tree_parser for more flexiblity
albeu
parents: 4156
diff changeset
976 }