Mercurial > mplayer.hg
annotate playtreeparser.c @ 16513:68890ac57391
Reflect recent changes to the the pan audio filter syntax and behavior in
the documentation, patch by Reimar Doeffinger with some fixes by me.
author | diego |
---|---|
date | Sun, 18 Sep 2005 11:40:06 +0000 |
parents | 90ffe76b5b25 |
children | 0586a1ffba44 |
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> |
12300
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
14 #include <ctype.h> |
9749 | 15 #include "m_config.h" |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
16 #include "playtree.h" |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
17 #include "playtreeparser.h" |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
18 #include "libmpdemux/stream.h" |
12223 | 19 #include "libmpdemux/demuxer.h" |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
20 #include "mp_msg.h" |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
21 |
6662
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
22 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
23 extern play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
24 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
|
25 |
4782 | 26 #define BUF_STEP 1024 |
27 | |
28 #define WHITES " \n\r\t" | |
29 | |
30 static void | |
31 strstrip(char* str) { | |
32 char* i; | |
33 | |
8907 | 34 if (str==NULL) |
35 return; | |
4782 | 36 for(i = str ; i[0] != '\0' && strchr(WHITES,i[0]) != NULL; i++) |
37 /* NOTHING */; | |
38 if(i[0] != '\0') { | |
8907 | 39 memmove(str,i,strlen(i) + 1); |
40 for(i = str + strlen(str) - 1 ; strchr(WHITES,i[0]) != NULL; i--) | |
4782 | 41 /* NOTHING */; |
42 i[1] = '\0'; | |
43 } else | |
44 str[0] = '\0'; | |
45 } | |
46 | |
47 static char* | |
48 play_tree_parser_get_line(play_tree_parser_t* p) { | |
49 char *end,*line_end; | |
50 int r,resize = 0; | |
51 | |
52 if(p->buffer == NULL) { | |
53 p->buffer = (char*)malloc(BUF_STEP); | |
54 p->buffer_size = BUF_STEP; | |
55 p->iter = p->buffer; | |
56 } | |
57 | |
5802 | 58 if(p->stream->eof && (p->buffer_end == 0 || p->iter[0] == '\0')) |
4782 | 59 return NULL; |
60 | |
61 while(1) { | |
62 | |
63 if(resize) { | |
64 r = p->iter - p->buffer; | |
65 p->buffer = (char*)realloc(p->buffer,p->buffer_size+BUF_STEP); | |
66 p->iter = p->buffer + r; | |
67 p->buffer_size += BUF_STEP; | |
68 resize = 0; | |
69 } | |
70 | |
71 if(p->buffer_size - p->buffer_end > 1 && ! p->stream->eof) { | |
72 r = stream_read(p->stream,p->buffer + p->buffer_end,p->buffer_size - p->buffer_end - 1); | |
73 if(r > 0) { | |
74 p->buffer_end += r; | |
75 p->buffer[p->buffer_end] = '\0'; | |
76 } | |
77 } | |
78 | |
79 end = strchr(p->iter,'\n'); | |
80 if(!end) { | |
81 if(p->stream->eof) { | |
4857 | 82 end = p->buffer + p->buffer_end; |
4782 | 83 break; |
84 } | |
85 resize = 1; | |
86 continue; | |
87 } | |
88 break; | |
89 } | |
90 | |
91 line_end = ((*(end-1)) == '\r') ? end-1 : end; | |
5802 | 92 if(line_end - p->iter >= 0) |
93 p->line = (char*)realloc(p->line,line_end - p->iter+1); | |
94 else | |
4782 | 95 return NULL; |
5802 | 96 if(line_end - p->iter > 0) |
97 strncpy(p->line,p->iter,line_end - p->iter); | |
4782 | 98 p->line[line_end - p->iter] = '\0'; |
5802 | 99 if(end[0] != '\0') |
4857 | 100 end++; |
4782 | 101 |
102 if(!p->keep) { | |
4857 | 103 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
|
104 p->buffer_end -= end-p->iter; |
4782 | 105 memmove(p->buffer,end,p->buffer_end); |
10694 | 106 p->buffer[p->buffer_end] = '\0'; |
4782 | 107 } else |
108 p->buffer_end = 0; | |
109 p->iter = p->buffer; | |
110 } else | |
111 p->iter = end; | |
112 | |
113 return p->line; | |
114 } | |
115 | |
116 static void | |
117 play_tree_parser_reset(play_tree_parser_t* p) { | |
118 p->iter = p->buffer; | |
119 } | |
120 | |
121 static void | |
122 play_tree_parser_stop_keeping(play_tree_parser_t* p) { | |
123 p->keep = 0; | |
124 if(p->iter && p->iter != p->buffer) { | |
125 p->buffer_end -= p->iter -p->buffer; | |
126 if(p->buffer_end) | |
127 memmove(p->buffer,p->iter,p->buffer_end); | |
128 p->iter = p->buffer; | |
129 } | |
130 } | |
131 | |
4043
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 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
134 parse_asx(play_tree_parser_t* p) { |
4782 | 135 int comments = 0,get_line = 1; |
136 char* line = NULL; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
137 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
138 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
|
139 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
140 while(1) { |
4782 | 141 if(get_line) { |
142 line = play_tree_parser_get_line(p); | |
143 if(!line) | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
144 return NULL; |
4782 | 145 strstrip(line); |
146 if(line[0] == '\0') | |
147 continue; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
148 } |
4782 | 149 if(!comments) { |
150 if(line[0] != '<') { | |
151 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
|
152 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
|
153 return NULL; |
4782 | 154 } else if(strncmp(line,"<!--",4) == 0) { // Comments |
155 comments = 1; | |
156 line += 4; | |
157 if(line[0] != '\0' && strlen(line) > 0) | |
158 get_line = 0; | |
159 } else if(strncasecmp(line,"<ASX",4) == 0) // We got an asx element | |
160 break; | |
161 else // We don't get an asx | |
162 return NULL; | |
163 } else { // Comments | |
164 char* c; | |
165 c = strchr(line,'-'); | |
166 if(c) { | |
167 if (strncmp(c,"--!>",4) == 0) { // End of comments | |
168 comments = 0; | |
169 line = c+4; | |
170 if(line[0] != '\0') // There is some more data on this line : keep it | |
171 get_line = 0; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
172 |
4782 | 173 } else { |
174 line = c+1; // Jump the - | |
175 if(line[0] != '\0') // Some more data | |
176 get_line = 0; | |
177 else // End of line | |
178 get_line = 1; | |
179 } | |
180 } else // No - on this line (or rest of line) : get next one | |
181 get_line = 1; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
182 } |
4782 | 183 } |
184 | |
185 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
|
186 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
187 // 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
|
188 |
4782 | 189 while((line = play_tree_parser_get_line(p)) != NULL) |
190 /* NOTHING */; | |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
191 |
10487 | 192 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
|
193 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
|
194 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
195 |
4782 | 196 static char* |
197 pls_entry_get_value(char* line) { | |
198 char* i; | |
199 | |
200 i = strchr(line,'='); | |
201 if(!i || i[1] == '\0') | |
202 return NULL; | |
203 else | |
204 return i+1; | |
205 } | |
206 | |
207 typedef struct pls_entry { | |
208 char* file; | |
209 char* title; | |
210 char* length; | |
211 } pls_entry_t; | |
212 | |
213 static int | |
214 pls_read_entry(char* line,pls_entry_t** _e,int* _max_entry,char** val) { | |
215 int num,max_entry = (*_max_entry); | |
216 pls_entry_t* e = (*_e); | |
217 char* v; | |
218 | |
219 v = pls_entry_get_value(line); | |
220 if(!v) { | |
221 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
222 return 0; | |
223 } | |
224 | |
225 num = atoi(line); | |
226 if(num < 0) { | |
227 num = max_entry+1; | |
228 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"No entry index in entry %s\nAssuming %d\n",line,num); | |
229 } | |
230 if(num > max_entry) { | |
231 e = (pls_entry_t*)realloc(e,num*sizeof(pls_entry_t)); | |
232 memset(&e[max_entry],0,(num-max_entry)*sizeof(pls_entry_t)); | |
233 max_entry = num; | |
234 } | |
235 (*_e) = e; | |
236 (*_max_entry) = max_entry; | |
237 (*val) = v; | |
238 | |
239 return num; | |
240 } | |
241 | |
242 | |
243 play_tree_t* | |
244 parse_pls(play_tree_parser_t* p) { | |
245 char *line,*v; | |
246 pls_entry_t* entries = NULL; | |
247 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
|
248 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL; |
4782 | 249 |
10487 | 250 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying Winamp playlist...\n"); |
8925
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
251 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
|
252 return NULL; |
4782 | 253 strstrip(line); |
254 if(strcasecmp(line,"[playlist]")) | |
255 return NULL; | |
10487 | 256 mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected Winamp playlist format\n"); |
4782 | 257 play_tree_parser_stop_keeping(p); |
258 line = play_tree_parser_get_line(p); | |
259 if(!line) | |
260 return NULL; | |
261 strstrip(line); | |
262 if(strncasecmp(line,"NumberOfEntries",15) == 0) { | |
263 v = pls_entry_get_value(line); | |
264 n_entries = atoi(v); | |
265 if(n_entries < 0) | |
10487 | 266 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Invalid number of entries: very funny!!!\n"); |
4782 | 267 else |
10487 | 268 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Playlist claims to have %d entries. Let's see.\n",n_entries); |
4782 | 269 line = play_tree_parser_get_line(p); |
270 } | |
271 | |
272 while(line) { | |
273 strstrip(line); | |
274 if(line[0] == '\0') { | |
275 line = play_tree_parser_get_line(p); | |
276 continue; | |
277 } | |
278 if(strncasecmp(line,"File",4) == 0) { | |
279 num = pls_read_entry(line+4,&entries,&max_entry,&v); | |
280 if(num < 0) | |
281 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
282 else | |
283 entries[num-1].file = strdup(v); | |
284 } else if(strncasecmp(line,"Title",5) == 0) { | |
285 num = pls_read_entry(line+5,&entries,&max_entry,&v); | |
286 if(num < 0) | |
287 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
288 else | |
289 entries[num-1].title = strdup(v); | |
290 } else if(strncasecmp(line,"Length",6) == 0) { | |
291 num = pls_read_entry(line+6,&entries,&max_entry,&v); | |
292 if(num < 0) | |
293 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"No value in entry %s\n",line); | |
294 else | |
295 entries[num-1].length = strdup(v); | |
296 } else | |
10397 | 297 mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Unknown entry type %s\n",line); |
4782 | 298 line = play_tree_parser_get_line(p); |
299 } | |
300 | |
301 for(num = 0; num < max_entry ; num++) { | |
302 if(entries[num].file == NULL) | |
303 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Entry %d don't have a file !!!!\n",num+1); | |
304 else { | |
5866 | 305 mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding entry %s\n",entries[num].file); |
4782 | 306 entry = play_tree_new(); |
307 play_tree_add_file(entry,entries[num].file); | |
308 free(entries[num].file); | |
309 if(list) | |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
310 play_tree_append_entry(last_entry,entry); |
4782 | 311 else |
312 list = entry; | |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
313 last_entry = entry; |
4782 | 314 } |
315 if(entries[num].title) { | |
316 // When we have info in playtree we add this info | |
317 free(entries[num].title); | |
318 } | |
319 if(entries[num].length) { | |
320 // When we have info in playtree we add this info | |
321 free(entries[num].length); | |
322 } | |
323 } | |
324 | |
325 free(entries); | |
5866 | 326 |
327 entry = play_tree_new(); | |
328 play_tree_set_child(entry,list); | |
329 return entry; | |
4782 | 330 } |
331 | |
8897
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
332 /* |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
333 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
|
334 */ |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
335 play_tree_t* |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
336 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
|
337 char *line,*v; |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
338 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
|
339 |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
340 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
|
341 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
|
342 return NULL; |
8897
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
343 strstrip(line); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
344 if(strcasecmp(line,"[Reference]")) |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
345 return NULL; |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
346 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
|
347 play_tree_parser_stop_keeping(p); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
348 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
|
349 if(!line) |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
350 return NULL; |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
351 while(line) { |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
352 strstrip(line); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
353 if(strncasecmp(line,"Ref",3) == 0) { |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
354 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
|
355 if(!v) |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
356 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
|
357 else |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
358 { |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
359 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
|
360 entry = play_tree_new(); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
361 play_tree_add_file(entry,v); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
362 if(list) |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
363 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
|
364 else |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
365 list = entry; |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
366 last_entry = entry; |
8897
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
367 } |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
368 } |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
369 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
|
370 } |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
371 |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
372 if(!list) return NULL; |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
373 entry = play_tree_new(); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
374 play_tree_set_child(entry,list); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
375 return entry; |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
376 } |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
377 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
378 play_tree_t* |
6661
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
379 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
|
380 char* line; |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
381 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
|
382 |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
383 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
|
384 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
|
385 return NULL; |
6661
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
386 strstrip(line); |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
387 if(strcasecmp(line,"#EXTM3U")) |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
388 return NULL; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
389 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
|
390 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
|
391 |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
392 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
|
393 strstrip(line); |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
394 if(line[0] == '\0') |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
395 continue; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
396 /* EXTM3U files contain such lines: |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
397 * #EXTINF:<seconds>, <title> |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
398 * 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
|
399 * 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
|
400 * 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
|
401 */ |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
402 if(line[0] == '#') { |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
403 #if 0 /* code functional */ |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 } |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
408 #endif |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
409 continue; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
410 } |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
411 entry = play_tree_new(); |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
412 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
|
413 if(!list) |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
414 list = entry; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
415 else |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
416 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
|
417 last_entry = entry; |
6661
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
418 } |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
419 |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
420 if(!list) return NULL; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
421 entry = play_tree_new(); |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
422 play_tree_set_child(entry,list); |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
423 return entry; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
424 } |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
425 |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
426 play_tree_t* |
12097
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
427 parse_smil(play_tree_parser_t* p) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
428 int entrymode=0; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
429 char* line,source[512],*pos,*s_start,*s_end; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
430 play_tree_t *list = NULL, *entry = NULL, *last_entry = NULL; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
431 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
432 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
|
433 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
434 // Check if smil |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
435 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
|
436 strstrip(line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
437 if(line[0] == '\0') // Ignore empties |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
438 continue; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
439 if (strncasecmp(line,"<smil",5)==0) |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
440 break; // smil header found |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
441 else |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
442 return NULL; //line not smil exit |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
443 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
444 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
445 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
|
446 play_tree_parser_stop_keeping(p); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
447 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
448 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
449 //Get entries from smil |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
450 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
|
451 strstrip(line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
452 if (line[0]=='\0') |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
453 continue; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
454 if (!entrymode) { // all entries filled so far |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
455 if (strncasecmp(line,"<video",6)==0 || strncasecmp(line,"<audio",6)==0) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
456 pos=strstr(line,"src="); // Is source present on this line |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
457 if (pos !=NULL) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
458 s_start=pos+5; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
459 s_end=strchr(s_start,'"'); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
460 if (s_end == NULL) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
461 mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
462 continue; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
463 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
464 if (s_end-s_start> 511) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
465 mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
466 continue; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
467 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
468 strncpy(source,s_start,s_end-s_start); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
469 source[(s_end-s_start)]='\0'; // Null terminate |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
470 entry = play_tree_new(); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
471 play_tree_add_file(entry,source); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
472 if(!list) //Insert new entry |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
473 list = entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
474 else |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
475 play_tree_append_entry(last_entry,entry); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
476 last_entry = entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
477 } else { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
478 entrymode=1; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
479 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
480 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
481 } else { //Entry found but not yet filled |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
482 pos = strstr(line,"src="); // Is source present on this line |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
483 if (pos != NULL) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
484 entrymode=0; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
485 s_start=pos+5; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
486 s_end=strchr(s_start,'"'); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
487 if (s_end == NULL) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
488 mp_msg(MSGT_PLAYTREE,MSGL_V,"Error parsing this source line %s\n",line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
489 continue; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
490 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
491 if (s_end-s_start> 511) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
492 mp_msg(MSGT_PLAYTREE,MSGL_V,"Cannot store such a large source %s\n",line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
493 continue; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
494 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
495 strncpy(source,s_start,s_end-s_start); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
496 source[(s_end-s_start)]='\0'; // Null terminate |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
497 entry = play_tree_new(); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
498 play_tree_add_file(entry,source); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
499 if(!list) //Insert new entry |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
500 list = entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
501 else |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
502 play_tree_append_entry(last_entry,entry); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
503 last_entry = entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
504 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
505 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
506 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
507 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
508 if(!list) return NULL; // Nothing found |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
509 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
510 entry = play_tree_new(); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
511 play_tree_set_child(entry,list); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
512 return entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
513 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
514 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
515 play_tree_t* |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
516 embedded_playlist_parse(char *line) { |
12223 | 517 int f=DEMUXER_TYPE_PLAYLIST; |
12097
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
518 stream_t* stream; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
519 play_tree_parser_t* ptp; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
520 play_tree_t* entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
521 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
522 // Get stream opened to link |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
523 stream=open_stream(line,0,&f); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
524 if(!stream) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
525 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
|
526 return NULL; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
527 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
528 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
529 //add new playtree |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
530 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
|
531 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
532 ptp = play_tree_parser_new(stream,1); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
533 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
|
534 play_tree_parser_free(ptp); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
535 free_stream(stream); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
536 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
537 return entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
538 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
539 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
540 play_tree_t* |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
541 parse_textplain(play_tree_parser_t* p) { |
4782 | 542 char* line; |
12300
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
543 char *c; |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
544 int embedded; |
9789
45173e0d34cc
Fix the incredible slowness with very long list. Now a 10^6 entries
albeu
parents:
9749
diff
changeset
|
545 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
|
546 |
6661
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
547 mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying plaintext playlist...\n"); |
4782 | 548 play_tree_parser_stop_keeping(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
549 |
4782 | 550 while((line = play_tree_parser_get_line(p)) != NULL) { |
551 strstrip(line); | |
12689
050c90536ddd
Support for comments in plaintext playlist by adland
alex
parents:
12538
diff
changeset
|
552 if(line[0] == '\0' || line[0] == '#' || (line[0] == '/' && line[1] == '/')) |
4782 | 553 continue; |
12097
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
554 |
12538
2beafad68f68
Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents:
12300
diff
changeset
|
555 //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
|
556 embedded = 0; |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
557 if (strlen(line) > 5) |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
558 for(c = line; c[0]; c++ ) |
12538
2beafad68f68
Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents:
12300
diff
changeset
|
559 if ( ((c[0] == '.') && //start with . and next have smil with optional ? or & |
2beafad68f68
Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents:
12300
diff
changeset
|
560 (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
|
561 (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
|
562 (!c[5] || c[5] == '?' || c[5] == '&')) || // or |
2beafad68f68
Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents:
12300
diff
changeset
|
563 ((c[0] == '.') && // start with . and next have smi or ram with optional ? or & |
2beafad68f68
Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents:
12300
diff
changeset
|
564 ( ((tolower(c[1]) == 's') && (tolower(c[2])== 'm') && (tolower(c[3]) == 'i')) || |
2beafad68f68
Enhance detection of embedded smil playlist, add embedded ram playlist
rtognimp
parents:
12300
diff
changeset
|
565 ((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
|
566 && (!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
|
567 entry=embedded_playlist_parse(line); |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
568 embedded = 1; |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
569 break; |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
570 } |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
571 |
95ea9f5f6f14
Fix embedded smil playlist detection if there are parameters on the url
rtognimp
parents:
12223
diff
changeset
|
572 if (!embedded) { //regular file link |
12097
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
573 entry = play_tree_new(); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
574 play_tree_add_file(entry,line); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
575 } |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
576 |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
577 if (entry != NULL) { |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
578 if(!list) |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
579 list = entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
580 else |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
581 play_tree_append_entry(last_entry,entry); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
582 last_entry = entry; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
583 } |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
584 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
585 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
586 if(!list) return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
587 entry = play_tree_new(); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
588 play_tree_set_child(entry,list); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
589 return entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
590 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
591 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
592 play_tree_t* |
8925
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
593 parse_playtree(stream_t *stream, int forced) { |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
594 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
595 play_tree_t* ret; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
596 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4043
diff
changeset
|
597 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
598 assert(stream != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
599 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
600 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
601 p = play_tree_parser_new(stream,0); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
602 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
603 return NULL; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
604 |
8925
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
605 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
|
606 play_tree_parser_free(p); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
607 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
608 return ret; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
609 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
610 |
6662
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
611 static void |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
612 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
|
613 int i,bl = strlen(bp),fl; |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
614 |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
615 if(pt->child) { |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
616 play_tree_t* i; |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
617 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
|
618 play_tree_add_basepath(i,bp); |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
619 return; |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
620 } |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
621 |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
622 if(!pt->files) |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
623 return; |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
624 |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
625 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
|
626 fl = strlen(pt->files[i]); |
13305
90ffe76b5b25
Don't prepend basepath to a full unix path. ( 10l to Joey. )
al
parents:
13010
diff
changeset
|
627 // 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
|
628 // don't mangle it. |
90ffe76b5b25
Don't prepend basepath to a full unix path. ( 10l to Joey. )
al
parents:
13010
diff
changeset
|
629 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
|
630 continue; |
13010 | 631 // if the path begins with \ then prepend drive letter to it. |
632 if (pt->files[i][0] == '\\') { | |
633 pt->files[i] = (char*)realloc(pt->files[i],2+fl+1); | |
634 memmove(pt->files[i] + 2,pt->files[i],fl+1); | |
635 memcpy(pt->files[i],bp,2); | |
636 return; | |
637 } | |
6662
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
638 pt->files[i] = (char*)realloc(pt->files[i],bl+fl+1); |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
639 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
|
640 memcpy(pt->files[i],bp,bl); |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
641 } |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
642 } |
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
643 |
9301
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
644 // 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
|
645 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
|
646 { |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
647 char *ls, *file; |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
648 |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
649 if (pt && filename) |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
650 { |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
651 file = strdup(filename); |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
652 if (file) |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
653 { |
13010 | 654 ls = strrchr(file,'/'); |
655 if(!ls) ls = strrchr(file,'\\'); | |
9301
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
656 if(ls) { |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
657 ls[1] = '\0'; |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
658 play_tree_add_basepath(pt,file); |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
659 } |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
660 free(file); |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
661 } |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
662 } |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
663 } |
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
664 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
665 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
666 parse_playlist_file(char* file) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
667 stream_t *stream; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
668 play_tree_t* ret; |
12223 | 669 int f=DEMUXER_TYPE_PLAYLIST; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
670 |
9749 | 671 stream = open_stream(file,0,&f); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
672 |
9749 | 673 if(!stream) { |
10487 | 674 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
|
675 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
676 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
677 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
678 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
|
679 |
8925
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
680 ret = parse_playtree(stream,1); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
681 free_stream(stream); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
682 |
9301
7841308ad250
this patch fixes latest bug, discovered by .so ... (relative filenames &
arpi
parents:
9089
diff
changeset
|
683 play_tree_add_bpf(ret, file); |
6662
f8e25756a5ec
Relative filename in playlist are now relative to the playlist path
albeu
parents:
6661
diff
changeset
|
684 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
685 return ret; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
686 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
687 } |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
688 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
689 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
690 play_tree_parser_t* |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
691 play_tree_parser_new(stream_t* stream,int deep) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
692 play_tree_parser_t* p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
693 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
694 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
|
695 if(!p) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
696 return NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
697 p->stream = stream; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
698 p->deep = deep; |
4782 | 699 p->keep = 1; |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
700 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
701 return p; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
702 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
703 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
704 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
705 void |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
706 play_tree_parser_free(play_tree_parser_t* p) { |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
707 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
708 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
709 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
710 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
711 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
712 if(p->buffer) free(p->buffer); |
4782 | 713 if(p->line) free(p->line); |
714 free(p); | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
715 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
716 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
717 play_tree_t* |
8925
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
718 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
|
719 play_tree_t* tree = NULL; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
720 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
721 #ifdef MP_DEBUG |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
722 assert(p != NULL); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
723 #endif |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
724 |
4782 | 725 |
726 while(play_tree_parser_get_line(p) != NULL) { | |
727 play_tree_parser_reset(p); | |
728 | |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
729 tree = parse_asx(p); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
730 if(tree) break; |
4782 | 731 play_tree_parser_reset(p); |
732 | |
733 tree = parse_pls(p); | |
734 if(tree) break; | |
735 play_tree_parser_reset(p); | |
736 | |
6661
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
737 tree = parse_m3u(p); |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
738 if(tree) break; |
dc61b6b159e4
Add support for m3u playlists as generated by eg recent versions of winamp.
atmos4
parents:
5866
diff
changeset
|
739 play_tree_parser_reset(p); |
8897
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
740 |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
741 tree = parse_ref_ini(p); |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
742 if(tree) break; |
ef01554542fb
This patch adds support for some silly ini-style-playlist-file-format ...
arpi
parents:
8164
diff
changeset
|
743 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
|
744 |
12097
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
745 tree = parse_smil(p); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
746 if(tree) break; |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
747 play_tree_parser_reset(p); |
cb0cdaa0bddf
Support for smil playlist, both standalone and embedded into other
rtognimp
parents:
10694
diff
changeset
|
748 |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
749 // 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
|
750 if (forced) |
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
751 { |
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
752 tree = parse_textplain(p); |
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
753 if(tree) break; |
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
754 } |
4308
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
755 break; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
756 } |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
757 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
758 if(tree) |
10487 | 759 mp_msg(MSGT_PLAYTREE,MSGL_V,"Playlist successfully parsed\n"); |
8925
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
760 else |
5c15777f1c07
this patch adds an fallback to playlist (any but the plaintext-list format)
arpi
parents:
8907
diff
changeset
|
761 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
|
762 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
763 if(tree) |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
764 tree = play_tree_cleanup(tree); |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
765 |
10487 | 766 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
|
767 |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
768 return tree; |
d752f99fd535
Objectization of the play_tree_parser for more flexiblity
albeu
parents:
4156
diff
changeset
|
769 } |