Mercurial > mplayer.hg
annotate playtreeparser.c @ 5807:d4bc84e7c0ad
fix system_name case
author | arpi |
---|---|
date | Wed, 24 Apr 2002 01:54:37 +0000 |
parents | 35f19046f809 |
children | 0f5f626e5151 |
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 { | |
297 entry = play_tree_new(); | |
298 play_tree_add_file(entry,entries[num].file); | |
299 free(entries[num].file); | |
300 if(list) | |
301 play_tree_append_entry(list,entry); | |
302 else | |
303 list = entry; | |
304 } | |
305 if(entries[num].title) { | |
306 // When we have info in playtree we add this info | |
307 free(entries[num].title); | |
308 } | |
309 if(entries[num].length) { | |
310 // When we have info in playtree we add this info | |
311 free(entries[num].length); | |
312 } | |
313 } | |
314 | |
315 free(entries); | |
316 | |
317 return list; | |
318 } | |
319 | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
320 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
321 parse_textplain(play_tree_parser_t* p) { |
4782 | 322 char* line; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
323 play_tree_t *list = NULL, *entry = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
324 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
325 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext...\n"); |
4782 | 326 play_tree_parser_stop_keeping(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
327 |
4782 | 328 while((line = play_tree_parser_get_line(p)) != NULL) { |
329 strstrip(line); | |
330 if(line[0] == '\0') | |
331 continue; | |
332 entry = play_tree_new(); | |
333 play_tree_add_file(entry,line); | |
334 if(!list) | |
335 list = entry; | |
336 else | |
337 play_tree_append_entry(list,entry); | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
338 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
339 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
340 if(!list) return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
341 entry = play_tree_new(); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
342 play_tree_set_child(entry,list); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
343 return entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
344 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
345 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
346 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
347 parse_playtree(stream_t *stream) { |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
348 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
349 play_tree_t* ret; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
350 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
351 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
352 assert(stream != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
353 assert(stream->type == STREAMTYPE_PLAYLIST); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
354 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
355 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
356 p = play_tree_parser_new(stream,0); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
357 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
358 return NULL; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
359 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
360 ret = play_tree_parser_get_play_tree(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
361 play_tree_parser_free(p); |
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 return ret; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
364 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
365 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
366 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
367 parse_playlist_file(char* file) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
368 stream_t *stream; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
369 play_tree_t* ret; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
370 int fd; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
371 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
372 if(!strcmp(file,"-")) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
373 fd = 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
374 else |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
375 fd = open(file,O_RDONLY); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
376 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
377 if(fd < 0) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
378 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
|
379 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
380 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
381 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
382 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
|
383 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
384 stream = new_stream(fd,STREAMTYPE_PLAYLIST); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
385 ret = parse_playtree(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
386 if(close(fd) < 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
387 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
|
388 free_stream(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
389 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
390 return ret; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
391 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
392 } |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
393 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
394 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
395 play_tree_parser_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
396 play_tree_parser_new(stream_t* stream,int deep) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
397 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
398 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
399 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
|
400 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
401 return NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
402 p->stream = stream; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
403 p->deep = deep; |
4782 | 404 p->keep = 1; |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
405 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
406 return p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
407 |
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 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
410 void |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
411 play_tree_parser_free(play_tree_parser_t* p) { |
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 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
414 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
415 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
416 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
417 if(p->buffer) free(p->buffer); |
4782 | 418 if(p->line) free(p->line); |
419 free(p); | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
420 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
421 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
422 play_tree_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
423 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
|
424 play_tree_t* tree = NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
425 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
426 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
427 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
428 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
429 |
4782 | 430 |
431 while(play_tree_parser_get_line(p) != NULL) { | |
432 play_tree_parser_reset(p); | |
433 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
434 tree = parse_asx(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
435 if(tree) break; |
4782 | 436 play_tree_parser_reset(p); |
437 | |
438 tree = parse_pls(p); | |
439 if(tree) break; | |
440 play_tree_parser_reset(p); | |
441 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
442 // 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
|
443 tree = parse_textplain(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
444 if(tree) break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
445 break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
446 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
447 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
448 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
449 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
|
450 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
|
451 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
452 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
453 tree = play_tree_cleanup(tree); |
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) 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
|
456 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
457 return tree; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
458 } |