Mercurial > mplayer.hg
annotate playtreeparser.c @ 6524:05cd2cf758e4
if09 support
author | alex |
---|---|
date | Sun, 23 Jun 2002 15:03:54 +0000 |
parents | 0f5f626e5151 |
children | dc61b6b159e4 |
rev | line source |
---|---|
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
1 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
2 #include "config.h" |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
3 #include <stdlib.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
4 #include <stdio.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
5 #include <string.h> |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
6 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
7 #include <assert.h> |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
8 #endif |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
9 #include <errno.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
10 #include <sys/types.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
11 #include <sys/stat.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
12 #include <fcntl.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
13 #include <unistd.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
14 #include "playtree.h" |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
15 #include "playtreeparser.h" |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
16 #include "libmpdemux/stream.h" |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
17 #include "mp_msg.h" |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
18 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
19 extern play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
20 asx_parser_build_tree(char* buffer, int ref); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
21 |
4782 | 22 #define BUF_STEP 1024 |
23 | |
24 #define WHITES " \n\r\t" | |
25 | |
26 static void | |
27 strstrip(char* str) { | |
28 char* i; | |
29 | |
30 for(i = str ; i[0] != '\0' && strchr(WHITES,i[0]) != NULL; i++) | |
31 /* NOTHING */; | |
32 if(i[0] != '\0') { | |
33 memmove(str,i,strlen(i)); | |
34 for(i = str + strlen(str) ; strchr(WHITES,i[0]) != NULL; i--) | |
35 /* NOTHING */; | |
36 i[1] = '\0'; | |
37 } else | |
38 str[0] = '\0'; | |
39 } | |
40 | |
41 static char* | |
42 play_tree_parser_get_line(play_tree_parser_t* p) { | |
43 char *end,*line_end; | |
44 int r,resize = 0; | |
45 | |
46 if(p->buffer == NULL) { | |
47 p->buffer = (char*)malloc(BUF_STEP); | |
48 p->buffer_size = BUF_STEP; | |
49 p->iter = p->buffer; | |
50 } | |
51 | |
5802 | 52 if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0')) |
4782 | 53 return NULL; |
54 | |
55 while(1) { | |
56 | |
57 if(resize) { | |
58 r = p->iter - p->buffer; | |
59 p->buffer = (char*)realloc(p->buffer,p->buffer_size+BUF_STEP); | |
60 p->iter = p->buffer + r; | |
61 p->buffer_size += BUF_STEP; | |
62 resize = 0; | |
63 } | |
64 | |
65 if(p->buffer_size - p->buffer_end > 1 && ! p->stream->eof) { | |
66 r = stream_read(p->stream,p->buffer + p->buffer_end,p->buffer_size - p->buffer_end - 1); | |
67 if(r > 0) { | |
68 p->buffer_end += r; | |
69 p->buffer[p->buffer_end] = '\0'; | |
70 } | |
71 } | |
72 | |
73 end = strchr(p->iter,'\n'); | |
74 if(!end) { | |
75 if(p->stream->eof) { | |
4857 | 76 end = p->buffer + p->buffer_end; |
4782 | 77 break; |
78 } | |
79 resize = 1; | |
80 continue; | |
81 } | |
82 break; | |
83 } | |
84 | |
85 line_end = ((*(end-1)) == '\r') ? end-1 : end; | |
5802 | 86 if(line_end - p->iter >= 0) |
87 p->line = (char*)realloc(p->line,line_end - p->iter+1); | |
88 else | |
4782 | 89 return NULL; |
5802 | 90 if(line_end - p->iter > 0) |
91 strncpy(p->line,p->iter,line_end - p->iter); | |
4782 | 92 p->line[line_end - p->iter] = '\0'; |
5802 | 93 if(end[0] != '\0') |
4857 | 94 end++; |
4782 | 95 |
96 if(!p->keep) { | |
4857 | 97 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
|
98 p->buffer_end -= end-p->iter; |
4782 | 99 memmove(p->buffer,end,p->buffer_end); |
100 } else | |
101 p->buffer_end = 0; | |
102 p->iter = p->buffer; | |
103 } else | |
104 p->iter = end; | |
105 | |
106 return p->line; | |
107 } | |
108 | |
109 static void | |
110 play_tree_parser_reset(play_tree_parser_t* p) { | |
111 p->iter = p->buffer; | |
112 } | |
113 | |
114 static void | |
115 play_tree_parser_stop_keeping(play_tree_parser_t* p) { | |
116 p->keep = 0; | |
117 if(p->iter && p->iter != p->buffer) { | |
118 p->buffer_end -= p->iter -p->buffer; | |
119 if(p->buffer_end) | |
120 memmove(p->buffer,p->iter,p->buffer_end); | |
121 p->iter = p->buffer; | |
122 } | |
123 } | |
124 | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
125 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
126 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
127 parse_asx(play_tree_parser_t* p) { |
4782 | 128 int comments = 0,get_line = 1; |
129 char* line = NULL; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
130 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
131 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying asx...\n"); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
132 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
133 while(1) { |
4782 | 134 if(get_line) { |
135 line = play_tree_parser_get_line(p); | |
136 if(!line) | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
137 return NULL; |
4782 | 138 strstrip(line); |
139 if(line[0] == '\0') | |
140 continue; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
141 } |
4782 | 142 if(!comments) { |
143 if(line[0] != '<') { | |
144 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
|
145 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
|
146 return NULL; |
4782 | 147 } else if(strncmp(line,"<!--",4) == 0) { // Comments |
148 comments = 1; | |
149 line += 4; | |
150 if(line[0] != '\0' && strlen(line) > 0) | |
151 get_line = 0; | |
152 } else if(strncasecmp(line,"<ASX",4) == 0) // We got an asx element | |
153 break; | |
154 else // We don't get an asx | |
155 return NULL; | |
156 } else { // Comments | |
157 char* c; | |
158 c = strchr(line,'-'); | |
159 if(c) { | |
160 if (strncmp(c,"--!>",4) == 0) { // End of comments | |
161 comments = 0; | |
162 line = c+4; | |
163 if(line[0] != '\0') // There is some more data on this line : keep it | |
164 get_line = 0; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
165 |
4782 | 166 } else { |
167 line = c+1; // Jump the - | |
168 if(line[0] != '\0') // Some more data | |
169 get_line = 0; | |
170 else // End of line | |
171 get_line = 1; | |
172 } | |
173 } else // No - on this line (or rest of line) : get next one | |
174 get_line = 1; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
175 } |
4782 | 176 } |
177 | |
178 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
|
179 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
180 // 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
|
181 |
4782 | 182 while((line = play_tree_parser_get_line(p)) != NULL) |
183 /* NOTHING */; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
184 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
185 mp_msg(MSGT_PLAYTREE,MSGL_DBG3,"Parsing asx file : [%s]\n",p->buffer); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
186 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
|
187 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
188 |
4782 | 189 static char* |
190 pls_entry_get_value(char* line) { | |
191 char* i; | |
192 | |
193 i = strchr(line,'='); | |
194 if(!i || i[1] == '\0') | |
195 return NULL; | |
196 else | |
197 return i+1; | |
198 } | |
199 | |
200 typedef struct pls_entry { | |
201 char* file; | |
202 char* title; | |
203 char* length; | |
204 } pls_entry_t; | |
205 | |
206 static int | |
207 pls_read_entry(char* line,pls_entry_t** _e,int* _max_entry,char** val) { | |
208 int num,max_entry = (*_max_entry); | |
209 pls_entry_t* e = (*_e); | |
210 char* v; | |
211 | |
212 v = pls_entry_get_value(line); | |
213 if(!v) { | |
214 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
215 return 0; | |
216 } | |
217 | |
218 num = atoi(line); | |
219 if(num < 0) { | |
220 num = max_entry+1; | |
221 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"No entry index in entry %s\nAssuming %d\n",line,num); | |
222 } | |
223 if(num > max_entry) { | |
224 e = (pls_entry_t*)realloc(e,num*sizeof(pls_entry_t)); | |
225 memset(&e[max_entry],0,(num-max_entry)*sizeof(pls_entry_t)); | |
226 max_entry = num; | |
227 } | |
228 (*_e) = e; | |
229 (*_max_entry) = max_entry; | |
230 (*val) = v; | |
231 | |
232 return num; | |
233 } | |
234 | |
235 | |
236 play_tree_t* | |
237 parse_pls(play_tree_parser_t* p) { | |
238 char *line,*v; | |
239 pls_entry_t* entries = NULL; | |
240 int n_entries = 0,max_entry=0,num; | |
241 play_tree_t *list = NULL, *entry = NULL; | |
242 | |
243 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying winamp playlist...\n"); | |
244 line = play_tree_parser_get_line(p); | |
245 strstrip(line); | |
246 if(strcasecmp(line,"[playlist]")) | |
247 return NULL; | |
248 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected winamp playlist format\n"); | |
249 play_tree_parser_stop_keeping(p); | |
250 line = play_tree_parser_get_line(p); | |
251 if(!line) | |
252 return NULL; | |
253 strstrip(line); | |
254 if(strncasecmp(line,"NumberOfEntries",15) == 0) { | |
255 v = pls_entry_get_value(line); | |
256 n_entries = atoi(v); | |
257 if(n_entries < 0) | |
258 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Invalid number of entries : very funny !!!\n"); | |
259 else | |
260 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Playlist claim to have %d entries. Let's see.\n",n_entries); | |
261 line = play_tree_parser_get_line(p); | |
262 } | |
263 | |
264 while(line) { | |
265 strstrip(line); | |
266 if(line[0] == '\0') { | |
267 line = play_tree_parser_get_line(p); | |
268 continue; | |
269 } | |
270 if(strncasecmp(line,"File",4) == 0) { | |
271 num = pls_read_entry(line+4,&entries,&max_entry,&v); | |
272 if(num < 0) | |
273 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
274 else | |
275 entries[num-1].file = strdup(v); | |
276 } else if(strncasecmp(line,"Title",5) == 0) { | |
277 num = pls_read_entry(line+5,&entries,&max_entry,&v); | |
278 if(num < 0) | |
279 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
280 else | |
281 entries[num-1].title = strdup(v); | |
282 } else if(strncasecmp(line,"Length",6) == 0) { | |
283 num = pls_read_entry(line+6,&entries,&max_entry,&v); | |
284 if(num < 0) | |
285 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
286 else | |
287 entries[num-1].length = strdup(v); | |
288 } else | |
289 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Unknow entry type %s\n",line); | |
290 line = play_tree_parser_get_line(p); | |
291 } | |
292 | |
293 for(num = 0; num < max_entry ; num++) { | |
294 if(entries[num].file == NULL) | |
295 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Entry %d don't have a file !!!!\n",num+1); | |
296 else { | |
5866 | 297 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",entries[num].file); |
4782 | 298 entry = play_tree_new(); |
299 play_tree_add_file(entry,entries[num].file); | |
300 free(entries[num].file); | |
301 if(list) | |
302 play_tree_append_entry(list,entry); | |
303 else | |
304 list = entry; | |
305 } | |
306 if(entries[num].title) { | |
307 // When we have info in playtree we add this info | |
308 free(entries[num].title); | |
309 } | |
310 if(entries[num].length) { | |
311 // When we have info in playtree we add this info | |
312 free(entries[num].length); | |
313 } | |
314 } | |
315 | |
316 free(entries); | |
5866 | 317 |
318 entry = play_tree_new(); | |
319 play_tree_set_child(entry,list); | |
320 return entry; | |
4782 | 321 } |
322 | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
323 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
324 parse_textplain(play_tree_parser_t* p) { |
4782 | 325 char* line; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
326 play_tree_t *list = NULL, *entry = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
327 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
328 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext...\n"); |
4782 | 329 play_tree_parser_stop_keeping(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
330 |
4782 | 331 while((line = play_tree_parser_get_line(p)) != NULL) { |
332 strstrip(line); | |
333 if(line[0] == '\0') | |
334 continue; | |
335 entry = play_tree_new(); | |
336 play_tree_add_file(entry,line); | |
337 if(!list) | |
338 list = entry; | |
339 else | |
340 play_tree_append_entry(list,entry); | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
341 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
342 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
343 if(!list) return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
344 entry = play_tree_new(); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
345 play_tree_set_child(entry,list); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
346 return entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
347 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
348 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
349 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
350 parse_playtree(stream_t *stream) { |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
351 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
352 play_tree_t* ret; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
353 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
354 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
355 assert(stream != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
356 assert(stream->type == STREAMTYPE_PLAYLIST); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
357 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
358 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
359 p = play_tree_parser_new(stream,0); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
360 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
361 return NULL; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
362 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
363 ret = play_tree_parser_get_play_tree(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
364 play_tree_parser_free(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
365 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
366 return ret; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
367 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
368 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
369 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
370 parse_playlist_file(char* file) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
371 stream_t *stream; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
372 play_tree_t* ret; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
373 int fd; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
374 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
375 if(!strcmp(file,"-")) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
376 fd = 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
377 else |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
378 fd = open(file,O_RDONLY); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
379 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
380 if(fd < 0) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
381 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while opening playlist file %s : %s\n",file,strerror(errno)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
382 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
383 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
384 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
385 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
|
386 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
387 stream = new_stream(fd,STREAMTYPE_PLAYLIST); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
388 ret = parse_playtree(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
389 if(close(fd) < 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
390 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Warning error while closing playlist file %s : %s\n",file,strerror(errno)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
391 free_stream(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
392 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
393 return ret; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
394 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
395 } |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
396 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
397 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
398 play_tree_parser_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
399 play_tree_parser_new(stream_t* stream,int deep) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
400 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
401 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
402 p = (play_tree_parser_t*)calloc(1,sizeof(play_tree_parser_t)); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
403 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
404 return NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
405 p->stream = stream; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
406 p->deep = deep; |
4782 | 407 p->keep = 1; |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
408 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
409 return p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
410 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
411 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
412 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
413 void |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
414 play_tree_parser_free(play_tree_parser_t* p) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
415 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
416 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
417 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
418 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
419 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
420 if(p->buffer) free(p->buffer); |
4782 | 421 if(p->line) free(p->line); |
422 free(p); | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
423 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
424 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
425 play_tree_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
426 play_tree_parser_get_play_tree(play_tree_parser_t* p) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
427 play_tree_t* tree = NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
428 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
429 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
430 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
431 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
432 |
4782 | 433 |
434 while(play_tree_parser_get_line(p) != NULL) { | |
435 play_tree_parser_reset(p); | |
436 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
437 tree = parse_asx(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
438 if(tree) break; |
4782 | 439 play_tree_parser_reset(p); |
440 | |
441 tree = parse_pls(p); | |
442 if(tree) break; | |
443 play_tree_parser_reset(p); | |
444 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
445 // Here come the others formats ( textplain must stay the last one ) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
446 tree = parse_textplain(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
447 if(tree) break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
448 break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
449 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
450 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
451 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
452 mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist succefully parsed\n"); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
453 else mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while parsing playlist\n"); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
454 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
455 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
456 tree = play_tree_cleanup(tree); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
457 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
458 if(!tree) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Warning empty playlist\n"); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
459 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
460 return tree; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
461 } |