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