Mercurial > mplayer.hg
annotate playtreeparser.c @ 5205:47259a4f3216
show sub/av delay at osdlevel=1 - patch by Marcin Juszkiewicz <marcinj@netbox.pl>
author | arpi |
---|---|
date | Tue, 19 Mar 2002 19:22:00 +0000 |
parents | f3f94fb55398 |
children | 8bd1c1e319fb |
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 | |
52 if(p->stream->eof && p->buffer_end == 0) | |
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; | |
86 p->line = (char*)realloc(p->line,line_end - p->iter+1); | |
87 if(!p->line) | |
88 return NULL; | |
89 strncpy(p->line,p->iter,line_end - p->iter); | |
90 p->line[line_end - p->iter] = '\0'; | |
4857 | 91 if(end != '\0') |
92 end++; | |
4782 | 93 |
94 if(!p->keep) { | |
4857 | 95 if(end[0] != '\0') { |
96 p->buffer_end -= strlen(p->line)+1; | |
4782 | 97 memmove(p->buffer,end,p->buffer_end); |
98 } else | |
99 p->buffer_end = 0; | |
100 p->iter = p->buffer; | |
101 } else | |
102 p->iter = end; | |
103 | |
104 return p->line; | |
105 } | |
106 | |
107 static void | |
108 play_tree_parser_reset(play_tree_parser_t* p) { | |
109 p->iter = p->buffer; | |
110 } | |
111 | |
112 static void | |
113 play_tree_parser_stop_keeping(play_tree_parser_t* p) { | |
114 p->keep = 0; | |
115 if(p->iter && p->iter != p->buffer) { | |
116 p->buffer_end -= p->iter -p->buffer; | |
117 if(p->buffer_end) | |
118 memmove(p->buffer,p->iter,p->buffer_end); | |
119 p->iter = p->buffer; | |
120 } | |
121 } | |
122 | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
123 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
124 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
125 parse_asx(play_tree_parser_t* p) { |
4782 | 126 int comments = 0,get_line = 1; |
127 char* line = NULL; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
128 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
129 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
|
130 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
131 while(1) { |
4782 | 132 if(get_line) { |
133 line = play_tree_parser_get_line(p); | |
134 if(!line) | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
135 return NULL; |
4782 | 136 strstrip(line); |
137 if(line[0] == '\0') | |
138 continue; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
139 } |
4782 | 140 if(!comments) { |
141 if(line[0] != '<') { | |
142 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
|
143 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
|
144 return NULL; |
4782 | 145 } else if(strncmp(line,"<!--",4) == 0) { // Comments |
146 comments = 1; | |
147 line += 4; | |
148 if(line[0] != '\0' && strlen(line) > 0) | |
149 get_line = 0; | |
150 } else if(strncasecmp(line,"<ASX",4) == 0) // We got an asx element | |
151 break; | |
152 else // We don't get an asx | |
153 return NULL; | |
154 } else { // Comments | |
155 char* c; | |
156 c = strchr(line,'-'); | |
157 if(c) { | |
158 if (strncmp(c,"--!>",4) == 0) { // End of comments | |
159 comments = 0; | |
160 line = c+4; | |
161 if(line[0] != '\0') // There is some more data on this line : keep it | |
162 get_line = 0; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
163 |
4782 | 164 } else { |
165 line = c+1; // Jump the - | |
166 if(line[0] != '\0') // Some more data | |
167 get_line = 0; | |
168 else // End of line | |
169 get_line = 1; | |
170 } | |
171 } else // No - on this line (or rest of line) : get next one | |
172 get_line = 1; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
173 } |
4782 | 174 } |
175 | |
176 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
|
177 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
178 // 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
|
179 |
4782 | 180 while((line = play_tree_parser_get_line(p)) != NULL) |
181 /* NOTHING */; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
182 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
183 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
|
184 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
|
185 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
186 |
4782 | 187 static char* |
188 pls_entry_get_value(char* line) { | |
189 char* i; | |
190 | |
191 i = strchr(line,'='); | |
192 if(!i || i[1] == '\0') | |
193 return NULL; | |
194 else | |
195 return i+1; | |
196 } | |
197 | |
198 typedef struct pls_entry { | |
199 char* file; | |
200 char* title; | |
201 char* length; | |
202 } pls_entry_t; | |
203 | |
204 static int | |
205 pls_read_entry(char* line,pls_entry_t** _e,int* _max_entry,char** val) { | |
206 int num,max_entry = (*_max_entry); | |
207 pls_entry_t* e = (*_e); | |
208 char* v; | |
209 | |
210 v = pls_entry_get_value(line); | |
211 if(!v) { | |
212 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
213 return 0; | |
214 } | |
215 | |
216 num = atoi(line); | |
217 if(num < 0) { | |
218 num = max_entry+1; | |
219 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"No entry index in entry %s\nAssuming %d\n",line,num); | |
220 } | |
221 if(num > max_entry) { | |
222 e = (pls_entry_t*)realloc(e,num*sizeof(pls_entry_t)); | |
223 memset(&e[max_entry],0,(num-max_entry)*sizeof(pls_entry_t)); | |
224 max_entry = num; | |
225 } | |
226 (*_e) = e; | |
227 (*_max_entry) = max_entry; | |
228 (*val) = v; | |
229 | |
230 return num; | |
231 } | |
232 | |
233 | |
234 play_tree_t* | |
235 parse_pls(play_tree_parser_t* p) { | |
236 char *line,*v; | |
237 pls_entry_t* entries = NULL; | |
238 int n_entries = 0,max_entry=0,num; | |
239 play_tree_t *list = NULL, *entry = NULL; | |
240 | |
241 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying winamp playlist...\n"); | |
242 line = play_tree_parser_get_line(p); | |
243 strstrip(line); | |
244 if(strcasecmp(line,"[playlist]")) | |
245 return NULL; | |
246 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected winamp playlist format\n"); | |
247 play_tree_parser_stop_keeping(p); | |
248 line = play_tree_parser_get_line(p); | |
249 if(!line) | |
250 return NULL; | |
251 strstrip(line); | |
252 if(strncasecmp(line,"NumberOfEntries",15) == 0) { | |
253 v = pls_entry_get_value(line); | |
254 n_entries = atoi(v); | |
255 if(n_entries < 0) | |
256 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Invalid number of entries : very funny !!!\n"); | |
257 else | |
258 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Playlist claim to have %d entries. Let's see.\n",n_entries); | |
259 line = play_tree_parser_get_line(p); | |
260 } | |
261 | |
262 while(line) { | |
263 strstrip(line); | |
264 if(line[0] == '\0') { | |
265 line = play_tree_parser_get_line(p); | |
266 continue; | |
267 } | |
268 if(strncasecmp(line,"File",4) == 0) { | |
269 num = pls_read_entry(line+4,&entries,&max_entry,&v); | |
270 if(num < 0) | |
271 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
272 else | |
273 entries[num-1].file = strdup(v); | |
274 } else if(strncasecmp(line,"Title",5) == 0) { | |
275 num = pls_read_entry(line+5,&entries,&max_entry,&v); | |
276 if(num < 0) | |
277 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
278 else | |
279 entries[num-1].title = strdup(v); | |
280 } else if(strncasecmp(line,"Length",6) == 0) { | |
281 num = pls_read_entry(line+6,&entries,&max_entry,&v); | |
282 if(num < 0) | |
283 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
284 else | |
285 entries[num-1].length = strdup(v); | |
286 } else | |
287 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Unknow entry type %s\n",line); | |
288 line = play_tree_parser_get_line(p); | |
289 } | |
290 | |
291 for(num = 0; num < max_entry ; num++) { | |
292 if(entries[num].file == NULL) | |
293 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Entry %d don't have a file !!!!\n",num+1); | |
294 else { | |
295 entry = play_tree_new(); | |
296 play_tree_add_file(entry,entries[num].file); | |
297 free(entries[num].file); | |
298 if(list) | |
299 play_tree_append_entry(list,entry); | |
300 else | |
301 list = entry; | |
302 } | |
303 if(entries[num].title) { | |
304 // When we have info in playtree we add this info | |
305 free(entries[num].title); | |
306 } | |
307 if(entries[num].length) { | |
308 // When we have info in playtree we add this info | |
309 free(entries[num].length); | |
310 } | |
311 } | |
312 | |
313 free(entries); | |
314 | |
315 return list; | |
316 } | |
317 | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
318 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
319 parse_textplain(play_tree_parser_t* p) { |
4782 | 320 char* line; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
321 play_tree_t *list = NULL, *entry = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
322 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
323 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext...\n"); |
4782 | 324 play_tree_parser_stop_keeping(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
325 |
4782 | 326 while((line = play_tree_parser_get_line(p)) != NULL) { |
327 strstrip(line); | |
328 if(line[0] == '\0') | |
329 continue; | |
330 entry = play_tree_new(); | |
331 play_tree_add_file(entry,line); | |
332 if(!list) | |
333 list = entry; | |
334 else | |
335 play_tree_append_entry(list,entry); | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
336 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
337 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
338 if(!list) return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
339 entry = play_tree_new(); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
340 play_tree_set_child(entry,list); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
341 return entry; |
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 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
344 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
345 parse_playtree(stream_t *stream) { |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
346 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
347 play_tree_t* ret; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
348 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
349 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
350 assert(stream != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
351 assert(stream->type == STREAMTYPE_PLAYLIST); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
352 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
353 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
354 p = play_tree_parser_new(stream,0); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
355 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
356 return NULL; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
357 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
358 ret = play_tree_parser_get_play_tree(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
359 play_tree_parser_free(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
360 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
361 return ret; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
362 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
363 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
364 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
365 parse_playlist_file(char* file) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
366 stream_t *stream; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
367 play_tree_t* ret; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
368 int fd; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
369 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
370 if(!strcmp(file,"-")) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
371 fd = 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
372 else |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
373 fd = open(file,O_RDONLY); |
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(fd < 0) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
376 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
|
377 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
378 } |
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 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
|
381 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
382 stream = new_stream(fd,STREAMTYPE_PLAYLIST); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
383 ret = parse_playtree(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
384 if(close(fd) < 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
385 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
|
386 free_stream(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
387 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
388 return ret; |
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 } |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
391 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
392 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
393 play_tree_parser_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
394 play_tree_parser_new(stream_t* stream,int deep) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
395 play_tree_parser_t* p; |
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 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
|
398 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
399 return NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
400 p->stream = stream; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
401 p->deep = deep; |
4782 | 402 p->keep = 1; |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
403 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
404 return p; |
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 } |
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 void |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
409 play_tree_parser_free(play_tree_parser_t* 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 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
412 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
413 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
414 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
415 if(p->buffer) free(p->buffer); |
4782 | 416 if(p->line) free(p->line); |
417 free(p); | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
418 } |
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 play_tree_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
421 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
|
422 play_tree_t* tree = NULL; |
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 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
425 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
426 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
427 |
4782 | 428 |
429 while(play_tree_parser_get_line(p) != NULL) { | |
430 play_tree_parser_reset(p); | |
431 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
432 tree = parse_asx(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
433 if(tree) break; |
4782 | 434 play_tree_parser_reset(p); |
435 | |
436 tree = parse_pls(p); | |
437 if(tree) break; | |
438 play_tree_parser_reset(p); | |
439 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
440 // 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
|
441 tree = parse_textplain(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
442 if(tree) break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
443 break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
444 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
445 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
446 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
447 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
|
448 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
|
449 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
450 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
451 tree = play_tree_cleanup(tree); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
452 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
453 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
|
454 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
455 return tree; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
456 } |